Commit c6ee3d3c authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'change-tag-url' into 'master'

Change url for tag push events in chat message integration

See merge request gitlab-org/gitlab!18126
parents df5459d1 2b404911
......@@ -75,11 +75,11 @@ module ChatMessage
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,
ref_type: ref_type,
branch_link: branch_link,
ref_link: ref_link,
user_combined_name: user_combined_name,
humanized_status: humanized_status
},
......@@ -123,7 +123,7 @@ module ChatMessage
fields = [
{
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
},
{
......@@ -141,12 +141,12 @@ module ChatMessage
end
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,
pipeline_link: pipeline_link,
ref_type: ref_type,
branch_link: branch_link,
ref_link: ref_link,
user_combined_name: user_combined_name,
humanized_status: humanized_status,
duration: pretty_duration(duration)
......@@ -193,12 +193,16 @@ module ChatMessage
end
end
def branch_url
def ref_url
if ref_type == 'tag'
"#{project_url}/-/tags/#{ref}"
else
"#{project_url}/commits/#{ref}"
end
end
def branch_link
"[#{ref}](#{branch_url})"
def ref_link
"[#{ref}](#{ref_url})"
end
def project_url
......@@ -266,14 +270,6 @@ module ChatMessage
"[#{commit.title}](#{commit_url})"
end
def commits_page_url
"#{project_url}/commits/#{ref}"
end
def ref_name_link
"[#{ref}](#{commits_page_url})"
end
def author_url
return unless user && committer
......
......@@ -82,16 +82,20 @@ module ChatMessage
Gitlab::Git.blank_ref?(after)
end
def branch_url
def ref_url
if ref_type == 'tag'
"#{project_url}/-/tags/#{ref}"
else
"#{project_url}/commits/#{ref}"
end
end
def compare_url
"#{project_url}/compare/#{before}...#{after}"
end
def branch_link
"[#{ref}](#{branch_url})"
def ref_link
"[#{ref}](#{ref_url})"
end
def project_link
......@@ -104,11 +108,11 @@ module ChatMessage
def compose_action_details
if new_branch?
['pushed new', branch_link, "to #{project_link}"]
['pushed new', ref_link, "to #{project_link}"]
elsif removed_branch?
['removed', ref, "from #{project_link}"]
else
['pushed to', branch_link, "of #{project_link} (#{compare_link})"]
['pushed to', ref_link, "of #{project_link} (#{compare_link})"]
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 ""
msgid "Chat"
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 ""
msgid "ChatMessage|Branch"
......@@ -2985,7 +2985,7 @@ msgstr ""
msgid "ChatMessage|Pipeline #%{pipeline_id} %{humanized_status} in %{duration}"
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 ""
msgid "ChatMessage|Tag"
......
......@@ -159,6 +159,45 @@ describe ChatMessage::PipelineMessage do
)
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
context 'when the fancy_pipeline_slack_notifications feature flag is enabled' do
......
......@@ -96,7 +96,7 @@ describe ChatMessage::PushMessage do
context 'without markdown' do
it 'returns a message regarding pushes' do
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>')
expect(subject.attachments).to be_empty
end
......@@ -109,10 +109,10 @@ describe ChatMessage::PushMessage do
it 'returns a message regarding pushes' do
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.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)',
text: '[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)',
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