diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/projects/services_controller.rb | 3 | ||||
-rw-r--r-- | app/models/project_services/hipchat_service.rb | 10 | ||||
-rw-r--r-- | spec/models/project_services/hipchat_service_spec.rb | 16 |
4 files changed, 27 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG index 82f789c2baf..2504a4e9c91 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ v 7.11.0 (unreleased) - Improve new project command options (Ben Bodenmiller) - Prevent sending empty messages to HipChat (Chulki Lee) - Improve UI for mobile phones on dashboard and project pages + - Add room notification and message color option for HipChat v 7.10.0 - Ignore submodules that are defined in .gitmodules but are checked in as directories. diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index 73031851734..2080ee9a00f 100644 --- a/app/controllers/projects/services_controller.rb +++ b/app/controllers/projects/services_controller.rb @@ -6,7 +6,8 @@ class Projects::ServicesController < Projects::ApplicationController :description, :issues_url, :new_issue_url, :restrict_to_branch, :channel, :colorize_messages, :channels, :push_events, :issues_events, :merge_requests_events, :tag_push_events, - :note_events, :send_from_committer_email, :disable_diffs, :external_wiki_url] + :note_events, :send_from_committer_email, :disable_diffs, :external_wiki_url, + :notify, :color] # Authorize before_action :authorize_admin_project! before_action :service, only: [:edit, :update, :test] diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index 07520eab5d1..2fa5f0ce71c 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -20,7 +20,7 @@ class HipchatService < Service MAX_COMMITS = 3 - prop_accessor :token, :room, :server + prop_accessor :token, :room, :server, :notify, :color validates :token, presence: true, if: :activated? def title @@ -39,6 +39,8 @@ class HipchatService < Service [ { type: 'text', name: 'token', placeholder: 'Room token' }, { type: 'text', name: 'room', placeholder: 'Room name or ID' }, + { type: 'checkbox', name: 'notify' }, + { type: 'select', name: 'color', choices: ['yellow', 'red', 'green', 'purple', 'gray', 'random'] }, { type: 'text', name: 'server', placeholder: 'Leave blank for default. https://hipchat.example.com' } ] @@ -52,7 +54,7 @@ class HipchatService < Service return unless supported_events.include?(data[:object_kind]) message = create_message(data) return unless message.present? - gate[room].send('GitLab', message) + gate[room].send('GitLab', message, message_options) end private @@ -63,6 +65,10 @@ class HipchatService < Service @gate ||= HipChat::Client.new(token, options) end + def message_options + { notify: notify.present? && notify == '1', color: color || 'yellow' } + end + def create_message(data) object_kind = data[:object_kind] diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index 8ab847e6432..348f83c56ad 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -213,5 +213,21 @@ describe HipchatService do "<pre>snippet note</pre>") end end + + context "#message_options" do + it "should be set to the defaults" do + expect(hipchat.send(:message_options)).to eq({notify: false, color: 'yellow'}) + end + + it "should set notfiy to true" do + hipchat.stub(notify: '1') + expect(hipchat.send(:message_options)).to eq({notify: true, color: 'yellow'}) + end + + it "should set the color" do + hipchat.stub(color: 'red') + expect(hipchat.send(:message_options)).to eq({notify: false, color: 'red'}) + end + end end end |