Commit 00b7b823 authored by Stan Hu's avatar Stan Hu

Merge branch '212073-slack-notifications-stop-working-after-updating-gitlab' into 'master'

Fix Slack notifications when upgrading from old GitLab versions

See merge request gitlab-org/gitlab!29111
parents 14bd47dc 8ac196c5
...@@ -84,10 +84,11 @@ class ChatNotificationService < Service ...@@ -84,10 +84,11 @@ class ChatNotificationService < Service
event_type = data[:event_type] || object_kind event_type = data[:event_type] || object_kind
channel_names = get_channel_field(event_type).presence || channel channel_names = get_channel_field(event_type).presence || channel.presence
channels = channel_names&.split(',')&.map(&:strip)
opts = {} opts = {}
opts[:channel] = channel_names.split(',').map(&:strip) if channel_names opts[:channel] = channels if channels.present?
opts[:username] = username if username opts[:username] = username if username
return false unless notify(message, opts) return false unless notify(message, opts)
......
---
title: Fix Slack notifications when upgrading from old GitLab versions
merge_request: 29111
author:
type: fixed
...@@ -75,6 +75,30 @@ describe ChatNotificationService do ...@@ -75,6 +75,30 @@ describe ChatNotificationService do
end end
end end
context 'with "channel" property' do
before do
allow(chat_service).to receive(:channel).and_return(channel)
end
context 'empty string' do
let(:channel) { '' }
it 'does not include the channel' do
expect(chat_service).to receive(:notify).with(any_args, hash_excluding(:channel)).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
context 'empty spaces' do
let(:channel) { ' ' }
it 'does not include the channel' do
expect(chat_service).to receive(:notify).with(any_args, hash_excluding(:channel)).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
end
shared_examples 'with channel specified' do |channel, expected_channels| shared_examples 'with channel specified' do |channel, expected_channels|
before do before do
allow(chat_service).to receive(:push_channel).and_return(channel) allow(chat_service).to receive(:push_channel).and_return(channel)
......
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