Merge branch '42342-teams-pipeline-notifications' into 'master'

Resolve "Microsoft Teams notification for pipelines do not work"

Closes #42342

See merge request gitlab-org/gitlab-ce!19632
This commit is contained in:
Douwe Maan 2018-06-13 08:23:32 +00:00
commit 504f362033
7 changed files with 20 additions and 9 deletions

View File

@ -26,13 +26,18 @@ module ChatMessage
end
end
def pretext
def summary
return message if markdown
format(message)
end
def pretext
summary
end
def fallback
format(message)
end
def attachments

View File

@ -23,10 +23,6 @@ module ChatMessage
''
end
def fallback
format(message)
end
def attachments
return message if markdown

View File

@ -44,7 +44,7 @@ class MicrosoftTeamsService < ChatNotificationService
def notify(message, opts)
MicrosoftTeams::Notifier.new(webhook).ping(
title: message.project_name,
pretext: message.pretext,
summary: message.summary,
activity: message.activity,
attachments: message.attachments
)

View File

@ -0,0 +1,5 @@
---
title: Fixes Microsoft Teams notifications for pipeline events
merge_request: 19632
author: Jeff Brown
type: fixed

View File

@ -30,7 +30,7 @@ module MicrosoftTeams
result = { 'sections' => [] }
result['title'] = options[:title]
result['summary'] = options[:pretext]
result['summary'] = options[:summary]
result['sections'] << MicrosoftTeams::Activity.new(options[:activity]).prepare
attachments = options[:attachments]

View File

@ -8,7 +8,7 @@ describe MicrosoftTeams::Notifier do
let(:options) do
{
title: 'JohnDoe4/project2',
pretext: '[[JohnDoe4/project2](http://localhost/namespace2/gitlabhq)] Issue [#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1) opened by user6',
summary: '[[JohnDoe4/project2](http://localhost/namespace2/gitlabhq)] Issue [#1 Awesome issue](http://localhost/namespace2/gitlabhq/issues/1) opened by user6',
activity: {
title: 'Issue opened by user6',
subtitle: 'in [JohnDoe4/project2](http://localhost/namespace2/gitlabhq)',

View File

@ -225,10 +225,15 @@ describe MicrosoftTeamsService do
it 'calls Microsoft Teams API for pipeline events' do
data = Gitlab::DataBuilder::Pipeline.build(pipeline)
data[:markdown] = true
chat_service.execute(data)
expect(WebMock).to have_requested(:post, webhook_url).once
message = ChatMessage::PipelineMessage.new(data)
expect(WebMock).to have_requested(:post, webhook_url)
.with(body: hash_including({ summary: message.summary }))
.once
end
end