diff options
Diffstat (limited to 'app/models/integrations')
-rw-r--r-- | app/models/integrations/datadog.rb | 26 | ||||
-rw-r--r-- | app/models/integrations/discord.rb | 46 | ||||
-rw-r--r-- | app/models/integrations/hangouts_chat.rb | 25 | ||||
-rw-r--r-- | app/models/integrations/harbor.rb | 4 | ||||
-rw-r--r-- | app/models/integrations/shimo.rb | 2 |
5 files changed, 55 insertions, 48 deletions
diff --git a/app/models/integrations/datadog.rb b/app/models/integrations/datadog.rb index bb0fb6b9079..4479725a33b 100644 --- a/app/models/integrations/datadog.rb +++ b/app/models/integrations/datadog.rb @@ -10,7 +10,7 @@ module Integrations URL_API_KEYS_DOCS = "https://docs.#{DEFAULT_DOMAIN}/account_management/api-app-keys/" SUPPORTED_EVENTS = %w[ - pipeline job + pipeline job archive_trace ].freeze TAG_KEY_VALUE_RE = %r{\A [\w-]+ : .*\S.* \z}x.freeze @@ -38,14 +38,6 @@ module Integrations SUPPORTED_EVENTS end - def supported_events - events = super - - return events + ['archive_trace'] if Feature.enabled?(:datadog_integration_logs_collection, parent) - - events - end - def self.default_test_event 'pipeline' end @@ -77,7 +69,7 @@ module Integrations end def fields - f = [ + [ { type: 'text', name: 'datadog_site', @@ -110,21 +102,15 @@ module Integrations linkClose: '</a>'.html_safe }, required: true - } - ] - - if Feature.enabled?(:datadog_integration_logs_collection, parent) - f.append({ + }, + { type: 'checkbox', name: 'archive_trace_events', title: s_('Logs'), checkbox_label: s_('Enable logs collection'), help: s_('When enabled, job logs are collected by Datadog and displayed along with pipeline execution traces.'), required: false - }) - end - - f += [ + }, { type: 'text', name: 'datadog_service', @@ -161,8 +147,6 @@ module Integrations } } ] - - f end override :hook_url diff --git a/app/models/integrations/discord.rb b/app/models/integrations/discord.rb index ec8a12e4760..d0389b82410 100644 --- a/app/models/integrations/discord.rb +++ b/app/models/integrations/discord.rb @@ -6,6 +6,24 @@ module Integrations class Discord < BaseChatNotification ATTACHMENT_REGEX = /: (?<entry>.*?)\n - (?<name>.*)\n*/.freeze + undef :notify_only_broken_pipelines + + field :webhook, + section: SECTION_TYPE_CONNECTION, + placeholder: 'https://discordapp.com/api/webhooks/…', + help: 'URL to the webhook for the Discord channel.', + required: true + + field :notify_only_broken_pipelines, + type: 'checkbox', + section: SECTION_TYPE_CONFIGURATION + + field :branches_to_be_notified, + type: 'select', + section: SECTION_TYPE_CONFIGURATION, + title: -> { s_('Integrations|Branches for which notifications are to be sent') }, + choices: -> { branch_choices } + def title s_("DiscordService|Discord Notifications") end @@ -18,6 +36,10 @@ module Integrations "discord" end + def fields + self.class.fields + build_event_channels + end + def help docs_link = ActionController::Base.helpers.link_to _('How do I set up this service?'), Rails.application.routes.url_helpers.help_page_url('user/project/integrations/discord_notifications'), target: '_blank', rel: 'noopener noreferrer' s_('Send notifications about project events to a Discord channel. %{docs_link}').html_safe % { docs_link: docs_link.html_safe } @@ -31,30 +53,6 @@ module Integrations %w[push issue confidential_issue merge_request note confidential_note tag_push pipeline wiki_page] end - def default_fields - [ - { - type: 'text', - section: SECTION_TYPE_CONNECTION, - name: 'webhook', - placeholder: 'https://discordapp.com/api/webhooks/…', - help: 'URL to the webhook for the Discord channel.' - }, - { - type: 'checkbox', - section: SECTION_TYPE_CONFIGURATION, - name: 'notify_only_broken_pipelines' - }, - { - type: 'select', - section: SECTION_TYPE_CONFIGURATION, - name: 'branches_to_be_notified', - title: s_('Integrations|Branches for which notifications are to be sent'), - choices: self.class.branch_choices - } - ] - end - def sections [ { diff --git a/app/models/integrations/hangouts_chat.rb b/app/models/integrations/hangouts_chat.rb index df112ad6ca8..6e7f31aa030 100644 --- a/app/models/integrations/hangouts_chat.rb +++ b/app/models/integrations/hangouts_chat.rb @@ -47,8 +47,31 @@ module Integrations private def notify(message, opts) + url = webhook.dup + + key = parse_thread_key(message) + url = Gitlab::Utils.add_url_parameters(url, { threadKey: key }) if key + simple_text = parse_simple_text_message(message) - ::HangoutsChat::Sender.new(webhook).simple(simple_text) + ::HangoutsChat::Sender.new(url).simple(simple_text) + end + + # Returns an appropriate key for threading messages in google chat + def parse_thread_key(message) + case message + when Integrations::ChatMessage::NoteMessage + message.target + when Integrations::ChatMessage::IssueMessage + "issue #{Issue.reference_prefix}#{message.issue_iid}" + when Integrations::ChatMessage::MergeMessage + "merge request #{MergeRequest.reference_prefix}#{message.merge_request_iid}" + when Integrations::ChatMessage::PushMessage + "push #{message.project_name}_#{message.ref}" + when Integrations::ChatMessage::PipelineMessage + "pipeline #{message.pipeline_id}" + when Integrations::ChatMessage::WikiPageMessage + "wiki_page #{message.wiki_page_url}" + end end def parse_simple_text_message(message) diff --git a/app/models/integrations/harbor.rb b/app/models/integrations/harbor.rb index 03913a71d47..58eabcfd378 100644 --- a/app/models/integrations/harbor.rb +++ b/app/models/integrations/harbor.rb @@ -24,6 +24,10 @@ module Integrations s_("HarborIntegration|After the Harbor integration is activated, global variables '$HARBOR_USERNAME', '$HARBOR_HOST', '$HARBOR_OCI', '$HARBOR_PASSWORD', '$HARBOR_URL' and '$HARBOR_PROJECT' will be created for CI/CD use.") end + def hostname + Gitlab::Utils.parse_url(url).hostname + end + class << self def to_param name.demodulize.downcase diff --git a/app/models/integrations/shimo.rb b/app/models/integrations/shimo.rb index 8bc296e0320..f5b6595fff2 100644 --- a/app/models/integrations/shimo.rb +++ b/app/models/integrations/shimo.rb @@ -9,8 +9,6 @@ module Integrations required: true def render? - return false unless Feature.enabled?(:shimo_integration, project) - valid? && activated? end |