Commit 3a41ec4e authored by Andy Soiron's avatar Andy Soiron Committed by Vitali Tatarintev

Move SlackService::Notifier module into file

The module is also used in MattermostService
to make it more clear that it is not a SlackService
internal. This commit moves it into its own file
parent d6d09424
# frozen_string_literal: true
class MattermostService < ChatNotificationService
include ::SlackService::Notifier
include SlackMattermost::Notifier
def title
'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
class SlackService < ChatNotificationService
include SlackMattermost::Notifier
prop_accessor EVENT_CHANNEL['alert']
def title
......@@ -35,27 +37,4 @@ class SlackService < ChatNotificationService
super
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
......@@ -7,7 +7,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
let(:webhook_url) { 'https://example.gitlab.com' }
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)
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