Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
73a0ff41
Commit
73a0ff41
authored
Nov 19, 2018
by
Tony Castrogiovanni
Committed by
Douglas Barbosa Alexandre
Nov 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for surfacing a link to the branch or tag name in push message…
parent
3eb36672
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
40 deletions
+77
-40
app/models/project_services/chat_message/push_message.rb
app/models/project_services/chat_message/push_message.rb
+19
-28
changelogs/unreleased/51959-branch-and-tag-name-links.yml
changelogs/unreleased/51959-branch-and-tag-name-links.yml
+5
-0
spec/models/project_services/chat_message/push_message_spec.rb
...models/project_services/chat_message/push_message_spec.rb
+53
-12
No files found.
app/models/project_services/chat_message/push_message.rb
View file @
73a0ff41
...
...
@@ -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
...
...
changelogs/unreleased/51959-branch-and-tag-name-links.yml
0 → 100644
View file @
73a0ff41
---
title
:
Chat message push notifications now include links back to GitLab branches
merge_request
:
22651
author
:
Tony Castrogiovanni
type
:
added
spec/models/project_services/chat_message/push_message_spec.rb
View file @
73a0ff41
...
...
@@ -48,12 +48,12 @@ describe ChatMessage::PushMessage do
'test.user pushed to branch [master](http://url.com/commits/master) of [project_name](http://url.com) ([Compare changes](http://url.com/compare/before...after))'
)
expect
(
subject
.
attachments
).
to
eq
(
"[abcdefgh](http://url1.com): message1 - author1
\n\n
[12345678](http://url2.com): message2 - author2"
)
expect
(
subject
.
activity
).
to
eq
(
{
title:
'test.user pushed to branch'
,
expect
(
subject
.
activity
).
to
eq
(
title:
'test.user pushed to branch
[master](http://url.com/commits/master)
'
,
subtitle:
'in [project_name](http://url.com)'
,
text:
'[Compare changes](http://url.com/compare/before...after)'
,
image:
'http://someavatar.com'
}
)
)
end
end
end
...
...
@@ -89,12 +89,53 @@ describe ChatMessage::PushMessage 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)'
)
expect
(
subject
.
attachments
).
to
be_empty
expect
(
subject
.
activity
).
to
eq
(
{
title:
'test.user
created tag
'
,
expect
(
subject
.
activity
).
to
eq
(
title:
'test.user
pushed new tag [new_tag](http://url.com/commits/new_tag)
'
,
subtitle:
'in [project_name](http://url.com)'
,
text:
'[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)'
,
image:
'http://someavatar.com'
})
)
end
end
end
context
'removed tag'
do
let
(
:args
)
do
{
after:
Gitlab
::
Git
::
BLANK_SHA
,
before:
'before'
,
project_name:
'project_name'
,
ref:
'refs/tags/new_tag'
,
user_name:
'test.user'
,
user_avatar:
'http://someavatar.com'
,
project_url:
'http://url.com'
}
end
context
'without markdown'
do
it
'returns a message regarding removal of tags'
do
expect
(
subject
.
pretext
).
to
eq
(
'test.user removed tag '
\
'new_tag from '
\
'<http://url.com|project_name>'
)
expect
(
subject
.
attachments
).
to
be_empty
end
end
context
'with markdown'
do
before
do
args
[
:markdown
]
=
true
end
it
'returns a message regarding removal of tags'
do
expect
(
subject
.
pretext
).
to
eq
(
'test.user removed tag new_tag from [project_name](http://url.com)'
)
expect
(
subject
.
attachments
).
to
be_empty
expect
(
subject
.
activity
).
to
eq
(
title:
'test.user removed tag new_tag'
,
subtitle:
'in [project_name](http://url.com)'
,
text:
'[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)'
,
image:
'http://someavatar.com'
)
end
end
end
...
...
@@ -122,12 +163,12 @@ describe ChatMessage::PushMessage do
expect
(
subject
.
pretext
).
to
eq
(
'test.user pushed new branch [master](http://url.com/commits/master) to [project_name](http://url.com)'
)
expect
(
subject
.
attachments
).
to
be_empty
expect
(
subject
.
activity
).
to
eq
(
{
title:
'test.user
created branch
'
,
expect
(
subject
.
activity
).
to
eq
(
title:
'test.user
pushed new branch [master](http://url.com/commits/master)
'
,
subtitle:
'in [project_name](http://url.com)'
,
text:
'[Compare changes](http://url.com/compare/0000000000000000000000000000000000000000...after)'
,
image:
'http://someavatar.com'
}
)
)
end
end
end
...
...
@@ -154,12 +195,12 @@ describe ChatMessage::PushMessage do
expect
(
subject
.
pretext
).
to
eq
(
'test.user removed branch master from [project_name](http://url.com)'
)
expect
(
subject
.
attachments
).
to
be_empty
expect
(
subject
.
activity
).
to
eq
(
{
title:
'test.user removed branch'
,
expect
(
subject
.
activity
).
to
eq
(
title:
'test.user removed branch
master
'
,
subtitle:
'in [project_name](http://url.com)'
,
text:
'[Compare changes](http://url.com/compare/before...0000000000000000000000000000000000000000)'
,
image:
'http://someavatar.com'
}
)
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment