Commit d8562cc9 authored by Boyan Tabakov's avatar Boyan Tabakov

Added Flowdock integration support via a service.

Added test for the FlowdockService.
parent 267e8c73
...@@ -111,6 +111,9 @@ gem 'tinder', '~> 1.9.2' ...@@ -111,6 +111,9 @@ gem 'tinder', '~> 1.9.2'
# HipChat integration # HipChat integration
gem "hipchat", "~> 0.9.0" gem "hipchat", "~> 0.9.0"
# Flowdock integration
gem "flowdock-git-hook", "~> 0.4.2"
# d3 # d3
gem "d3_rails", "~> 3.1.4" gem "d3_rails", "~> 3.1.4"
......
...@@ -135,6 +135,9 @@ GEM ...@@ -135,6 +135,9 @@ GEM
faraday (>= 0.7.4, < 0.9) faraday (>= 0.7.4, < 0.9)
ffaker (1.18.0) ffaker (1.18.0)
ffi (1.9.0) ffi (1.9.0)
flowdock-git-hook (0.4.2)
grit (>= 2.4.1)
multi_json
fog (1.3.1) fog (1.3.1)
builder builder
excon (~> 0.13.0) excon (~> 0.13.0)
...@@ -205,6 +208,10 @@ GEM ...@@ -205,6 +208,10 @@ GEM
grape-entity (0.3.0) grape-entity (0.3.0)
activesupport activesupport
multi_json (>= 1.3.2) multi_json (>= 1.3.2)
grit (2.5.0)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3.6)
growl (1.0.3) growl (1.0.3)
guard (1.8.1) guard (1.8.1)
formatador (>= 0.2.4) formatador (>= 0.2.4)
...@@ -568,6 +575,7 @@ DEPENDENCIES ...@@ -568,6 +575,7 @@ DEPENDENCIES
enumerize enumerize
factory_girl_rails factory_girl_rails
ffaker ffaker
flowdock-git-hook (~> 0.4.2)
fog (~> 1.3.1) fog (~> 1.3.1)
font-awesome-rails font-awesome-rails
foreman foreman
......
# == 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)
#
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
...@@ -48,6 +48,7 @@ class Project < ActiveRecord::Base ...@@ -48,6 +48,7 @@ class Project < ActiveRecord::Base
has_one :campfire_service, dependent: :destroy has_one :campfire_service, dependent: :destroy
has_one :pivotaltracker_service, dependent: :destroy has_one :pivotaltracker_service, dependent: :destroy
has_one :hipchat_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_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
has_one :forked_from_project, through: :forked_project_link has_one :forked_from_project, through: :forked_project_link
...@@ -221,7 +222,7 @@ class Project < ActiveRecord::Base ...@@ -221,7 +222,7 @@ class Project < ActiveRecord::Base
end end
def available_services_names def available_services_names
%w(gitlab_ci campfire hipchat pivotaltracker) %w(gitlab_ci campfire hipchat pivotaltracker flowdock)
end end
def gitlab_ci? def gitlab_ci?
......
...@@ -24,3 +24,9 @@ Feature: Project Services ...@@ -24,3 +24,9 @@ Feature: Project Services
And I click pivotaltracker service link And I click pivotaltracker service link
And I fill pivotaltracker settings And I fill pivotaltracker settings
Then I should see pivotaltracker service settings saved 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
...@@ -58,4 +58,18 @@ class ProjectServices < Spinach::FeatureSteps ...@@ -58,4 +58,18 @@ class ProjectServices < Spinach::FeatureSteps
Then 'I should see pivotaltracker service settings saved' do Then 'I should see pivotaltracker service settings saved' do
find_field('Token').value.should == 'verySecret' find_field('Token').value.should == 'verySecret'
end 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 end
# == 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment