Commit 618dc4cd authored by Jeroen van Baarsen's avatar Jeroen van Baarsen

Merge pull request #9206 from dsander/hipchat-options

Add notify and color options to HipchatService
parents f0c4c51f 3c3b43b0
...@@ -23,6 +23,7 @@ v 7.11.0 (unreleased) ...@@ -23,6 +23,7 @@ v 7.11.0 (unreleased)
- Improve new project command options (Ben Bodenmiller) - Improve new project command options (Ben Bodenmiller)
- Prevent sending empty messages to HipChat (Chulki Lee) - Prevent sending empty messages to HipChat (Chulki Lee)
- Improve UI for mobile phones on dashboard and project pages - Improve UI for mobile phones on dashboard and project pages
- Add room notification and message color option for HipChat
v 7.10.0 v 7.10.0
- Ignore submodules that are defined in .gitmodules but are checked in as directories. - Ignore submodules that are defined in .gitmodules but are checked in as directories.
......
...@@ -6,7 +6,8 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -6,7 +6,8 @@ class Projects::ServicesController < Projects::ApplicationController
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel, :description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
:colorize_messages, :channels, :colorize_messages, :channels,
:push_events, :issues_events, :merge_requests_events, :tag_push_events, :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 # Authorize
before_action :authorize_admin_project! before_action :authorize_admin_project!
before_action :service, only: [:edit, :update, :test] before_action :service, only: [:edit, :update, :test]
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
class HipchatService < Service class HipchatService < Service
MAX_COMMITS = 3 MAX_COMMITS = 3
prop_accessor :token, :room, :server prop_accessor :token, :room, :server, :notify, :color
validates :token, presence: true, if: :activated? validates :token, presence: true, if: :activated?
def title def title
...@@ -39,6 +39,8 @@ class HipchatService < Service ...@@ -39,6 +39,8 @@ class HipchatService < Service
[ [
{ type: 'text', name: 'token', placeholder: 'Room token' }, { type: 'text', name: 'token', placeholder: 'Room token' },
{ type: 'text', name: 'room', placeholder: 'Room name or ID' }, { 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', { type: 'text', name: 'server',
placeholder: 'Leave blank for default. https://hipchat.example.com' } placeholder: 'Leave blank for default. https://hipchat.example.com' }
] ]
...@@ -52,7 +54,7 @@ class HipchatService < Service ...@@ -52,7 +54,7 @@ class HipchatService < Service
return unless supported_events.include?(data[:object_kind]) return unless supported_events.include?(data[:object_kind])
message = create_message(data) message = create_message(data)
return unless message.present? return unless message.present?
gate[room].send('GitLab', message) gate[room].send('GitLab', message, message_options)
end end
private private
...@@ -63,6 +65,10 @@ class HipchatService < Service ...@@ -63,6 +65,10 @@ class HipchatService < Service
@gate ||= HipChat::Client.new(token, options) @gate ||= HipChat::Client.new(token, options)
end end
def message_options
{ notify: notify.present? && notify == '1', color: color || 'yellow' }
end
def create_message(data) def create_message(data)
object_kind = data[:object_kind] object_kind = data[:object_kind]
......
...@@ -213,5 +213,21 @@ describe HipchatService do ...@@ -213,5 +213,21 @@ describe HipchatService do
"<pre>snippet note</pre>") "<pre>snippet note</pre>")
end end
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
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