Merge branch 'issue_25887' into 'master'

Do not override incoming webhook channel for mattermost and slack

Closes #25887

See merge request !8270
parent 7a2a5dd3
...@@ -49,11 +49,13 @@ class ChatNotificationService < Service ...@@ -49,11 +49,13 @@ class ChatNotificationService < Service
return false unless message return false unless message
opt = {} channel_name = get_channel_field(object_kind).presence || channel
opt[:channel] = get_channel_field(object_kind).presence || channel || default_channel opts = {}
opt[:username] = username if username opts[:channel] = channel_name if channel_name
notifier = Slack::Notifier.new(webhook, opt) opts[:username] = username if username
notifier = Slack::Notifier.new(webhook, opts)
notifier.ping(message.pretext, attachments: message.attachments, fallback: message.fallback) notifier.ping(message.pretext, attachments: message.attachments, fallback: message.fallback)
true true
...@@ -71,7 +73,7 @@ class ChatNotificationService < Service ...@@ -71,7 +73,7 @@ class ChatNotificationService < Service
fields.reject { |field| field[:name].end_with?('channel') } fields.reject { |field| field[:name].end_with?('channel') }
end end
def default_channel def default_channel_placeholder
raise NotImplementedError raise NotImplementedError
end end
...@@ -103,7 +105,7 @@ class ChatNotificationService < Service ...@@ -103,7 +105,7 @@ class ChatNotificationService < Service
def build_event_channels def build_event_channels
supported_events.reduce([]) do |channels, event| supported_events.reduce([]) do |channels, event|
channels << { type: 'text', name: event_channel_name(event), placeholder: default_channel } channels << { type: 'text', name: event_channel_name(event), placeholder: default_channel_placeholder }
end end
end end
......
...@@ -35,7 +35,7 @@ class MattermostService < ChatNotificationService ...@@ -35,7 +35,7 @@ class MattermostService < ChatNotificationService
] ]
end end
def default_channel def default_channel_placeholder
"#town-square" "#town-square"
end end
end end
...@@ -34,7 +34,7 @@ class SlackService < ChatNotificationService ...@@ -34,7 +34,7 @@ class SlackService < ChatNotificationService
] ]
end end
def default_channel def default_channel_placeholder
"#general" "#general"
end end
end end
---
title: Do not override incoming webhook for mattermost and slack
merge_request:
author:
...@@ -105,7 +105,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do ...@@ -105,7 +105,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do
allow(chat_service).to receive(:username).and_return(username) allow(chat_service).to receive(:username).and_return(username)
expect(Slack::Notifier).to receive(:new). expect(Slack::Notifier).to receive(:new).
with(webhook_url, username: username, channel: chat_service.default_channel). with(webhook_url, username: username).
and_return( and_return(
double(:slack_service).as_null_object double(:slack_service).as_null_object
) )
......
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