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)
- 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.
......
......@@ -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]
......
......@@ -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]
......
......@@ -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
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