BigW Consortium Gitlab

pivotaltracker_service.rb 1.04 KB
Newer Older
1 2 3
class PivotaltrackerService < Service
  include HTTParty

4
  prop_accessor :token
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  validates :token, presence: true, if: :activated?

  def title
    'PivotalTracker'
  end

  def description
    'Project Management Software (Source Commits Endpoint)'
  end

  def to_param
    'pivotaltracker'
  end

  def fields
    [
      { type: 'text', name: 'token', placeholder: '' }
    ]
  end

25 26 27 28
  def supported_events
    %w(push)
  end

29
  def execute(data)
30
    return unless supported_events.include?(data[:object_kind])
31

32
    url = 'https://www.pivotaltracker.com/services/v5/source_commits'
33
    data[:commits].each do |commit|
Johannes Becker committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
      message = {
        'source_commit' => {
          'commit_id' => commit[:id],
          'author' => commit[:author][:name],
          'url' => commit[:url],
          'message' => commit[:message]
        }
      }
      PivotaltrackerService.post(
        url,
        body: message.to_json,
        headers: {
          'Content-Type' => 'application/json',
          'X-TrackerToken' => token
        }
      )
50 51 52
    end
  end
end