gitlab-org--gitlab-foss/app/models/project_services/slack_service.rb

48 lines
1,008 B
Ruby
Raw Normal View History

# frozen_string_literal: true
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
def self.to_param
'slack'
2014-03-18 13:27:03 -04:00
end
def default_channel_placeholder
_('Slack channels (e.g. general, development)')
end
def webhook_placeholder
'https://hooks.slack.com/services/…'
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
2014-03-18 13:27:03 -04:00
end