diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 03:09:56 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 03:09:56 +0300 |
commit | cc626f14115f740bd4aa247cf3ac42dfb2082a4e (patch) | |
tree | b5c7f25711903177ea0e756b1fabd8eef2a9ca14 /app/models/integrations | |
parent | 19db7fd1fefc4e4249d4e55f409f321fdb85aed1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/integrations')
-rw-r--r-- | app/models/integrations/base_chat_notification.rb | 20 | ||||
-rw-r--r-- | app/models/integrations/base_slack_notification.rb | 8 | ||||
-rw-r--r-- | app/models/integrations/slack.rb | 7 |
3 files changed, 30 insertions, 5 deletions
diff --git a/app/models/integrations/base_chat_notification.rb b/app/models/integrations/base_chat_notification.rb index 750aa60b185..c7ab9befd12 100644 --- a/app/models/integrations/base_chat_notification.rb +++ b/app/models/integrations/base_chat_notification.rb @@ -33,7 +33,10 @@ module Integrations boolean_accessor :notify_only_broken_pipelines, :notify_only_default_branch - validates :webhook, presence: true, public_url: true, if: :activated? + validates :webhook, + presence: true, + public_url: true, + if: -> (integration) { integration.activated? && integration.requires_webhook? } validates :labels_to_be_notified_behavior, inclusion: { in: LABEL_NOTIFICATION_BEHAVIOURS }, allow_blank: true def initialize_properties @@ -73,8 +76,6 @@ module Integrations def default_fields [ - { type: 'text', name: 'webhook', help: "#{webhook_help}", required: true }.freeze, - { type: 'text', name: 'username', placeholder: 'GitLab-integration' }.freeze, { type: 'checkbox', name: 'notify_only_broken_pipelines', help: 'Do not send notifications for successful pipelines.' }.freeze, { type: 'select', @@ -96,7 +97,14 @@ module Integrations ['Match all of the labels', MATCH_ALL_LABELS] ] }.freeze - ].freeze + ].tap do |fields| + next unless requires_webhook? + + fields.unshift( + { type: 'text', name: 'webhook', help: "#{webhook_help}", required: true }.freeze, + { type: 'text', name: 'username', placeholder: 'GitLab-integration' }.freeze + ) + end.freeze end def execute(data) @@ -168,6 +176,10 @@ module Integrations self.public_send(field_name) # rubocop:disable GitlabSecurity/PublicSend end + def requires_webhook? + true + end + private def log_usage(_, _) diff --git a/app/models/integrations/base_slack_notification.rb b/app/models/integrations/base_slack_notification.rb index cb785afdcfe..cbfcb1807f0 100644 --- a/app/models/integrations/base_slack_notification.rb +++ b/app/models/integrations/base_slack_notification.rb @@ -32,13 +32,15 @@ module Integrations true end + private + 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" + key = "#{metrics_key_prefix}_#{event}_notification" Gitlab::UsageDataCounters::HLLRedisCounter.track_event(key, values: user_id) @@ -58,5 +60,9 @@ module Integrations **optional_arguments ) end + + def metrics_key_prefix + raise NotImplementedError + end end end diff --git a/app/models/integrations/slack.rb b/app/models/integrations/slack.rb index 89326b8174f..07d2d802915 100644 --- a/app/models/integrations/slack.rb +++ b/app/models/integrations/slack.rb @@ -20,5 +20,12 @@ module Integrations def webhook_help 'https://hooks.slack.com/services/…' end + + private + + override :metrics_key_prefix + def metrics_key_prefix + 'i_ecosystem_slack_service' + end end end |