diff options
author | Robert Speicher <robert@gitlab.com> | 2016-07-27 19:01:37 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-07-27 19:01:37 +0300 |
commit | ccb5daee5926b83c3c580d9d64a141d7155894a6 (patch) | |
tree | 1272a83ec3fc56cd074f8a2fea06e78b3741d927 /app/models | |
parent | a8bbeb48bbeace8760f7420fc2f2c999a092182f (diff) | |
parent | 386478d800e2e098371d27817ebda6627d6838bc (diff) |
Merge branch '5571-hipchat-notifications-missing-colors' into 'master'
Resolve "HipChat notifications missing colors"
_Originally opened at !2322 by @eisnerd._
- - -
## What does this MR do?
This MR restores the colors mentioned in #5571 by overriding the color setting with green/red just for build events.
## What are the relevant issue numbers?
Closes #5571.
See merge request !5498
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project_services/hipchat_service.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index 23e5b16221b..d7c986c1a91 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -46,7 +46,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, message_options) + gate[room].send('GitLab', message, message_options(data)) end def test(data) @@ -67,8 +67,8 @@ class HipchatService < Service @gate ||= HipChat::Client.new(token, options) end - def message_options - { notify: notify.present? && notify == '1', color: color || 'yellow' } + def message_options(data = nil) + { notify: notify.present? && notify == '1', color: message_color(data) } end def create_message(data) @@ -240,6 +240,21 @@ class HipchatService < Service "#{project_link}: Commit #{commit_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status(status)} in #{duration} second(s)" end + def message_color(data) + build_status_color(data) || color || 'yellow' + end + + def build_status_color(data) + return unless data && data[:object_kind] == 'build' + + case data[:commit][:status] + when 'success' + 'green' + else + 'red' + end + end + def project_name project.name_with_namespace.gsub(/\s/, '') end |