2018-08-10 06:45:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-20 21:14:33 +00:00
|
|
|
class SlackService < ChatNotificationService
|
2014-03-18 17:27:03 +00:00
|
|
|
def title
|
2016-11-25 19:36:37 +00:00
|
|
|
'Slack notifications'
|
2014-03-18 17:27:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2016-11-25 19:36:37 +00:00
|
|
|
'Receive event notifications in Slack'
|
2014-03-18 17:27:03 +00:00
|
|
|
end
|
|
|
|
|
2016-12-27 12:44:24 +00:00
|
|
|
def self.to_param
|
2016-12-20 21:14:33 +00:00
|
|
|
'slack'
|
2014-03-18 17:27:03 +00:00
|
|
|
end
|
|
|
|
|
2016-12-22 18:12:35 +00:00
|
|
|
def default_channel_placeholder
|
2020-02-25 21:09:23 +00:00
|
|
|
_('Slack channels (e.g. general, development)')
|
2016-07-29 16:59:54 +00:00
|
|
|
end
|
2017-03-22 19:54:17 +00:00
|
|
|
|
|
|
|
def webhook_placeholder
|
|
|
|
'https://hooks.slack.com/services/…'
|
|
|
|
end
|
2019-09-27 11:35:37 +00:00
|
|
|
|
|
|
|
module Notifier
|
|
|
|
private
|
|
|
|
|
|
|
|
def notify(message, opts)
|
2020-02-25 21:09:23 +00:00
|
|
|
# See https://gitlab.com/gitlab-org/slack-notifier/#custom-http-client
|
|
|
|
notifier = Slack::Messenger.new(webhook, opts.merge(http_client: HTTPClient))
|
2019-09-27 11:35:37 +00:00
|
|
|
|
|
|
|
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
|
2014-03-18 17:27:03 +00:00
|
|
|
end
|