diff options
Diffstat (limited to 'app/models/project_services/chat_message/push_message.rb')
-rw-r--r-- | app/models/project_services/chat_message/push_message.rb | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/app/models/project_services/chat_message/push_message.rb b/app/models/project_services/chat_message/push_message.rb index 82be33a12a1..5dd0414b7e6 100644 --- a/app/models/project_services/chat_message/push_message.rb +++ b/app/models/project_services/chat_message/push_message.rb @@ -26,16 +26,8 @@ module ChatMessage end def activity - action = if new_branch? - "created" - elsif removed_branch? - "removed" - else - "pushed to" - end - { - title: "#{user_combined_name} #{action} #{ref_type}", + title: humanized_action(short: true), subtitle: "in #{project_link}", text: compare_link, image: user_avatar @@ -44,32 +36,21 @@ module ChatMessage private + def humanized_action(short: false) + action, ref_link, target_link = compose_action_details + text = [user_combined_name, action, ref_type, ref_link] + text << target_link unless short + text.join(' ') + end + def message - if new_branch? - new_branch_message - elsif removed_branch? - removed_branch_message - else - push_message - end + humanized_action end def format(string) Slack::Notifier::LinkFormatter.format(string) end - def new_branch_message - "#{user_combined_name} pushed new #{ref_type} #{branch_link} to #{project_link}" - end - - def removed_branch_message - "#{user_combined_name} removed #{ref_type} #{ref} from #{project_link}" - end - - def push_message - "#{user_combined_name} pushed to #{ref_type} #{branch_link} of #{project_link} (#{compare_link})" - end - def commit_messages commits.map { |commit| compose_commit_message(commit) }.join("\n\n") end @@ -115,6 +96,16 @@ module ChatMessage "[Compare changes](#{compare_url})" end + def compose_action_details + if new_branch? + ['pushed new', branch_link, "to #{project_link}"] + elsif removed_branch? + ['removed', ref, "from #{project_link}"] + else + ['pushed to', branch_link, "of #{project_link} (#{compare_link})"] + end + end + def attachment_color '#345' end |