debian-mirror-gitlab/app/models/concerns/integrations/slack_mattermost_notifier.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.3 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
2021-09-04 01:27:46 +05:30
module Integrations
module SlackMattermostNotifier
2021-04-17 20:07:23 +05:30
private
def notify(message, opts)
# See https://gitlab.com/gitlab-org/slack-notifier/#custom-http-client
2022-01-12 12:59:36 +05:30
#
# TODO: By default both Markdown and HTML links are converted into Slack "mrkdwn" syntax,
# but it seems we only need to support Markdown and could disable HTML.
#
# See:
# - https://gitlab.com/gitlab-org/slack-notifier#middleware
# - https://gitlab.com/gitlab-org/gitlab/-/issues/347048
2021-09-04 01:27:46 +05:30
notifier = ::Slack::Messenger.new(webhook, opts.merge(http_client: HTTPClient))
2022-07-16 23:28:13 +05:30
responses = notifier.ping(
2021-04-17 20:07:23 +05:30
message.pretext,
attachments: message.attachments,
fallback: message.fallback
)
2022-07-16 23:28:13 +05:30
responses.each do |response|
2022-10-11 01:57:18 +05:30
next if response.success?
log_error('SlackMattermostNotifier HTTP error response',
request_host: response.request.uri.host,
response_code: response.code,
response_body: response.body
)
2022-07-16 23:28:13 +05:30
end
2021-04-17 20:07:23 +05:30
end
class HTTPClient
def self.post(uri, params = {})
params.delete(:http_options) # these are internal to the client and we do not want them
2022-08-13 15:12:31 +05:30
Gitlab::HTTP.post(uri, body: params)
2021-04-17 20:07:23 +05:30
end
end
end
end