debian-mirror-gitlab/app/models/project_services/pivotaltracker_service.rb

53 lines
1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class PivotaltrackerService < Service
include HTTParty
2015-04-26 12:48:37 +05:30
prop_accessor :token
2014-09-02 18:07:02 +05:30
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
2015-04-26 12:48:37 +05:30
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
2014-09-02 18:07:02 +05:30
url = 'https://www.pivotaltracker.com/services/v5/source_commits'
2015-04-26 12:48:37 +05:30
data[:commits].each do |commit|
2014-09-02 18:07:02 +05:30
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
}
)
end
end
end