Commit 83c727c5 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #5216 from bladealslayer/feature/flowdock_integration

Added Flowdock integration support via a service.
parents dc00562f e8b6974a
...@@ -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 "gitlab-flowdock-git-hook", "~> 0.4.2"
# d3 # d3
gem "d3_rails", "~> 3.1.4" gem "d3_rails", "~> 3.1.4"
......
...@@ -156,6 +156,9 @@ GEM ...@@ -156,6 +156,9 @@ GEM
pygments.rb (>= 0.2.13) pygments.rb (>= 0.2.13)
github-markdown (0.5.3) github-markdown (0.5.3)
github-markup (0.7.5) 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) gitlab-gollum-lib (1.0.1)
github-markdown (~> 0.5.3) github-markdown (~> 0.5.3)
github-markup (>= 0.7.5, < 1.0.0) github-markup (>= 0.7.5, < 1.0.0)
...@@ -571,6 +574,7 @@ DEPENDENCIES ...@@ -571,6 +574,7 @@ DEPENDENCIES
gemoji (~> 1.2.1) gemoji (~> 1.2.1)
github-linguist github-linguist
github-markup (~> 0.7.4) github-markup (~> 0.7.4)
gitlab-flowdock-git-hook (~> 0.4.2)
gitlab-gollum-lib (~> 1.0.1) gitlab-gollum-lib (~> 1.0.1)
gitlab-grack (~> 1.0.1) gitlab-grack (~> 1.0.1)
gitlab-pygments.rb (~> 0.3.2) gitlab-pygments.rb (~> 0.3.2)
......
# == 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
...@@ -46,6 +46,7 @@ class Project < ActiveRecord::Base ...@@ -46,6 +46,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
...@@ -219,7 +220,7 @@ class Project < ActiveRecord::Base ...@@ -219,7 +220,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