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
def notify(message, opts)
response = Gitlab::HTTP.post(webhook, body: {
subject: message.project_name,
text: message.pretext,
text: message.summary,
markdown: true
}.to_json)
......
......@@ -46,7 +46,7 @@ class WebexTeamsService < ChatNotificationService
def notify(message, opts)
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?
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
it_behaves_like "chat service", "Discord notifications" do
let(:client) { Discordrb::Webhooks::Client }
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
describe '#execute' do
......
......@@ -6,6 +6,10 @@ RSpec.describe HangoutsChatService do
it_behaves_like "chat service", "Hangouts Chat" do
let(:client) { HangoutsChat::Sender }
let(:client_arguments) { webhook_url }
let(:content_key) { :text }
let(:payload) do
{
text: be_present
}
end
end
end
......@@ -5,6 +5,12 @@ require "spec_helper"
RSpec.describe UnifyCircuitService do
it_behaves_like "chat service", "Unify Circuit" do
let(:client_arguments) { webhook_url }
let(:content_key) { :subject }
let(:payload) do
{
subject: project.full_name,
text: be_present,
markdown: true
}
end
end
end
......@@ -5,6 +5,10 @@ require "spec_helper"
RSpec.describe WebexTeamsService do
it_behaves_like "chat service", "Webex Teams" do
let(:client_arguments) { webhook_url }
let(:content_key) { :markdown }
let(:payload) do
{
markdown: be_present
}
end
end
end
......@@ -53,9 +53,13 @@ RSpec.shared_examples "chat service" do |service_name|
end
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
......@@ -67,7 +71,8 @@ RSpec.shared_examples "chat service" do |service_name|
it "does not call #{service_name} API" do
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
......
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