Commit 1f1aafab authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'move_slack_notifier_module_to_own_file' into 'master'

Move SlackService::Notifier module into file

See merge request gitlab-org/gitlab!53657
parents 2ac9a385 3a41ec4e
# frozen_string_literal: true # frozen_string_literal: true
class MattermostService < ChatNotificationService class MattermostService < ChatNotificationService
include ::SlackService::Notifier include SlackMattermost::Notifier
def title def title
'Mattermost notifications' 'Mattermost notifications'
......
# frozen_string_literal: true
module SlackMattermost
module Notifier
private
def notify(message, opts)
# See https://gitlab.com/gitlab-org/slack-notifier/#custom-http-client
notifier = Slack::Messenger.new(webhook, opts.merge(http_client: HTTPClient))
notifier.ping(
message.pretext,
attachments: message.attachments,
fallback: message.fallback
)
end
class HTTPClient
def self.post(uri, params = {})
params.delete(:http_options) # these are internal to the client and we do not want them
Gitlab::HTTP.post(uri, body: params)
end
end
end
end
# frozen_string_literal: true # frozen_string_literal: true
class SlackService < ChatNotificationService class SlackService < ChatNotificationService
include SlackMattermost::Notifier
prop_accessor EVENT_CHANNEL['alert'] prop_accessor EVENT_CHANNEL['alert']
def title def title
...@@ -35,27 +37,4 @@ class SlackService < ChatNotificationService ...@@ -35,27 +37,4 @@ class SlackService < ChatNotificationService
super super
end end
module Notifier
private
def notify(message, opts)
# See https://gitlab.com/gitlab-org/slack-notifier/#custom-http-client
notifier = Slack::Messenger.new(webhook, opts.merge(http_client: HTTPClient))
notifier.ping(
message.pretext,
attachments: message.attachments,
fallback: message.fallback
)
end
class HTTPClient
def self.post(uri, params = {})
params.delete(:http_options) # these are internal to the client and we do not want them
Gitlab::HTTP.post(uri, body: params)
end
end
end
include Notifier
end end
...@@ -7,7 +7,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name| ...@@ -7,7 +7,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
let(:webhook_url) { 'https://example.gitlab.com' } let(:webhook_url) { 'https://example.gitlab.com' }
def execute_with_options(options) def execute_with_options(options)
receive(:new).with(webhook_url, options.merge(http_client: SlackService::Notifier::HTTPClient)) receive(:new).with(webhook_url, options.merge(http_client: SlackMattermost::Notifier::HTTPClient))
.and_return(double(:slack_service).as_null_object) .and_return(double(:slack_service).as_null_object)
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