summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock4
-rw-r--r--app/models/flowdock_service.rb52
-rw-r--r--app/models/project.rb3
-rw-r--r--features/project/service.feature6
-rw-r--r--features/steps/project/project_services.rb14
-rw-r--r--spec/models/flowdock_service_spec.rb48
7 files changed, 129 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index 708211e3f40..fb67f301f72 100644
--- a/Gemfile
+++ b/Gemfile
@@ -111,6 +111,9 @@ gem 'tinder', '~> 1.9.2'
# HipChat integration
gem "hipchat", "~> 0.9.0"
+# Flowdock integration
+gem "gitlab-flowdock-git-hook", "~> 0.4.2"
+
# d3
gem "d3_rails", "~> 3.1.4"
diff --git a/Gemfile.lock b/Gemfile.lock
index c66036295aa..ce3aeb7994b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -156,6 +156,9 @@ GEM
pygments.rb (>= 0.2.13)
github-markdown (0.5.3)
github-markup (0.7.5)
+ gitlab-flowdock-git-hook (0.4.2.2)
+ gitlab-grit (>= 2.4.1)
+ multi_json
gitlab-gollum-lib (1.0.1)
github-markdown (~> 0.5.3)
github-markup (>= 0.7.5, < 1.0.0)
@@ -571,6 +574,7 @@ DEPENDENCIES
gemoji (~> 1.2.1)
github-linguist
github-markup (~> 0.7.4)
+ gitlab-flowdock-git-hook (~> 0.4.2)
gitlab-gollum-lib (~> 1.0.1)
gitlab-grack (~> 1.0.1)
gitlab-pygments.rb (~> 0.3.2)
diff --git a/app/models/flowdock_service.rb b/app/models/flowdock_service.rb
new file mode 100644
index 00000000000..6ec431d4a10
--- /dev/null
+++ b/app/models/flowdock_service.rb
@@ -0,0 +1,52 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# token :string(255)
+# project_id :integer not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# active :boolean default(FALSE), not null
+# project_url :string(255)
+#
+
+require "flowdock-git-hook"
+
+class FlowdockService < Service
+ validates :token, presence: true, if: :activated?
+
+ def title
+ 'Flowdock'
+ end
+
+ def description
+ 'Flowdock is a collaboration web app for technical teams.'
+ end
+
+ def to_param
+ 'flowdock'
+ end
+
+ def fields
+ [
+ { type: 'text', name: 'token', placeholder: '' }
+ ]
+ end
+
+ def execute(push_data)
+ repo_path = File.join(Gitlab.config.gitlab_shell.repos_path, "#{project.path_with_namespace}.git")
+ Flowdock::Git.post(
+ push_data[:ref],
+ push_data[:before],
+ push_data[:after],
+ token: token,
+ repo: repo_path,
+ repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}",
+ commit_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/commit/%s",
+ diff_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}/compare/%s...%s",
+ )
+ end
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index 709a6b1ea49..8755ffa69b8 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -46,6 +46,7 @@ class Project < ActiveRecord::Base
has_one :campfire_service, dependent: :destroy
has_one :pivotaltracker_service, dependent: :destroy
has_one :hipchat_service, dependent: :destroy
+ has_one :flowdock_service, dependent: :destroy
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
has_one :forked_from_project, through: :forked_project_link
@@ -219,7 +220,7 @@ class Project < ActiveRecord::Base
end
def available_services_names
- %w(gitlab_ci campfire hipchat pivotaltracker)
+ %w(gitlab_ci campfire hipchat pivotaltracker flowdock)
end
def gitlab_ci?
diff --git a/features/project/service.feature b/features/project/service.feature
index e685c385d1d..4805d2befbe 100644
--- a/features/project/service.feature
+++ b/features/project/service.feature
@@ -24,3 +24,9 @@ Feature: Project Services
And I click pivotaltracker service link
And I fill pivotaltracker settings
Then I should see pivotaltracker service settings saved
+
+ Scenario: Activate Flowdock service
+ When I visit project "Shop" services page
+ And I click Flowdock service link
+ And I fill Flowdock settings
+ Then I should see Flowdock service settings saved
diff --git a/features/steps/project/project_services.rb b/features/steps/project/project_services.rb
index a24100ff8c0..70eafc875d4 100644
--- a/features/steps/project/project_services.rb
+++ b/features/steps/project/project_services.rb
@@ -58,4 +58,18 @@ class ProjectServices < Spinach::FeatureSteps
Then 'I should see pivotaltracker service settings saved' do
find_field('Token').value.should == 'verySecret'
end
+
+ And 'I click Flowdock service link' do
+ click_link 'Flowdock'
+ end
+
+ And 'I fill Flowdock settings' do
+ check 'Active'
+ fill_in 'Token', with: 'verySecret'
+ click_button 'Save'
+ end
+
+ Then 'I should see Flowdock service settings saved' do
+ find_field('Token').value.should == 'verySecret'
+ end
end
diff --git a/spec/models/flowdock_service_spec.rb b/spec/models/flowdock_service_spec.rb
new file mode 100644
index 00000000000..b22193c9e93
--- /dev/null
+++ b/spec/models/flowdock_service_spec.rb
@@ -0,0 +1,48 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# token :string(255)
+# project_id :integer not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# active :boolean default(FALSE), not null
+# project_url :string(255)
+#
+
+require 'spec_helper'
+
+describe FlowdockService do
+ describe "Associations" do
+ it { should belong_to :project }
+ it { should have_one :service_hook }
+ end
+
+ describe "Execute" do
+ let(:user) { create(:user) }
+ let(:project) { create(:project_with_code) }
+
+ before do
+ @flowdock_service = FlowdockService.new
+ @flowdock_service.stub(
+ project_id: project.id,
+ project: project,
+ service_hook: true,
+ token: 'verySecret'
+ )
+ @sample_data = GitPushService.new.sample_data(project, user)
+ @api_url = 'https://api.flowdock.com/v1/git/verySecret'
+ WebMock.stub_request(:post, @api_url)
+ end
+
+ it "should call FlowDock API" do
+ @flowdock_service.execute(@sample_data)
+ WebMock.should have_requested(:post, @api_url).with(
+ body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
+ ).once
+ end
+ end
+end