Commit 35597f61aabc613e8b64c8f8e66999f8f3b3a8a6

Authored by Johannes Becker
1 parent daf2cf62

Simple PivotalTracker Source Commits Service

app/models/pivotaltracker_service.rb 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: services
  4 +#
  5 +# id :integer not null, primary key
  6 +# type :string(255)
  7 +# title :string(255)
  8 +# token :string(255)
  9 +# project_id :integer not null
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +# active :boolean default(FALSE), not null
  13 +#
  14 +
  15 +class PivotaltrackerService < Service
  16 + include HTTParty
  17 +
  18 + attr_accessible :subdomain, :room
  19 +
  20 + validates :token, presence: true, if: :activated?
  21 +
  22 + def title
  23 + 'PivotalTracker'
  24 + end
  25 +
  26 + def description
  27 + 'Project Management Software (Source Commits Endpoint)'
  28 + end
  29 +
  30 + def to_param
  31 + 'pivotaltracker'
  32 + end
  33 +
  34 + def fields
  35 + [
  36 + { type: 'text', name: 'token', placeholder: '' }
  37 + ]
  38 + end
  39 +
  40 + def execute(push)
  41 + url = 'https://www.pivotaltracker.com/services/v5/source_commits'
  42 + push[:commits].each do |commit|
  43 + message = {'source_commit' =>
  44 + {'commit_id' => commit[:id],
  45 + 'author' => commit[:author][:name],
  46 + 'url' => commit[:url],
  47 + 'message' => commit[:message]}
  48 + }
  49 + status = PivotaltrackerService.post(url,
  50 + body: message.to_json,
  51 + headers: {'Content-Type' => 'application/json',
  52 + 'X-TrackerToken' => token}
  53 + )
  54 + end
  55 + end
  56 +
  57 +end
... ...
app/models/project.rb
... ... @@ -46,6 +46,7 @@ class Project &lt; ActiveRecord::Base
46 46 has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id'
47 47 has_one :gitlab_ci_service, dependent: :destroy
48 48 has_one :campfire_service, dependent: :destroy
  49 + has_one :pivotaltracker_service, dependent: :destroy
49 50 has_one :hipchat_service, dependent: :destroy
50 51 has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
51 52 has_one :forked_from_project, through: :forked_project_link
... ... @@ -220,7 +221,7 @@ class Project &lt; ActiveRecord::Base
220 221 end
221 222  
222 223 def available_services_names
223   - %w(gitlab_ci campfire hipchat)
  224 + %w(gitlab_ci campfire hipchat pivotaltracker)
224 225 end
225 226  
226 227 def gitlab_ci?
... ...