Commit 255162e1 authored by Rémy Coutable's avatar Rémy Coutable

Little refactor, add specs, and a CHANGELOG entry

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 189e3b57
...@@ -9,6 +9,7 @@ v 8.11.0 (unreleased) ...@@ -9,6 +9,7 @@ v 8.11.0 (unreleased)
- Add green outline to New Branch button. !5447 (winniehell) - Add green outline to New Branch button. !5447 (winniehell)
- Retrieve rendered HTML from cache in one request - Retrieve rendered HTML from cache in one request
- Nokogiri's various parsing methods are now instrumented - Nokogiri's various parsing methods are now instrumented
- Add build event color in HipChat messages (David Eisner)
- Make fork counter always clickable. !5463 (winniehell) - Make fork counter always clickable. !5463 (winniehell)
- Remove `search_id` of labels dropdown filter to fix 'Missleading URI for labels in Merge Requests and Issues view'. !5368 (Scott Le) - Remove `search_id` of labels dropdown filter to fix 'Missleading URI for labels in Merge Requests and Issues view'. !5368 (Scott Le)
- Load project invited groups and members eagerly in `ProjectTeam#fetch_members` - Load project invited groups and members eagerly in `ProjectTeam#fetch_members`
......
...@@ -67,7 +67,7 @@ class HipchatService < Service ...@@ -67,7 +67,7 @@ class HipchatService < Service
@gate ||= HipChat::Client.new(token, options) @gate ||= HipChat::Client.new(token, options)
end end
def message_options(data) def message_options(data = nil)
{ notify: notify.present? && notify == '1', color: build_status_color(data) || color || 'yellow' } { notify: notify.present? && notify == '1', color: build_status_color(data) || color || 'yellow' }
end end
...@@ -241,11 +241,14 @@ class HipchatService < Service ...@@ -241,11 +241,14 @@ class HipchatService < Service
end end
def build_status_color(data) def build_status_color(data)
if data[:commit][:status] == 'success' return unless data && data[:object_kind] == 'build'
case data[:commit][:status]
when 'success'
'green' 'green'
else else
'red' 'red'
end if data[:object_kind] == 'build' end
end end
def project_name def project_name
......
...@@ -340,18 +340,36 @@ describe HipchatService, models: true do ...@@ -340,18 +340,36 @@ describe HipchatService, models: true do
end end
context "#message_options" do context "#message_options" do
it "should be set to the defaults" do it "is set to the defaults" do
expect(hipchat.send(:message_options)).to eq({ notify: false, color: 'yellow' }) expect(hipchat.__send__(:message_options)).to eq({ notify: false, color: 'yellow' })
end end
it "should set notfiy to true" do it "sets notify to true" do
allow(hipchat).to receive(:notify).and_return('1') allow(hipchat).to receive(:notify).and_return('1')
expect(hipchat.send(:message_options)).to eq({ notify: true, color: 'yellow' })
expect(hipchat.__send__(:message_options)).to eq({ notify: true, color: 'yellow' })
end end
it "should set the color" do it "sets the color" do
allow(hipchat).to receive(:color).and_return('red') allow(hipchat).to receive(:color).and_return('red')
expect(hipchat.send(:message_options)).to eq({ notify: false, color: 'red' })
expect(hipchat.__send__(:message_options)).to eq({ notify: false, color: 'red' })
end
context 'with a successful build' do
it 'uses the green color' do
build_data = { object_kind: 'build', commit: { status: 'success' } }
expect(hipchat.__send__(:message_options, build_data)).to eq({ notify: false, color: 'green' })
end
end
context 'with a failed build' do
it 'uses the red color' do
build_data = { object_kind: 'build', commit: { status: 'failed' } }
expect(hipchat.__send__(:message_options, build_data)).to eq({ notify: false, color: 'red' })
end
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