2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class SlackService < ChatNotificationService
|
2021-04-17 20:07:23 +05:30
|
|
|
include SlackMattermost::Notifier
|
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
|
|
|
|
SUPPORTED_EVENTS_FOR_USAGE_LOG = %w[
|
|
|
|
push issue confidential_issue merge_request note confidential_note
|
|
|
|
tag_push wiki_page deployment
|
|
|
|
].freeze
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
prop_accessor EVENT_CHANNEL['alert']
|
|
|
|
|
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
|
2021-04-29 21:17:54 +05:30
|
|
|
'Send notifications about project events to 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
|
2021-04-29 21:17:54 +05:30
|
|
|
_('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
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def supported_events
|
|
|
|
additional = []
|
|
|
|
additional << 'alert'
|
|
|
|
|
|
|
|
super + additional
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_message(object_kind, data)
|
|
|
|
return ChatMessage::AlertMessage.new(data) if object_kind == 'alert'
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
override :log_usage
|
|
|
|
def log_usage(event, user_id)
|
|
|
|
return unless user_id
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
return unless SUPPORTED_EVENTS_FOR_USAGE_LOG.include?(event)
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
key = "i_ecosystem_slack_service_#{event}_notification"
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(key, values: user_id)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|