Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/integrations')
-rw-r--r--app/models/integrations/asana.rb6
-rw-r--r--app/models/integrations/bamboo.rb2
-rw-r--r--app/models/integrations/base_chat_notification.rb33
-rw-r--r--app/models/integrations/base_slack_notification.rb9
-rw-r--r--app/models/integrations/base_slash_commands.rb2
-rw-r--r--app/models/integrations/confluence.rb2
-rw-r--r--app/models/integrations/datadog.rb10
-rw-r--r--app/models/integrations/flowdock.rb43
-rw-r--r--app/models/integrations/jira.rb9
-rw-r--r--app/models/integrations/mattermost.rb2
-rw-r--r--app/models/integrations/packagist.rb8
-rw-r--r--app/models/integrations/pushover.rb2
-rw-r--r--app/models/integrations/slack.rb7
13 files changed, 65 insertions, 70 deletions
diff --git a/app/models/integrations/asana.rb b/app/models/integrations/asana.rb
index 2cfd71c9eb2..b8cfd718007 100644
--- a/app/models/integrations/asana.rb
+++ b/app/models/integrations/asana.rb
@@ -42,10 +42,8 @@ module Integrations
end
def client
- @_client ||= begin
- ::Asana::Client.new do |c|
- c.authentication :access_token, api_key
- end
+ @_client ||= ::Asana::Client.new do |c|
+ c.authentication :access_token, api_key
end
end
diff --git a/app/models/integrations/bamboo.rb b/app/models/integrations/bamboo.rb
index b4e97f0871e..fc5e6a88c2d 100644
--- a/app/models/integrations/bamboo.rb
+++ b/app/models/integrations/bamboo.rb
@@ -16,7 +16,7 @@ module Integrations
help: -> { s_('BambooService|Bamboo build plan key.') },
non_empty_password_title: -> { s_('BambooService|Enter new build key') },
non_empty_password_help: -> { s_('BambooService|Leave blank to use your current build key.') },
- placeholder: -> { s_('KEY') },
+ placeholder: -> { _('KEY') },
required: true
field :username,
diff --git a/app/models/integrations/base_chat_notification.rb b/app/models/integrations/base_chat_notification.rb
index 750aa60b185..f2a707c2214 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,19 +97,24 @@ 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)
- return unless supported_events.include?(data[:object_kind])
-
- return unless webhook.present?
-
object_kind = data[:object_kind]
+ return false unless should_execute?(object_kind)
+
data = custom_data(data)
- return unless notify_label?(data)
+ return false unless notify_label?(data)
# WebHook events often have an 'update' event that follows a 'open' or
# 'close' action. Ignore update events for now to prevent duplicate
@@ -168,8 +174,17 @@ module Integrations
self.public_send(field_name) # rubocop:disable GitlabSecurity/PublicSend
end
+ def requires_webhook?
+ true
+ end
+
private
+ def should_execute?(object_kind)
+ supported_events.include?(object_kind) &&
+ (!requires_webhook? || webhook.present?)
+ end
+
def log_usage(_, _)
# Implement in child class
end
diff --git a/app/models/integrations/base_slack_notification.rb b/app/models/integrations/base_slack_notification.rb
index cb785afdcfe..7a2a91aa0d2 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)
@@ -55,8 +57,13 @@ module Integrations
label: Integration::SNOWPLOW_EVENT_LABEL,
property: key,
user: User.find(user_id),
+ context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: key).to_context],
**optional_arguments
)
end
+
+ def metrics_key_prefix
+ raise NotImplementedError
+ end
end
end
diff --git a/app/models/integrations/base_slash_commands.rb b/app/models/integrations/base_slash_commands.rb
index 314f0a6ee5d..11ff7547325 100644
--- a/app/models/integrations/base_slash_commands.rb
+++ b/app/models/integrations/base_slash_commands.rb
@@ -60,7 +60,7 @@ module Integrations
# rubocop: disable CodeReuse/ServiceClass
def find_chat_user(params)
- ChatNames::FindUserService.new(self, params).execute
+ ChatNames::FindUserService.new(params[:team_id], params[:user_id]).execute
end
# rubocop: enable CodeReuse/ServiceClass
diff --git a/app/models/integrations/confluence.rb b/app/models/integrations/confluence.rb
index c1c43af99bf..31e9a171d1b 100644
--- a/app/models/integrations/confluence.rb
+++ b/app/models/integrations/confluence.rb
@@ -10,7 +10,7 @@ module Integrations
validate :validate_confluence_url_is_cloud, if: :activated?
field :confluence_url,
- title: -> { s_('Confluence Cloud Workspace URL') },
+ title: -> { _('Confluence Cloud Workspace URL') },
placeholder: 'https://example.atlassian.net/wiki',
required: true
diff --git a/app/models/integrations/datadog.rb b/app/models/integrations/datadog.rb
index 27bed5d3f76..80eecc14d0f 100644
--- a/app/models/integrations/datadog.rb
+++ b/app/models/integrations/datadog.rb
@@ -9,7 +9,7 @@ module Integrations
URL_API_KEYS_DOCS = "https://docs.#{DEFAULT_DOMAIN}/account_management/api-app-keys/"
SUPPORTED_EVENTS = %w[
- pipeline job archive_trace
+ pipeline build archive_trace
].freeze
TAG_KEY_VALUE_RE = %r{\A [\w-]+ : .*\S.* \z}x.freeze
@@ -48,8 +48,8 @@ module Integrations
field :archive_trace_events,
storage: :attribute,
type: 'checkbox',
- title: -> { s_('Logs') },
- checkbox_label: -> { s_('Enable logs collection') },
+ title: -> { _('Logs') },
+ checkbox_label: -> { _('Enable logs collection') },
help: -> { s_('When enabled, job logs are collected by Datadog and displayed along with pipeline execution traces.') }
field :datadog_service,
@@ -156,10 +156,10 @@ module Integrations
end
def execute(data)
+ return unless supported_events.include?(data[:object_kind])
+
object_kind = data[:object_kind]
object_kind = 'job' if object_kind == 'build'
- return unless supported_events.include?(object_kind)
-
data = hook_data(data, object_kind)
execute_web_hook!(data, "#{object_kind} hook")
end
diff --git a/app/models/integrations/flowdock.rb b/app/models/integrations/flowdock.rb
index 52efb29f2c1..d7625cfb3d2 100644
--- a/app/models/integrations/flowdock.rb
+++ b/app/models/integrations/flowdock.rb
@@ -1,28 +1,12 @@
# frozen_string_literal: true
+# This integration is scheduled for removal.
+# All records must be deleted before the class can be removed.
+# https://gitlab.com/gitlab-org/gitlab/-/issues/379197
module Integrations
class Flowdock < Integration
- validates :token, presence: true, if: :activated?
-
- field :token,
- type: 'password',
- help: -> { s_('FlowdockService|Enter your Flowdock token.') },
- non_empty_password_title: -> { s_('ProjectService|Enter new token') },
- non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') },
- placeholder: '1b609b52537...',
- required: true
-
- def title
- 'Flowdock'
- end
-
- def description
- s_('FlowdockService|Send event notifications from GitLab to Flowdock flows.')
- end
-
- def help
- docs_link = ActionController::Base.helpers.link_to _('Learn more.'), Rails.application.routes.url_helpers.help_page_url('api/services', anchor: 'flowdock'), target: '_blank', rel: 'noopener noreferrer'
- s_('FlowdockService|Send event notifications from GitLab to Flowdock flows. %{docs_link}').html_safe % { docs_link: docs_link.html_safe }
+ def readonly?
+ true
end
def self.to_param
@@ -30,22 +14,7 @@ module Integrations
end
def self.supported_events
- %w(push)
- end
-
- def execute(data)
- return unless supported_events.include?(data[:object_kind])
-
- ::Flowdock::Git.post(
- data[:ref],
- data[:before],
- data[:after],
- token: token,
- repo: project.repository,
- repo_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}",
- commit_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/-/commit/%s",
- diff_url: "#{Gitlab.config.gitlab.url}/#{project.full_path}/compare/%s...%s"
- )
+ %w[]
end
end
end
diff --git a/app/models/integrations/jira.rb b/app/models/integrations/jira.rb
index 65492bfd9c2..45302a0bd09 100644
--- a/app/models/integrations/jira.rb
+++ b/app/models/integrations/jira.rb
@@ -132,11 +132,9 @@ module Integrations
end
def client
- @client ||= begin
- JIRA::Client.new(options).tap do |client|
- # Replaces JIRA default http client with our implementation
- client.request_client = Gitlab::Jira::HttpClient.new(client.options)
- end
+ @client ||= JIRA::Client.new(options).tap do |client|
+ # Replaces JIRA default http client with our implementation
+ client.request_client = Gitlab::Jira::HttpClient.new(client.options)
end
end
@@ -406,6 +404,7 @@ module Integrations
label: Integration::SNOWPLOW_EVENT_LABEL,
property: key,
user: user,
+ context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: key).to_context],
**optional_arguments
)
end
diff --git a/app/models/integrations/mattermost.rb b/app/models/integrations/mattermost.rb
index dd1c98ee06b..e3c5c22ad3a 100644
--- a/app/models/integrations/mattermost.rb
+++ b/app/models/integrations/mattermost.rb
@@ -5,7 +5,7 @@ module Integrations
include SlackMattermostNotifier
def title
- s_('Mattermost notifications')
+ _('Mattermost notifications')
end
def description
diff --git a/app/models/integrations/packagist.rb b/app/models/integrations/packagist.rb
index 7148de66aee..3973b492b6d 100644
--- a/app/models/integrations/packagist.rb
+++ b/app/models/integrations/packagist.rb
@@ -5,15 +5,15 @@ module Integrations
include HasWebHook
field :username,
- title: -> { s_('Username') },
- help: -> { s_('Enter your Packagist username.') },
+ title: -> { _('Username') },
+ help: -> { _('Enter your Packagist username.') },
placeholder: '',
required: true
field :token,
type: 'password',
- title: -> { s_('Token') },
- help: -> { s_('Enter your Packagist token.') },
+ title: -> { _('Token') },
+ help: -> { _('Enter your Packagist token.') },
non_empty_password_title: -> { s_('ProjectService|Enter new token') },
non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') },
placeholder: '',
diff --git a/app/models/integrations/pushover.rb b/app/models/integrations/pushover.rb
index 791e27c5db7..6bb6b6d60f6 100644
--- a/app/models/integrations/pushover.rb
+++ b/app/models/integrations/pushover.rb
@@ -112,7 +112,7 @@ module Integrations
user: user_key,
device: device,
priority: priority,
- title: "#{project.full_name}",
+ title: project.full_name.to_s,
message: message,
url: data[:project][:web_url],
url_title: s_("PushoverService|See project %{project_full_name}") % { project_full_name: project.full_name }
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