Commit d8562cc9a141917e5b0adc1f33f2ec8da8ab10d4

Authored by Boyan Tabakov
1 parent 267e8c73

Added Flowdock integration support via a service.

Added test for the FlowdockService.
@@ -111,6 +111,9 @@ gem 'tinder', '~> 1.9.2' @@ -111,6 +111,9 @@ gem 'tinder', '~> 1.9.2'
111 # HipChat integration 111 # HipChat integration
112 gem "hipchat", "~> 0.9.0" 112 gem "hipchat", "~> 0.9.0"
113 113
  114 +# Flowdock integration
  115 +gem "flowdock-git-hook", "~> 0.4.2"
  116 +
114 # d3 117 # d3
115 gem "d3_rails", "~> 3.1.4" 118 gem "d3_rails", "~> 3.1.4"
116 119
@@ -135,6 +135,9 @@ GEM @@ -135,6 +135,9 @@ GEM
135 faraday (>= 0.7.4, < 0.9) 135 faraday (>= 0.7.4, < 0.9)
136 ffaker (1.18.0) 136 ffaker (1.18.0)
137 ffi (1.9.0) 137 ffi (1.9.0)
  138 + flowdock-git-hook (0.4.2)
  139 + grit (>= 2.4.1)
  140 + multi_json
138 fog (1.3.1) 141 fog (1.3.1)
139 builder 142 builder
140 excon (~> 0.13.0) 143 excon (~> 0.13.0)
@@ -205,6 +208,10 @@ GEM @@ -205,6 +208,10 @@ GEM
205 grape-entity (0.3.0) 208 grape-entity (0.3.0)
206 activesupport 209 activesupport
207 multi_json (>= 1.3.2) 210 multi_json (>= 1.3.2)
  211 + grit (2.5.0)
  212 + diff-lcs (~> 1.1)
  213 + mime-types (~> 1.15)
  214 + posix-spawn (~> 0.3.6)
208 growl (1.0.3) 215 growl (1.0.3)
209 guard (1.8.1) 216 guard (1.8.1)
210 formatador (>= 0.2.4) 217 formatador (>= 0.2.4)
@@ -568,6 +575,7 @@ DEPENDENCIES @@ -568,6 +575,7 @@ DEPENDENCIES
568 enumerize 575 enumerize
569 factory_girl_rails 576 factory_girl_rails
570 ffaker 577 ffaker
  578 + flowdock-git-hook (~> 0.4.2)
571 fog (~> 1.3.1) 579 fog (~> 1.3.1)
572 font-awesome-rails 580 font-awesome-rails
573 foreman 581 foreman
app/models/flowdock_service.rb 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  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 +# project_url :string(255)
  14 +#
  15 +
  16 +class FlowdockService < Service
  17 + validates :token, presence: true, if: :activated?
  18 +
  19 + def title
  20 + 'Flowdock'
  21 + end
  22 +
  23 + def description
  24 + 'Flowdock is a collaboration web app for technical teams.'
  25 + end
  26 +
  27 + def to_param
  28 + 'flowdock'
  29 + end
  30 +
  31 + def fields
  32 + [
  33 + { type: 'text', name: 'token', placeholder: '' }
  34 + ]
  35 + end
  36 +
  37 + def execute(push_data)
  38 + repo_path = File.join(Gitlab.config.gitlab_shell.repos_path, "#{project.path_with_namespace}.git")
  39 + Flowdock::Git.post(
  40 + push_data[:ref],
  41 + push_data[:before],
  42 + push_data[:after],
  43 + token: token,
  44 + repo: repo_path,
  45 + repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}",
  46 + commit_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/%s",
  47 + diff_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/compare/%s...%s",
  48 + )
  49 + end
  50 +end
app/models/project.rb
@@ -48,6 +48,7 @@ class Project &lt; ActiveRecord::Base @@ -48,6 +48,7 @@ class Project &lt; ActiveRecord::Base
48 has_one :campfire_service, dependent: :destroy 48 has_one :campfire_service, dependent: :destroy
49 has_one :pivotaltracker_service, dependent: :destroy 49 has_one :pivotaltracker_service, dependent: :destroy
50 has_one :hipchat_service, dependent: :destroy 50 has_one :hipchat_service, dependent: :destroy
  51 + has_one :flowdock_service, dependent: :destroy
51 has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" 52 has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
52 has_one :forked_from_project, through: :forked_project_link 53 has_one :forked_from_project, through: :forked_project_link
53 54
@@ -221,7 +222,7 @@ class Project &lt; ActiveRecord::Base @@ -221,7 +222,7 @@ class Project &lt; ActiveRecord::Base
221 end 222 end
222 223
223 def available_services_names 224 def available_services_names
224 - %w(gitlab_ci campfire hipchat pivotaltracker) 225 + %w(gitlab_ci campfire hipchat pivotaltracker flowdock)
225 end 226 end
226 227
227 def gitlab_ci? 228 def gitlab_ci?
features/project/service.feature
@@ -24,3 +24,9 @@ Feature: Project Services @@ -24,3 +24,9 @@ Feature: Project Services
24 And I click pivotaltracker service link 24 And I click pivotaltracker service link
25 And I fill pivotaltracker settings 25 And I fill pivotaltracker settings
26 Then I should see pivotaltracker service settings saved 26 Then I should see pivotaltracker service settings saved
  27 +
  28 + Scenario: Activate Flowdock service
  29 + When I visit project "Shop" services page
  30 + And I click Flowdock service link
  31 + And I fill Flowdock settings
  32 + Then I should see Flowdock service settings saved
features/steps/project/project_services.rb
@@ -58,4 +58,18 @@ class ProjectServices &lt; Spinach::FeatureSteps @@ -58,4 +58,18 @@ class ProjectServices &lt; Spinach::FeatureSteps
58 Then 'I should see pivotaltracker service settings saved' do 58 Then 'I should see pivotaltracker service settings saved' do
59 find_field('Token').value.should == 'verySecret' 59 find_field('Token').value.should == 'verySecret'
60 end 60 end
  61 +
  62 + And 'I click Flowdock service link' do
  63 + click_link 'Flowdock'
  64 + end
  65 +
  66 + And 'I fill Flowdock settings' do
  67 + check 'Active'
  68 + fill_in 'Token', with: 'verySecret'
  69 + click_button 'Save'
  70 + end
  71 +
  72 + Then 'I should see Flowdock service settings saved' do
  73 + find_field('Token').value.should == 'verySecret'
  74 + end
61 end 75 end
spec/models/flowdock_service_spec.rb 0 → 100644
@@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
  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 +# project_url :string(255)
  14 +#
  15 +
  16 +require 'spec_helper'
  17 +
  18 +describe FlowdockService do
  19 + describe "Associations" do
  20 + it { should belong_to :project }
  21 + it { should have_one :service_hook }
  22 + end
  23 +
  24 + describe "Execute" do
  25 + let(:user) { create(:user) }
  26 + let(:project) { create(:project_with_code) }
  27 +
  28 + before do
  29 + @flowdock_service = FlowdockService.new
  30 + @flowdock_service.stub(
  31 + project_id: project.id,
  32 + project: project,
  33 + service_hook: true,
  34 + token: 'verySecret'
  35 + )
  36 + @sample_data = GitPushService.new.sample_data(project, user)
  37 + @api_url = 'https://api.flowdock.com/v1/git/verySecret'
  38 + WebMock.stub_request(:post, @api_url)
  39 + end
  40 +
  41 + it "should call FlowDock API" do
  42 + @flowdock_service.execute(@sample_data)
  43 + WebMock.should have_requested(:post, @api_url).with(
  44 + body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
  45 + ).once
  46 + end
  47 + end
  48 +end