diff options
author | Federico Ravasio <ravasio.federico@gmail.com> | 2014-04-06 13:57:48 +0400 |
---|---|---|
committer | Federico Ravasio <ravasio.federico@gmail.com> | 2014-04-06 13:57:48 +0400 |
commit | 6a9eb4b231fc7e563b9c3551dafc5d1bfdc959b3 (patch) | |
tree | a87fb113d3c3b313fb63505122d42b367d683616 /app/models | |
parent | 2ceef7691795958e657f24d78089eecb0eb4a90d (diff) |
Improved Slack integration with message attachments.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project_services/slack_message.rb | 25 | ||||
-rw-r--r-- | app/models/project_services/slack_service.rb | 2 |
2 files changed, 21 insertions, 6 deletions
diff --git a/app/models/project_services/slack_message.rb b/app/models/project_services/slack_message.rb index b2b8d6fed7a..28204e5ea60 100644 --- a/app/models/project_services/slack_message.rb +++ b/app/models/project_services/slack_message.rb @@ -11,10 +11,16 @@ class SlackMessage @username = params.fetch(:user_name) end - def compose + def pretext format(message) end + def attachments + return [] if new_branch? || removed_branch? + + commit_message_attachments + end + private attr_reader :after @@ -31,7 +37,7 @@ class SlackMessage elsif removed_branch? removed_branch_message else - push_message << commit_messages + push_message end end @@ -54,15 +60,20 @@ class SlackMessage def commit_messages commits.each_with_object('') do |commit, str| str << compose_commit_message(commit) - end + end.chomp + end + + def commit_message_attachments + [{ text: format(commit_messages), color: attachment_color }] end def compose_commit_message(commit) - id = commit.fetch(:id)[0..5] + author = commit.fetch(:author).fetch(:name) + id = commit.fetch(:id)[0..8] message = commit.fetch(:message) url = commit.fetch(:url) - "\n - #{message} ([#{id}](#{url}))" + "[#{id}](#{url}): #{message} - #{author}\n" end def new_branch? @@ -92,4 +103,8 @@ class SlackMessage def compare_link "[Compare changes](#{compare_url})" end + + def attachment_color + '#345' + end end diff --git a/app/models/project_services/slack_service.rb b/app/models/project_services/slack_service.rb index 410dda22d47..a3697b31352 100644 --- a/app/models/project_services/slack_service.rb +++ b/app/models/project_services/slack_service.rb @@ -53,7 +53,7 @@ class SlackService < Service notifier = Slack::Notifier.new(subdomain, token) notifier.channel = room notifier.username = 'GitLab' - notifier.ping(message.compose) + notifier.ping(message.pretext, attachments: message.attachments) end private |