Commit 0600cde6 authored by Markus Koller's avatar Markus Koller

Fix pipeline notifications for Webex Teams / Unify Circuit integrations

The Webex Teams and Unify Circuit integrations didn't work correctly for
pipeline notifications, because they were using the method
`ChatMessage::PipelineMessage#pretext` which is overriden to always
return an empty string.

We can fix this by calling `#summary` instead, which is also what
`ChatMessage::BaseMessage#pretext` does by default. No other message
types override `#pretext` or `#summary`, so this change should be
backwards-compatible.
parent 0afccd2a
...@@ -47,7 +47,7 @@ class UnifyCircuitService < ChatNotificationService ...@@ -47,7 +47,7 @@ class UnifyCircuitService < ChatNotificationService
def notify(message, opts) def notify(message, opts)
response = Gitlab::HTTP.post(webhook, body: { response = Gitlab::HTTP.post(webhook, body: {
subject: message.project_name, subject: message.project_name,
text: message.pretext, text: message.summary,
markdown: true markdown: true
}.to_json) }.to_json)
......
...@@ -46,7 +46,7 @@ class WebexTeamsService < ChatNotificationService ...@@ -46,7 +46,7 @@ class WebexTeamsService < ChatNotificationService
def notify(message, opts) def notify(message, opts)
header = { 'Content-Type' => 'application/json' } header = { 'Content-Type' => 'application/json' }
response = Gitlab::HTTP.post(webhook, headers: header, body: { markdown: message.pretext }.to_json) response = Gitlab::HTTP.post(webhook, headers: header, body: { markdown: message.summary }.to_json)
response if response.success? response if response.success?
end end
......
---
title: Fix pipeline notifications for Webex Teams / Unify Circuit integrations
merge_request: 54852
author:
type: fixed
...@@ -6,7 +6,16 @@ RSpec.describe DiscordService do ...@@ -6,7 +6,16 @@ RSpec.describe DiscordService do
it_behaves_like "chat service", "Discord notifications" do it_behaves_like "chat service", "Discord notifications" do
let(:client) { Discordrb::Webhooks::Client } let(:client) { Discordrb::Webhooks::Client }
let(:client_arguments) { { url: webhook_url } } let(:client_arguments) { { url: webhook_url } }
let(:content_key) { :content } let(:payload) do
{
embeds: [
include(
author: include(name: be_present),
description: be_present
)
]
}
end
end end
describe '#execute' do describe '#execute' do
......
...@@ -6,6 +6,10 @@ RSpec.describe HangoutsChatService do ...@@ -6,6 +6,10 @@ RSpec.describe HangoutsChatService do
it_behaves_like "chat service", "Hangouts Chat" do it_behaves_like "chat service", "Hangouts Chat" do
let(:client) { HangoutsChat::Sender } let(:client) { HangoutsChat::Sender }
let(:client_arguments) { webhook_url } let(:client_arguments) { webhook_url }
let(:content_key) { :text } let(:payload) do
{
text: be_present
}
end
end end
end end
...@@ -5,6 +5,12 @@ require "spec_helper" ...@@ -5,6 +5,12 @@ require "spec_helper"
RSpec.describe UnifyCircuitService do RSpec.describe UnifyCircuitService do
it_behaves_like "chat service", "Unify Circuit" do it_behaves_like "chat service", "Unify Circuit" do
let(:client_arguments) { webhook_url } let(:client_arguments) { webhook_url }
let(:content_key) { :subject } let(:payload) do
{
subject: project.full_name,
text: be_present,
markdown: true
}
end
end end
end end
...@@ -5,6 +5,10 @@ require "spec_helper" ...@@ -5,6 +5,10 @@ require "spec_helper"
RSpec.describe WebexTeamsService do RSpec.describe WebexTeamsService do
it_behaves_like "chat service", "Webex Teams" do it_behaves_like "chat service", "Webex Teams" do
let(:client_arguments) { webhook_url } let(:client_arguments) { webhook_url }
let(:content_key) { :markdown } let(:payload) do
{
markdown: be_present
}
end
end end
end end
...@@ -53,9 +53,13 @@ RSpec.shared_examples "chat service" do |service_name| ...@@ -53,9 +53,13 @@ RSpec.shared_examples "chat service" do |service_name|
end end
it "calls #{service_name} API" do it "calls #{service_name} API" do
subject.execute(sample_data) result = subject.execute(sample_data)
expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"#{content_key}":.+}\Z/ }.once expect(result).to be(true)
expect(WebMock).to have_requested(:post, webhook_url).once.with { |req|
json_body = Gitlab::Json.parse(req.body).with_indifferent_access
expect(json_body).to include(payload)
}
end end
end end
...@@ -67,7 +71,8 @@ RSpec.shared_examples "chat service" do |service_name| ...@@ -67,7 +71,8 @@ RSpec.shared_examples "chat service" do |service_name|
it "does not call #{service_name} API" do it "does not call #{service_name} API" do
result = subject.execute(sample_data) result = subject.execute(sample_data)
expect(result).to be_falsy expect(result).to be(false)
expect(WebMock).not_to have_requested(:post, webhook_url)
end end
end end
......
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