Sha256: 573085198792b05478975327878555bf98a0fc996b54ac42665569f8bf9ebb6e

Contents?: true

Size: 1.95 KB

Versions: 8

Compression:

Stored size: 1.95 KB

Contents

class CC::Service::PivotalTracker < CC::Service
  class Config < CC::Service::Config
    attribute :api_token, Axiom::Types::String,
      description: "Your Pivotal Tracker API Token, from your profile page"

    attribute :project_id, Axiom::Types::String,
      description: "Your Pivotal Tracker project ID"

    attribute :labels, Axiom::Types::String,
      label: "Labels (comma separated)",
      description: "Comma separated list of labels to apply to the story"

    validates :api_token, presence: true
    validates :project_id, presence: true
  end

  self.title = "Pivotal Tracker"
  self.description = "Create stories on Pivotal Tracker"
  self.issue_tracker = true

  BASE_URL = "https://www.pivotaltracker.com/services/v3"

  def receive_test
    result = create_story("Test ticket from Code Climate", "")
    result.merge(
      message: "Ticket <a href='#{result[:url]}'>#{result[:id]}</a> created."
    )
  end

  def receive_quality
    create_story(quality_title, details_url)
  end

  def receive_issue
    title = %{Fix "#{issue["check_name"]}" issue in #{constant_name}}

    body = [issue["description"], details_url].join("\n\n")

    create_story(title, body)
  end

  def receive_vulnerability
    formatter = CC::Formatters::TicketFormatter.new(self)

    create_story(
      formatter.format_vulnerability_title,
      formatter.format_vulnerability_body
    )
  end

private

  def create_story(name, description)
    params = {
      "story[name]"        => name,
      "story[story_type]"  => "chore",
      "story[description]" => description,
    }

    if config.labels.present?
      params["story[labels]"] = config.labels.strip
    end

    http.headers["X-TrackerToken"] = config.api_token
    url = "#{BASE_URL}/projects/#{config.project_id}/stories"

    service_post(url, params) do |response|
      body = Nokogiri::XML(response.body)
      {
        id: (body / "story/id").text,
        url: (body / "story/url").text
      }
    end
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
codeclimate-services-1.6.1 lib/cc/services/pivotal_tracker.rb
codeclimate-services-1.6.0 lib/cc/services/pivotal_tracker.rb
codeclimate-services-1.5.1 lib/cc/services/pivotal_tracker.rb
codeclimate-services-1.5.0 lib/cc/services/pivotal_tracker.rb
codeclimate-services-1.4.0 lib/cc/services/pivotal_tracker.rb
codeclimate-services-1.3.0 lib/cc/services/pivotal_tracker.rb
codeclimate-services-1.2.0 lib/cc/services/pivotal_tracker.rb
codeclimate-services-1.1.0 lib/cc/services/pivotal_tracker.rb