Commit 82f3446fde4c6c0507e1752152b9e3be68ae4aa8
Exists in
master
and in
4 other branches
Merge pull request #5174 from johannesbecker/service-pivotaltracker
PivotalTracker Source Commits Endpoint
Showing
4 changed files
with
81 additions
and
1 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,59 @@ |
| 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 | + validates :token, presence: true, if: :activated? | |
| 19 | + | |
| 20 | + def title | |
| 21 | + 'PivotalTracker' | |
| 22 | + end | |
| 23 | + | |
| 24 | + def description | |
| 25 | + 'Project Management Software (Source Commits Endpoint)' | |
| 26 | + end | |
| 27 | + | |
| 28 | + def to_param | |
| 29 | + 'pivotaltracker' | |
| 30 | + end | |
| 31 | + | |
| 32 | + def fields | |
| 33 | + [ | |
| 34 | + { type: 'text', name: 'token', placeholder: '' } | |
| 35 | + ] | |
| 36 | + end | |
| 37 | + | |
| 38 | + def execute(push) | |
| 39 | + url = 'https://www.pivotaltracker.com/services/v5/source_commits' | |
| 40 | + push[:commits].each do |commit| | |
| 41 | + message = { | |
| 42 | + 'source_commit' => { | |
| 43 | + 'commit_id' => commit[:id], | |
| 44 | + 'author' => commit[:author][:name], | |
| 45 | + 'url' => commit[:url], | |
| 46 | + 'message' => commit[:message] | |
| 47 | + } | |
| 48 | + } | |
| 49 | + PivotaltrackerService.post( | |
| 50 | + url, | |
| 51 | + body: message.to_json, | |
| 52 | + headers: { | |
| 53 | + 'Content-Type' => 'application/json', | |
| 54 | + 'X-TrackerToken' => token | |
| 55 | + } | |
| 56 | + ) | |
| 57 | + end | |
| 58 | + end | |
| 59 | +end | ... | ... |
app/models/project.rb
| ... | ... | @@ -46,6 +46,7 @@ class Project < 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 < 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? | ... | ... |
features/project/service.feature
| ... | ... | @@ -18,3 +18,9 @@ Feature: Project Services |
| 18 | 18 | And I click hipchat service link |
| 19 | 19 | And I fill hipchat settings |
| 20 | 20 | Then I should see hipchat service settings saved |
| 21 | + | |
| 22 | + Scenario: Activate pivotaltracker service | |
| 23 | + When I visit project "Shop" services page | |
| 24 | + And I click pivotaltracker service link | |
| 25 | + And I fill pivotaltracker settings | |
| 26 | + Then I should see pivotaltracker service settings saved | ... | ... |
features/steps/project/project_services.rb
| ... | ... | @@ -44,4 +44,18 @@ class ProjectServices < Spinach::FeatureSteps |
| 44 | 44 | find_field('Room').value.should == 'gitlab' |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | + | |
| 48 | + And 'I click pivotaltracker service link' do | |
| 49 | + click_link 'PivotalTracker' | |
| 50 | + end | |
| 51 | + | |
| 52 | + And 'I fill pivotaltracker settings' do | |
| 53 | + check 'Active' | |
| 54 | + fill_in 'Token', with: 'verySecret' | |
| 55 | + click_button 'Save' | |
| 56 | + end | |
| 57 | + | |
| 58 | + Then 'I should see pivotaltracker service settings saved' do | |
| 59 | + find_field('Token').value.should == 'verySecret' | |
| 60 | + end | |
| 47 | 61 | end | ... | ... |