Commit 7d64e83b authored by Takuya Noguchi's avatar Takuya Noguchi Committed by Arturo Herrero

Use the commit title on chat service notification

instead of the full commit message as on it is not necessary to have
the full commit message on chat services.
Signed-off-by: default avatarTakuya Noguchi <takninnovationresearch@gmail.com>
parent de715ec8
...@@ -226,6 +226,7 @@ class Commit ...@@ -226,6 +226,7 @@ class Commit
data = { data = {
id: id, id: id,
message: safe_message, message: safe_message,
title: title,
timestamp: committed_date.xmlschema, timestamp: committed_date.xmlschema,
url: Gitlab::UrlBuilder.build(self), url: Gitlab::UrlBuilder.build(self),
author: { author: {
......
...@@ -12,7 +12,6 @@ module ChatMessage ...@@ -12,7 +12,6 @@ module ChatMessage
attr_reader :user_avatar attr_reader :user_avatar
attr_reader :project_name attr_reader :project_name
attr_reader :project_url attr_reader :project_url
attr_reader :commit_message_html
def initialize(params) def initialize(params)
@markdown = params[:markdown] || false @markdown = params[:markdown] || false
...@@ -21,7 +20,6 @@ module ChatMessage ...@@ -21,7 +20,6 @@ module ChatMessage
@user_full_name = params.dig(:user, :name) || params[:user_full_name] @user_full_name = params.dig(:user, :name) || params[:user_full_name]
@user_name = params.dig(:user, :username) || params[:user_name] @user_name = params.dig(:user, :username) || params[:user_name]
@user_avatar = params.dig(:user, :avatar_url) || params[:user_avatar] @user_avatar = params.dig(:user, :avatar_url) || params[:user_avatar]
@commit_message_html = params[:commit_message_html] || false
end end
def user_combined_name def user_combined_name
......
...@@ -52,8 +52,7 @@ module ChatMessage ...@@ -52,8 +52,7 @@ module ChatMessage
end end
def commit_messages def commit_messages
linebreak_chars = commit_message_html ? "<br/>\n<br/>\n" : "\n\n" commits.map { |commit| compose_commit_message(commit) }.join("\n\n")
commits.map { |commit| compose_commit_message(commit) }.join(linebreak_chars)
end end
def commit_message_attachments def commit_message_attachments
...@@ -63,15 +62,11 @@ module ChatMessage ...@@ -63,15 +62,11 @@ module ChatMessage
def compose_commit_message(commit) def compose_commit_message(commit)
author = commit[:author][:name] author = commit[:author][:name]
id = Commit.truncate_sha(commit[:id]) id = Commit.truncate_sha(commit[:id])
message = commit[:message] title = commit[:title]
if commit_message_html
message = message.gsub(Gitlab::Regex.breakline_regex, "<br/>\n")
end
url = commit[:url] url = commit[:url]
"[#{id}](#{url}): #{message} - #{author}" "[#{id}](#{url}): #{title} - #{author}"
end end
def new_branch? def new_branch?
......
...@@ -58,6 +58,6 @@ class MicrosoftTeamsService < ChatNotificationService ...@@ -58,6 +58,6 @@ class MicrosoftTeamsService < ChatNotificationService
end end
def custom_data(data) def custom_data(data)
super(data).merge(markdown: true, commit_message_html: true) super(data).merge(markdown: true)
end end
end end
---
title: Use only the first line of the commit message on chat service notification
merge_request: 25224
author: Takuya Noguchi
type: changed
...@@ -35,7 +35,8 @@ module Gitlab ...@@ -35,7 +35,8 @@ module Gitlab
commits: [ commits: [
{ {
id: "c5feabde2d8cd023215af4d2ceeb7a64839fc428", id: "c5feabde2d8cd023215af4d2ceeb7a64839fc428",
message: "Add simple search to projects in public area", message: "Add simple search to projects in public area\n\ncommit message body",
title: "Add simple search to projects in public area",
timestamp: "2013-05-13T18:18:08+00:00", timestamp: "2013-05-13T18:18:08+00:00",
url: "https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428", url: "https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428",
author: { author: {
......
...@@ -22,8 +22,14 @@ describe ChatMessage::PushMessage do ...@@ -22,8 +22,14 @@ describe ChatMessage::PushMessage do
context 'push' do context 'push' do
before do before do
args[:commits] = [ args[:commits] = [
{ message: 'message1', url: 'http://url1.com', id: 'abcdefghijkl', author: { name: 'author1' } }, { message: 'message1', title: 'message1', url: 'http://url1.com', id: 'abcdefghijkl', author: { name: 'author1' } },
{ message: "message2\nsecondline", url: 'http://url2.com', id: '123456789012', author: { name: 'author2' } } {
message: 'message2' + ' w' * 100 + "\nsecondline",
title: 'message2 w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w ...',
url: 'http://url2.com',
id: '123456789012',
author: { name: 'author2' }
}
] ]
end end
...@@ -34,7 +40,7 @@ describe ChatMessage::PushMessage do ...@@ -34,7 +40,7 @@ describe ChatMessage::PushMessage do
'<http://url.com|project_name> (<http://url.com/compare/before...after|Compare changes>)') '<http://url.com|project_name> (<http://url.com/compare/before...after|Compare changes>)')
expect(subject.attachments).to eq([{ expect(subject.attachments).to eq([{
text: "<http://url1.com|abcdefgh>: message1 - author1\n\n"\ text: "<http://url1.com|abcdefgh>: message1 - author1\n\n"\
"<http://url2.com|12345678>: message2\nsecondline - author2", "<http://url2.com|12345678>: message2 w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w ... - author2",
color: color color: color
}]) }])
end end
...@@ -49,27 +55,7 @@ describe ChatMessage::PushMessage do ...@@ -49,27 +55,7 @@ describe ChatMessage::PushMessage do
expect(subject.pretext).to eq( expect(subject.pretext).to eq(
'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))') '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( expect(subject.attachments).to eq(
"[abcdefgh](http://url1.com): message1 - author1\n\n[12345678](http://url2.com): message2\nsecondline - author2") "[abcdefgh](http://url1.com): message1 - author1\n\n[12345678](http://url2.com): message2 w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w ... - author2")
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
context 'with markdown and commit message html' do
before do
args[:commit_message_html] = true
args[:markdown] = true
end
it 'returns a message regarding pushes' do
expect(subject.pretext).to eq(
'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<br/>\n<br/>\n[12345678](http://url2.com): message2<br/>\nsecondline - author2")
expect(subject.activity).to eq( expect(subject.activity).to eq(
title: 'test.user pushed to branch [master](http://url.com/commits/master)', title: 'test.user pushed to branch [master](http://url.com/commits/master)',
subtitle: 'in [project_name](http://url.com)', subtitle: 'in [project_name](http://url.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