Commit 8ac196c5 authored by Justin Ho's avatar Justin Ho

Fix Slack notifications when upgrading

Make the presence check more robust to only allow
values that make sense.
parent 262be9c5
......@@ -84,10 +84,11 @@ class ChatNotificationService < Service
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[:channel] = channel_names.split(',').map(&:strip) if channel_names
opts[:channel] = channels if channels.present?
opts[:username] = username if username
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
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|
before do
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