2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class SlackService < ChatNotificationService
|
2014-09-02 18:07:02 +05:30
|
|
|
def title
|
2017-08-17 22:00:37 +05:30
|
|
|
'Slack notifications'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2017-08-17 22:00:37 +05:30
|
|
|
'Receive event notifications in Slack'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def self.to_param
|
2014-09-02 18:07:02 +05:30
|
|
|
'slack'
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def default_channel_placeholder
|
2020-04-08 14:13:33 +05:30
|
|
|
_('Slack channels (e.g. general, development)')
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def webhook_placeholder
|
|
|
|
'https://hooks.slack.com/services/…'
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
module Notifier
|
|
|
|
private
|
|
|
|
|
|
|
|
def notify(message, opts)
|
2020-04-08 14:13:33 +05:30
|
|
|
# See https://gitlab.com/gitlab-org/slack-notifier/#custom-http-client
|
|
|
|
notifier = Slack::Messenger.new(webhook, opts.merge(http_client: HTTPClient))
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
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-09-02 18:07:02 +05:30
|
|
|
end
|