debian-mirror-gitlab/app/models/project_services/slack_service.rb

58 lines
1.5 KiB
Ruby
Raw Normal View History

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
2015-09-25 12:07:36 +05:30
def help
2017-08-17 22:00:37 +05:30
'This service sends notifications about projects events to Slack channels.<br />
To set up this service:
<ol>
<li><a href="https://slack.com/apps/A0F7XDUAZ-incoming-webhooks">Add an incoming webhook</a> in your Slack team. The default channel can be overridden for each event.</li>
<li>Paste the <strong>Webhook URL</strong> into the field below.</li>
<li>Select events below to enable notifications. The <strong>Channel name</strong> and <strong>Username</strong> fields are optional.</li>
</ol>'
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
def default_channel_placeholder
"Channel name (e.g. general)"
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)
# See https://github.com/stevenosloan/slack-notifier#custom-http-client
notifier = Slack::Notifier.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-09-02 18:07:02 +05:30
end