Commit 68825be12fb5d35080660d3f9eb6916a7a421fa8
Exists in
master
and in
4 other branches
Merge pull request #4063 from ronaldvaneede/hipchat-service
Hipchat service implementation
Showing
6 changed files
with
104 additions
and
1 deletions
Show diff stats
Gemfile
| @@ -104,6 +104,9 @@ gem "redis-rails" | @@ -104,6 +104,9 @@ gem "redis-rails" | ||
| 104 | # Campfire integration | 104 | # Campfire integration |
| 105 | gem 'tinder', '~> 1.9.2' | 105 | gem 'tinder', '~> 1.9.2' |
| 106 | 106 | ||
| 107 | +# HipChat integration | ||
| 108 | +gem "hipchat", "~> 0.9.0" | ||
| 109 | + | ||
| 107 | group :assets do | 110 | group :assets do |
| 108 | gem "sass-rails" | 111 | gem "sass-rails" |
| 109 | gem "coffee-rails" | 112 | gem "coffee-rails" |
Gemfile.lock
| @@ -208,6 +208,8 @@ GEM | @@ -208,6 +208,8 @@ GEM | ||
| 208 | railties (>= 3.1, < 4.1) | 208 | railties (>= 3.1, < 4.1) |
| 209 | hashie (1.2.0) | 209 | hashie (1.2.0) |
| 210 | hike (1.2.2) | 210 | hike (1.2.2) |
| 211 | + hipchat (0.9.0) | ||
| 212 | + httparty | ||
| 211 | http_parser.rb (0.5.3) | 213 | http_parser.rb (0.5.3) |
| 212 | httparty (0.11.0) | 214 | httparty (0.11.0) |
| 213 | multi_json (~> 1.0) | 215 | multi_json (~> 1.0) |
| @@ -532,6 +534,7 @@ DEPENDENCIES | @@ -532,6 +534,7 @@ DEPENDENCIES | ||
| 532 | guard-rspec | 534 | guard-rspec |
| 533 | guard-spinach | 535 | guard-spinach |
| 534 | haml-rails | 536 | haml-rails |
| 537 | + hipchat (~> 0.9.0) | ||
| 535 | httparty | 538 | httparty |
| 536 | jquery-atwho-rails (= 0.3.0) | 539 | jquery-atwho-rails (= 0.3.0) |
| 537 | jquery-rails (= 2.1.3) | 540 | jquery-rails (= 2.1.3) |
| @@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
| 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 HipchatService < Service | ||
| 17 | + attr_accessible :room | ||
| 18 | + | ||
| 19 | + validates :token, presence: true, if: :activated? | ||
| 20 | + | ||
| 21 | + def title | ||
| 22 | + 'Hipchat' | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | + def description | ||
| 26 | + 'Simple web-based real-time group chat' | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | + def to_param | ||
| 30 | + 'hipchat' | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + def fields | ||
| 34 | + [ | ||
| 35 | + { type: 'text', name: 'token', placeholder: '' }, | ||
| 36 | + { type: 'text', name: 'room', placeholder: '' } | ||
| 37 | + ] | ||
| 38 | + end | ||
| 39 | + | ||
| 40 | + def execute(push_data) | ||
| 41 | + gate[room].send('Gitlab', create_message(push_data)) | ||
| 42 | + end | ||
| 43 | + | ||
| 44 | + private | ||
| 45 | + | ||
| 46 | + def gate | ||
| 47 | + @gate ||= HipChat::Client.new(token) | ||
| 48 | + end | ||
| 49 | + | ||
| 50 | + def create_message(push) | ||
| 51 | + ref = push[:ref].gsub("refs/heads/", "") | ||
| 52 | + before = push[:before] | ||
| 53 | + after = push[:after] | ||
| 54 | + | ||
| 55 | + message = "" | ||
| 56 | + message << "#{push[:user_name]} " | ||
| 57 | + if before =~ /000000/ | ||
| 58 | + message << "pushed new branch <a href=\"#{project.web_url}/commits/#{ref}\">#{ref}</a> to <a href=\"#{project.web_url}\">#{project.name_with_namespace.gsub!(/\s/,'')}</a>\n" | ||
| 59 | + elsif after =~ /000000/ | ||
| 60 | + message << "removed branch #{ref} from <a href=\"#{project.web_url}\">#{project.name_with_namespace.gsub!(/\s/,'')}</a> \n" | ||
| 61 | + else | ||
| 62 | + message << "#pushed to branch <a href=\"#{project.web_url}/commits/#{ref}\">#{ref}</a> " | ||
| 63 | + message << "of <a href=\"#{project.web_url}\">#{project.name_with_namespace.gsub!(/\s/,'')}</a> " | ||
| 64 | + message << "(<a href=\"#{project.web_url}/compare/#{before}...#{after}\">Compare changes</a>)" | ||
| 65 | + for commit in push[:commits] do | ||
| 66 | + message << "<br /> - #{commit[:message]} (<a href=\"#{commit[:url]}\">#{commit[:id][0..5]}</a>)" | ||
| 67 | + end | ||
| 68 | + end | ||
| 69 | + | ||
| 70 | + message | ||
| 71 | + end | ||
| 72 | + | ||
| 73 | +end | ||
| 0 | \ No newline at end of file | 74 | \ No newline at end of file |
app/models/project.rb
| @@ -46,6 +46,7 @@ class Project < ActiveRecord::Base | @@ -46,6 +46,7 @@ class Project < ActiveRecord::Base | ||
| 46 | has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id' | 46 | has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id' |
| 47 | has_one :gitlab_ci_service, dependent: :destroy | 47 | has_one :gitlab_ci_service, dependent: :destroy |
| 48 | has_one :campfire_service, dependent: :destroy | 48 | has_one :campfire_service, dependent: :destroy |
| 49 | + has_one :hipchat_service, dependent: :destroy | ||
| 49 | has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" | 50 | has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" |
| 50 | has_one :forked_from_project, through: :forked_project_link | 51 | has_one :forked_from_project, through: :forked_project_link |
| 51 | 52 | ||
| @@ -236,7 +237,7 @@ class Project < ActiveRecord::Base | @@ -236,7 +237,7 @@ class Project < ActiveRecord::Base | ||
| 236 | end | 237 | end |
| 237 | 238 | ||
| 238 | def available_services_names | 239 | def available_services_names |
| 239 | - %w(gitlab_ci campfire) | 240 | + %w(gitlab_ci campfire hipchat) |
| 240 | end | 241 | end |
| 241 | 242 | ||
| 242 | def gitlab_ci? | 243 | def gitlab_ci? |
features/project/service.feature
| @@ -12,3 +12,9 @@ Feature: Project Services | @@ -12,3 +12,9 @@ Feature: Project Services | ||
| 12 | And I click gitlab-ci service link | 12 | And I click gitlab-ci service link |
| 13 | And I fill gitlab-ci settings | 13 | And I fill gitlab-ci settings |
| 14 | Then I should see service settings saved | 14 | Then I should see service settings saved |
| 15 | + | ||
| 16 | + Scenario: Activate hipchat service | ||
| 17 | + When I visit project "Shop" services page | ||
| 18 | + And I click hipchat service link | ||
| 19 | + And I fill hipchat settings | ||
| 20 | + Then I should see hipchat service settings saved |
features/steps/project/project_services.rb
| @@ -10,6 +10,7 @@ class ProjectServices < Spinach::FeatureSteps | @@ -10,6 +10,7 @@ class ProjectServices < Spinach::FeatureSteps | ||
| 10 | Then 'I should see list of available services' do | 10 | Then 'I should see list of available services' do |
| 11 | page.should have_content 'Services' | 11 | page.should have_content 'Services' |
| 12 | page.should have_content 'Campfire' | 12 | page.should have_content 'Campfire' |
| 13 | + page.should have_content 'Hipchat' | ||
| 13 | page.should have_content 'GitLab CI' | 14 | page.should have_content 'GitLab CI' |
| 14 | end | 15 | end |
| 15 | 16 | ||
| @@ -27,4 +28,20 @@ class ProjectServices < Spinach::FeatureSteps | @@ -27,4 +28,20 @@ class ProjectServices < Spinach::FeatureSteps | ||
| 27 | Then 'I should see service settings saved' do | 28 | Then 'I should see service settings saved' do |
| 28 | find_field('Project url').value.should == 'http://ci.gitlab.org/projects/3' | 29 | find_field('Project url').value.should == 'http://ci.gitlab.org/projects/3' |
| 29 | end | 30 | end |
| 31 | + | ||
| 32 | + And 'I click hipchat service link' do | ||
| 33 | + click_link 'Hipchat' | ||
| 34 | + end | ||
| 35 | + | ||
| 36 | + And 'I fill hipchat settings' do | ||
| 37 | + check 'Active' | ||
| 38 | + fill_in 'Room', with: 'gitlab' | ||
| 39 | + fill_in 'Token', with: 'verySecret' | ||
| 40 | + click_button 'Save' | ||
| 41 | + end | ||
| 42 | + | ||
| 43 | + Then 'I should see hipchat service settings saved' do | ||
| 44 | + find_field('Room').value.should == 'gitlab' | ||
| 45 | + end | ||
| 46 | + | ||
| 30 | end | 47 | end |