2018-08-10 02:45:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-20 16:14:33 -05:00
|
|
|
class SlackService < ChatNotificationService
|
2014-03-18 13:27:03 -04:00
|
|
|
def title
|
2016-11-25 14:36:37 -05:00
|
|
|
'Slack notifications'
|
2014-03-18 13:27:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2016-11-25 14:36:37 -05:00
|
|
|
'Receive event notifications in Slack'
|
2014-03-18 13:27:03 -04:00
|
|
|
end
|
|
|
|
|
2016-12-27 07:44:24 -05:00
|
|
|
def self.to_param
|
2016-12-20 16:14:33 -05:00
|
|
|
'slack'
|
2014-03-18 13:27:03 -04:00
|
|
|
end
|
|
|
|
|
2016-12-22 13:12:35 -05:00
|
|
|
def default_channel_placeholder
|
2020-02-25 16:09:23 -05:00
|
|
|
_('Slack channels (e.g. general, development)')
|
2016-07-29 12:59:54 -04:00
|
|
|
end
|
2017-03-22 15:54:17 -04:00
|
|
|
|
|
|
|
def webhook_placeholder
|
|
|
|
'https://hooks.slack.com/services/…'
|
|
|
|
end
|
2019-09-27 07:35:37 -04:00
|
|
|
|
|
|
|
module Notifier
|
|
|
|
private
|
|
|
|
|
|
|
|
def notify(message, opts)
|
2020-02-25 16:09:23 -05: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 07:35:37 -04: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 13:27:03 -04:00
|
|
|
end
|