Commit 2b404911 authored by Mats Estensen's avatar Mats Estensen Committed by Lin Jen-Shin

Enhancement: Tag-specific url for tag pushes

Instead of the branch_url being set to `/commits/<ref>` for both tags
and regular pushes, branch_url is conditionally set to `/-/tags/<ref>`
for tags.
parent df5459d1
...@@ -75,11 +75,11 @@ module ChatMessage ...@@ -75,11 +75,11 @@ module ChatMessage
def activity def activity
{ {
title: s_("ChatMessage|Pipeline %{pipeline_link} of %{ref_type} %{branch_link} by %{user_combined_name} %{humanized_status}") % title: s_("ChatMessage|Pipeline %{pipeline_link} of %{ref_type} %{ref_link} by %{user_combined_name} %{humanized_status}") %
{ {
pipeline_link: pipeline_link, pipeline_link: pipeline_link,
ref_type: ref_type, ref_type: ref_type,
branch_link: branch_link, ref_link: ref_link,
user_combined_name: user_combined_name, user_combined_name: user_combined_name,
humanized_status: humanized_status humanized_status: humanized_status
}, },
...@@ -123,7 +123,7 @@ module ChatMessage ...@@ -123,7 +123,7 @@ module ChatMessage
fields = [ fields = [
{ {
title: ref_type == "tag" ? s_("ChatMessage|Tag") : s_("ChatMessage|Branch"), title: ref_type == "tag" ? s_("ChatMessage|Tag") : s_("ChatMessage|Branch"),
value: Slack::Notifier::LinkFormatter.format(ref_name_link), value: Slack::Notifier::LinkFormatter.format(ref_link),
short: true short: true
}, },
{ {
...@@ -141,12 +141,12 @@ module ChatMessage ...@@ -141,12 +141,12 @@ module ChatMessage
end end
def message def message
s_("ChatMessage|%{project_link}: Pipeline %{pipeline_link} of %{ref_type} %{branch_link} by %{user_combined_name} %{humanized_status} in %{duration}") % s_("ChatMessage|%{project_link}: Pipeline %{pipeline_link} of %{ref_type} %{ref_link} by %{user_combined_name} %{humanized_status} in %{duration}") %
{ {
project_link: project_link, project_link: project_link,
pipeline_link: pipeline_link, pipeline_link: pipeline_link,
ref_type: ref_type, ref_type: ref_type,
branch_link: branch_link, ref_link: ref_link,
user_combined_name: user_combined_name, user_combined_name: user_combined_name,
humanized_status: humanized_status, humanized_status: humanized_status,
duration: pretty_duration(duration) duration: pretty_duration(duration)
...@@ -193,12 +193,16 @@ module ChatMessage ...@@ -193,12 +193,16 @@ module ChatMessage
end end
end end
def branch_url def ref_url
"#{project_url}/commits/#{ref}" if ref_type == 'tag'
"#{project_url}/-/tags/#{ref}"
else
"#{project_url}/commits/#{ref}"
end
end end
def branch_link def ref_link
"[#{ref}](#{branch_url})" "[#{ref}](#{ref_url})"
end end
def project_url def project_url
...@@ -266,14 +270,6 @@ module ChatMessage ...@@ -266,14 +270,6 @@ module ChatMessage
"[#{commit.title}](#{commit_url})" "[#{commit.title}](#{commit_url})"
end end
def commits_page_url
"#{project_url}/commits/#{ref}"
end
def ref_name_link
"[#{ref}](#{commits_page_url})"
end
def author_url def author_url
return unless user && committer return unless user && committer
......
...@@ -82,16 +82,20 @@ module ChatMessage ...@@ -82,16 +82,20 @@ module ChatMessage
Gitlab::Git.blank_ref?(after) Gitlab::Git.blank_ref?(after)
end end
def branch_url def ref_url
"#{project_url}/commits/#{ref}" if ref_type == 'tag'
"#{project_url}/-/tags/#{ref}"
else
"#{project_url}/commits/#{ref}"
end
end end
def compare_url def compare_url
"#{project_url}/compare/#{before}...#{after}" "#{project_url}/compare/#{before}...#{after}"
end end
def branch_link def ref_link
"[#{ref}](#{branch_url})" "[#{ref}](#{ref_url})"
end end
def project_link def project_link
...@@ -104,11 +108,11 @@ module ChatMessage ...@@ -104,11 +108,11 @@ module ChatMessage
def compose_action_details def compose_action_details
if new_branch? if new_branch?
['pushed new', branch_link, "to #{project_link}"] ['pushed new', ref_link, "to #{project_link}"]
elsif removed_branch? elsif removed_branch?
['removed', ref, "from #{project_link}"] ['removed', ref, "from #{project_link}"]
else else
['pushed to', branch_link, "of #{project_link} (#{compare_link})"] ['pushed to', ref_link, "of #{project_link} (#{compare_link})"]
end end
end end
......
---
title: "Show tag link whenever it's a tag in chat message integration for push events and pipeline events"
merge_request: 18126
author: Mats Estensen
type: fixed
...@@ -2964,7 +2964,7 @@ msgstr "" ...@@ -2964,7 +2964,7 @@ msgstr ""
msgid "Chat" msgid "Chat"
msgstr "" msgstr ""
msgid "ChatMessage|%{project_link}: Pipeline %{pipeline_link} of %{ref_type} %{branch_link} by %{user_combined_name} %{humanized_status} in %{duration}" msgid "ChatMessage|%{project_link}: Pipeline %{pipeline_link} of %{ref_type} %{ref_link} by %{user_combined_name} %{humanized_status} in %{duration}"
msgstr "" msgstr ""
msgid "ChatMessage|Branch" msgid "ChatMessage|Branch"
...@@ -2985,7 +2985,7 @@ msgstr "" ...@@ -2985,7 +2985,7 @@ msgstr ""
msgid "ChatMessage|Pipeline #%{pipeline_id} %{humanized_status} in %{duration}" msgid "ChatMessage|Pipeline #%{pipeline_id} %{humanized_status} in %{duration}"
msgstr "" msgstr ""
msgid "ChatMessage|Pipeline %{pipeline_link} of %{ref_type} %{branch_link} by %{user_combined_name} %{humanized_status}" msgid "ChatMessage|Pipeline %{pipeline_link} of %{ref_type} %{ref_link} by %{user_combined_name} %{humanized_status}"
msgstr "" msgstr ""
msgid "ChatMessage|Tag" msgid "ChatMessage|Tag"
......
...@@ -159,6 +159,45 @@ describe ChatMessage::PipelineMessage do ...@@ -159,6 +159,45 @@ describe ChatMessage::PipelineMessage do
) )
end end
end end
context 'when ref type is tag' do
before do
args[:object_attributes][:tag] = true
args[:object_attributes][:ref] = 'new_tag'
end
it "returns the pipeline summary in the activity's title" do
expect(subject.activity[:title]).to eq(
"Pipeline [#123](http://example.gitlab.com/pipelines/123)" \
" of tag [new_tag](http://example.gitlab.com/-/tags/new_tag)" \
" by The Hacker (hacker) passed"
)
end
it "returns the pipeline summary as the attachment's text property" do
expect(subject.attachments.first[:text]).to eq(
"<http://example.gitlab.com|project_name>:" \
" Pipeline <http://example.gitlab.com/pipelines/123|#123>" \
" of tag <http://example.gitlab.com/-/tags/new_tag|new_tag>" \
" by The Hacker (hacker) passed in 02:00:10"
)
end
context 'when rendering markdown' do
before do
args[:markdown] = true
end
it 'returns the pipeline summary as the attachments in markdown format' do
expect(subject.attachments).to eq(
"[project_name](http://example.gitlab.com):" \
" Pipeline [#123](http://example.gitlab.com/pipelines/123)" \
" of tag [new_tag](http://example.gitlab.com/-/tags/new_tag)" \
" by The Hacker (hacker) passed in 02:00:10"
)
end
end
end
end end
context 'when the fancy_pipeline_slack_notifications feature flag is enabled' do context 'when the fancy_pipeline_slack_notifications feature flag is enabled' do
......
...@@ -96,7 +96,7 @@ describe ChatMessage::PushMessage do ...@@ -96,7 +96,7 @@ describe ChatMessage::PushMessage do
context 'without markdown' do context 'without markdown' do
it 'returns a message regarding pushes' do it 'returns a message regarding pushes' do
expect(subject.pretext).to eq('test.user pushed new tag ' \ expect(subject.pretext).to eq('test.user pushed new tag ' \
'<http://url.com/commits/new_tag|new_tag> to ' \ '<http://url.com/-/tags/new_tag|new_tag> to ' \
'<http://url.com|project_name>') '<http://url.com|project_name>')
expect(subject.attachments).to be_empty expect(subject.attachments).to be_empty
end end
...@@ -109,10 +109,10 @@ describe ChatMessage::PushMessage do ...@@ -109,10 +109,10 @@ describe ChatMessage::PushMessage do
it 'returns a message regarding pushes' do it 'returns a message regarding pushes' do
expect(subject.pretext).to eq( expect(subject.pretext).to eq(
'test.user pushed new tag [new_tag](http://url.com/commits/new_tag) to [project_name](http://url.com)') 'test.user pushed new tag [new_tag](http://url.com/-/tags/new_tag) to [project_name](http://url.com)')
expect(subject.attachments).to be_empty expect(subject.attachments).to be_empty
expect(subject.activity).to eq( expect(subject.activity).to eq(
title: 'test.user pushed new tag [new_tag](http://url.com/commits/new_tag)', title: 'test.user pushed new tag [new_tag](http://url.com/-/tags/new_tag)',
subtitle: 'in [project_name](http://url.com)', subtitle: 'in [project_name](http://url.com)',
text: '[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)', text: '[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)',
image: 'http://someavatar.com' image: 'http://someavatar.com'
......
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