2021-05-31 23:10:06 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Integrations
|
|
|
|
class Slack < BaseChatNotification
|
2021-06-02 05:09:46 -04:00
|
|
|
include SlackMattermostNotifier
|
2021-05-31 23:10:06 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
prop_accessor EVENT_CHANNEL['alert']
|
|
|
|
|
|
|
|
def title
|
|
|
|
'Slack notifications'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
'Send notifications about project events to Slack.'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.to_param
|
|
|
|
'slack'
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_channel_placeholder
|
2021-06-08 20:10:20 -04:00
|
|
|
_('#general, #development')
|
2021-05-31 23:10:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def webhook_placeholder
|
|
|
|
'https://hooks.slack.com/services/…'
|
|
|
|
end
|
|
|
|
|
|
|
|
def supported_events
|
|
|
|
additional = []
|
|
|
|
additional << 'alert'
|
|
|
|
|
|
|
|
super + additional
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_message(object_kind, data)
|
|
|
|
return Integrations::ChatMessage::AlertMessage.new(data) if object_kind == 'alert'
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
override :log_usage
|
|
|
|
def log_usage(event, user_id)
|
|
|
|
return unless user_id
|
|
|
|
|
|
|
|
return unless SUPPORTED_EVENTS_FOR_USAGE_LOG.include?(event)
|
|
|
|
|
|
|
|
key = "i_ecosystem_slack_service_#{event}_notification"
|
|
|
|
|
|
|
|
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(key, values: user_id)
|
|
|
|
end
|
2022-06-20 23:08:34 -04:00
|
|
|
|
|
|
|
override :configurable_channels?
|
|
|
|
def configurable_channels?
|
|
|
|
true
|
|
|
|
end
|
2021-05-31 23:10:06 -04:00
|
|
|
end
|
|
|
|
end
|