diff options
Diffstat (limited to 'app/models/integrations')
-rw-r--r-- | app/models/integrations/bamboo.rb | 20 | ||||
-rw-r--r-- | app/models/integrations/base_chat_notification.rb | 2 | ||||
-rw-r--r-- | app/models/integrations/buildkite.rb | 12 | ||||
-rw-r--r-- | app/models/integrations/drone_ci.rb | 8 | ||||
-rw-r--r-- | app/models/integrations/field.rb | 7 | ||||
-rw-r--r-- | app/models/integrations/harbor.rb | 2 | ||||
-rw-r--r-- | app/models/integrations/irker.rb | 55 | ||||
-rw-r--r-- | app/models/integrations/jenkins.rb | 14 | ||||
-rw-r--r-- | app/models/integrations/jira.rb | 5 | ||||
-rw-r--r-- | app/models/integrations/microsoft_teams.rb | 30 | ||||
-rw-r--r-- | app/models/integrations/mock_ci.rb | 2 | ||||
-rw-r--r-- | app/models/integrations/prometheus.rb | 2 | ||||
-rw-r--r-- | app/models/integrations/teamcity.rb | 10 | ||||
-rw-r--r-- | app/models/integrations/zentao_tracker_data.rb | 13 |
14 files changed, 118 insertions, 64 deletions
diff --git a/app/models/integrations/bamboo.rb b/app/models/integrations/bamboo.rb index 4e144a688f6..4e30c1ccc69 100644 --- a/app/models/integrations/bamboo.rb +++ b/app/models/integrations/bamboo.rb @@ -6,25 +6,25 @@ module Integrations prepend EnableSslVerification field :bamboo_url, - title: s_('BambooService|Bamboo URL'), - placeholder: s_('https://bamboo.example.com'), - help: s_('BambooService|Bamboo service root URL.'), + title: -> { s_('BambooService|Bamboo URL') }, + placeholder: -> { s_('https://bamboo.example.com') }, + help: -> { s_('BambooService|Bamboo service root URL.') }, required: true field :build_key, - 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'), + 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') }, required: true field :username, - help: s_('BambooService|The user with API access to the Bamboo server.') + help: -> { s_('BambooService|The user with API access to the Bamboo server.') } field :password, type: 'password', - non_empty_password_title: s_('ProjectService|Enter new password'), - non_empty_password_help: s_('ProjectService|Leave blank to use your current password') + non_empty_password_title: -> { s_('ProjectService|Enter new password') }, + non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current password') } validates :bamboo_url, presence: true, public_url: true, if: :activated? validates :build_key, presence: true, if: :activated? diff --git a/app/models/integrations/base_chat_notification.rb b/app/models/integrations/base_chat_notification.rb index 9bf208abcf7..33d4eecbf49 100644 --- a/app/models/integrations/base_chat_notification.rb +++ b/app/models/integrations/base_chat_notification.rb @@ -249,7 +249,7 @@ module Integrations ref = data[:ref] || data.dig(:object_attributes, :ref) return true if ref.blank? # No need to check protected branches when there is no ref - return true if Gitlab::Git.tag_ref?(ref) # Skip protected branch check because it doesn't support tags + return true if Gitlab::Git.tag_ref?(project.repository.expand_ref(ref) || ref) # Skip protected branch check because it doesn't support tags notify_for_branch?(data) end diff --git a/app/models/integrations/buildkite.rb b/app/models/integrations/buildkite.rb index d1e54ce86ee..def646c6d49 100644 --- a/app/models/integrations/buildkite.rb +++ b/app/models/integrations/buildkite.rb @@ -11,16 +11,18 @@ module Integrations ENDPOINT = "https://buildkite.com" field :project_url, - title: _('Pipeline URL'), + title: -> { _('Pipeline URL') }, placeholder: "#{ENDPOINT}/example-org/test-pipeline", required: true field :token, type: 'password', - title: _('Token'), - help: s_('ProjectService|The token you get after you create a Buildkite pipeline with a GitLab repository.'), - non_empty_password_title: s_('ProjectService|Enter new token'), - non_empty_password_help: s_('ProjectService|Leave blank to use your current token.'), + title: -> { _('Token') }, + help: -> do + s_('ProjectService|The token you get after you create a Buildkite pipeline with a GitLab repository.') + end, + non_empty_password_title: -> { s_('ProjectService|Enter new token') }, + non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') }, required: true validates :project_url, presence: true, public_url: true, if: :activated? diff --git a/app/models/integrations/drone_ci.rb b/app/models/integrations/drone_ci.rb index 0c65ed8cd5f..35524503dea 100644 --- a/app/models/integrations/drone_ci.rb +++ b/app/models/integrations/drone_ci.rb @@ -11,15 +11,15 @@ module Integrations DRONE_SAAS_HOSTNAME = 'cloud.drone.io' field :drone_url, - title: s_('ProjectService|Drone server URL'), + title: -> { s_('ProjectService|Drone server URL') }, placeholder: 'http://drone.example.com', required: true field :token, type: 'password', - help: s_('ProjectService|Token for the Drone project.'), - non_empty_password_title: s_('ProjectService|Enter new token'), - non_empty_password_help: s_('ProjectService|Leave blank to use your current token.'), + help: -> { s_('ProjectService|Token for the Drone project.') }, + non_empty_password_title: -> { s_('ProjectService|Enter new token') }, + non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current token.') }, required: true validates :drone_url, presence: true, public_url: true, if: :activated? diff --git a/app/models/integrations/field.rb b/app/models/integrations/field.rb index ca7833c1a56..cbda418755b 100644 --- a/app/models/integrations/field.rb +++ b/app/models/integrations/field.rb @@ -13,10 +13,11 @@ module Integrations exposes_secrets ].freeze - attr_reader :name + attr_reader :name, :integration_class - def initialize(name:, type: 'text', api_only: false, **attributes) + def initialize(name:, integration_class:, type: 'text', api_only: false, **attributes) @name = name.to_s.freeze + @integration_class = integration_class attributes[:type] = SECRET_NAME.match?(@name) ? 'password' : type attributes[:api_only] = api_only @@ -27,7 +28,7 @@ module Integrations return name if key == :name value = @attributes[key] - return value.call if value.respond_to?(:call) + return integration_class.class_exec(&value) if value.respond_to?(:call) value end diff --git a/app/models/integrations/harbor.rb b/app/models/integrations/harbor.rb index 6b561575f30..44813795fc0 100644 --- a/app/models/integrations/harbor.rb +++ b/app/models/integrations/harbor.rb @@ -81,7 +81,7 @@ module Integrations [ { key: 'HARBOR_URL', value: url }, { key: 'HARBOR_PROJECT', value: project_name }, - { key: 'HARBOR_USERNAME', value: username }, + { key: 'HARBOR_USERNAME', value: username.gsub(/^robot\$/, 'robot$$') }, { key: 'HARBOR_PASSWORD', value: password, public: false, masked: true } ] end diff --git a/app/models/integrations/irker.rb b/app/models/integrations/irker.rb index 116d1fb233d..780f4bef0c9 100644 --- a/app/models/integrations/irker.rb +++ b/app/models/integrations/irker.rb @@ -24,14 +24,23 @@ module Integrations end def self.supported_events - %w(push) + %w[push] end def execute(data) return unless supported_events.include?(data[:object_kind]) - IrkerWorker.perform_async(project_id, channels, - colorize_messages, data, settings) + if Feature.enabled?(:rename_integrations_workers) + Integrations::IrkerWorker.perform_async( + project_id, channels, + colorize_messages, data, settings + ) + else + ::IrkerWorker.perform_async( + project_id, channels, + colorize_messages, data, settings + ) + end end def settings @@ -42,7 +51,15 @@ module Integrations end def fields - recipients_docs_link = ActionController::Base.helpers.link_to s_('IrkerService|How to enter channels or users?'), Rails.application.routes.url_helpers.help_page_url('user/project/integrations/irker', anchor: 'enter-irker-recipients'), target: '_blank', rel: 'noopener noreferrer' + recipients_docs_link = ActionController::Base.helpers.link_to( + s_('IrkerService|How to enter channels or users?'), + Rails.application.routes.url_helpers.help_page_url( + 'user/project/integrations/irker', + anchor: 'enter-irker-recipients' + ), + target: '_blank', rel: 'noopener noreferrer' + ) + [ { type: 'text', name: 'server_host', placeholder: 'localhost', title: s_('IrkerService|Server host (optional)'), help: s_('IrkerService|irker daemon hostname (defaults to localhost).') }, @@ -53,14 +70,29 @@ module Integrations placeholder: 'irc://irc.network.net:6697/' }, { type: 'textarea', name: 'recipients', title: s_('IrkerService|Recipients'), placeholder: 'irc[s]://irc.network.net[:port]/#channel', required: true, - help: s_('IrkerService|Channels and users separated by whitespaces. %{recipients_docs_link}').html_safe % { recipients_docs_link: recipients_docs_link.html_safe } }, + help: format( + s_('IrkerService|Channels and users separated by whitespaces. %{recipients_docs_link}').html_safe, + recipients_docs_link: recipients_docs_link.html_safe + ) }, { type: 'checkbox', name: 'colorize_messages', title: _('Colorize messages') } ] end def help - docs_link = ActionController::Base.helpers.link_to _('Learn more.'), Rails.application.routes.url_helpers.help_page_url('user/project/integrations/irker', anchor: 'set-up-an-irker-daemon'), target: '_blank', rel: 'noopener noreferrer' - s_('IrkerService|Send update messages to an irker server. Before you can use this, you need to set up the irker daemon. %{docs_link}').html_safe % { docs_link: docs_link.html_safe } + docs_link = ActionController::Base.helpers.link_to( + _('Learn more.'), + Rails.application.routes.url_helpers.help_page_url( + 'user/project/integrations/irker', + anchor: 'set-up-an-irker-daemon' + ), + target: '_blank', + rel: 'noopener noreferrer' + ) + + format(s_( + 'IrkerService|Send update messages to an irker server. ' \ + 'Before you can use this, you need to set up the irker daemon. %{docs_link}' + ).html_safe, docs_link: docs_link.html_safe) end private @@ -104,12 +136,11 @@ module Integrations end def consider_uri(uri) - return if uri.scheme.nil? - + return unless uri.is_a?(URI) && uri.scheme.present? # Authorize both irc://domain.com/#chan and irc://domain.com/chan - if uri.is_a?(URI) && uri.scheme[/^ircs?\z/] && !uri.path.nil? - uri.to_s - end + return unless uri.scheme =~ /\Aircs?\z/ && !uri.path.nil? + + uri.to_s end end end diff --git a/app/models/integrations/jenkins.rb b/app/models/integrations/jenkins.rb index a1abbce72bc..ab39d1f7b77 100644 --- a/app/models/integrations/jenkins.rb +++ b/app/models/integrations/jenkins.rb @@ -8,24 +8,24 @@ module Integrations extend Gitlab::Utils::Override field :jenkins_url, - title: s_('ProjectService|Jenkins server URL'), + title: -> { s_('ProjectService|Jenkins server URL') }, required: true, placeholder: 'http://jenkins.example.com', - help: s_('The URL of the Jenkins server.') + help: -> { s_('The URL of the Jenkins server.') } field :project_name, required: true, placeholder: 'my_project_name', - help: s_('The name of the Jenkins project. Copy the name from the end of the URL to the project.') + help: -> { s_('The name of the Jenkins project. Copy the name from the end of the URL to the project.') } field :username, - help: s_('The username for the Jenkins server.') + help: -> { s_('The username for the Jenkins server.') } field :password, type: 'password', - help: s_('The password for the Jenkins server.'), - non_empty_password_title: s_('ProjectService|Enter new password.'), - non_empty_password_help: s_('ProjectService|Leave blank to use your current password.') + help: -> { s_('The password for the Jenkins server.') }, + non_empty_password_title: -> { s_('ProjectService|Enter new password.') }, + non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current password.') } before_validation :reset_password diff --git a/app/models/integrations/jira.rb b/app/models/integrations/jira.rb index 992bd01bf5f..125f52104d4 100644 --- a/app/models/integrations/jira.rb +++ b/app/models/integrations/jira.rb @@ -24,7 +24,10 @@ module Integrations validates :password, presence: true, if: :activated? validates :jira_issue_transition_id, - format: { with: Gitlab::Regex.jira_transition_id_regex, message: s_("JiraService|IDs must be a list of numbers that can be split with , or ;") }, + format: { + with: Gitlab::Regex.jira_transition_id_regex, + message: ->(*_) { s_("JiraService|IDs must be a list of numbers that can be split with , or ;") } + }, allow_blank: true # Jira Cloud version is deprecating authentication via username and password. diff --git a/app/models/integrations/microsoft_teams.rb b/app/models/integrations/microsoft_teams.rb index 71cd4ddaf82..625ee0bc522 100644 --- a/app/models/integrations/microsoft_teams.rb +++ b/app/models/integrations/microsoft_teams.rb @@ -35,10 +35,16 @@ module Integrations def default_fields [ - { type: 'text', name: 'webhook', placeholder: "#{webhook_placeholder}" }, - { type: 'checkbox', name: 'notify_only_broken_pipelines', help: 'If selected, successful pipelines do not trigger a notification event.' }, + { type: 'text', section: SECTION_TYPE_CONNECTION, name: 'webhook', required: true, placeholder: "#{webhook_placeholder}" }, + { + type: 'checkbox', + section: SECTION_TYPE_CONFIGURATION, + name: 'notify_only_broken_pipelines', + help: 'If selected, successful pipelines do not trigger a notification event.' + }, { type: 'select', + section: SECTION_TYPE_CONFIGURATION, name: 'branches_to_be_notified', title: s_('Integrations|Branches for which notifications are to be sent'), choices: branch_choices @@ -46,6 +52,26 @@ module Integrations ] end + def sections + [ + { + type: SECTION_TYPE_CONNECTION, + title: s_('Integrations|Connection details'), + description: help + }, + { + type: SECTION_TYPE_TRIGGER, + title: s_('Integrations|Trigger'), + description: s_('Integrations|An event will be triggered when one of the following items happen.') + }, + { + type: SECTION_TYPE_CONFIGURATION, + title: s_('Integrations|Notification settings'), + description: s_('Integrations|Configure the scope of notifications.') + } + ] + end + private def notify(message, opts) diff --git a/app/models/integrations/mock_ci.rb b/app/models/integrations/mock_ci.rb index cd2928136ef..0b3a9bc5405 100644 --- a/app/models/integrations/mock_ci.rb +++ b/app/models/integrations/mock_ci.rb @@ -8,7 +8,7 @@ module Integrations ALLOWED_STATES = %w[failed canceled running pending success success-with-warnings skipped not_found].freeze field :mock_service_url, - title: s_('ProjectService|Mock service URL'), + title: -> { s_('ProjectService|Mock service URL') }, placeholder: 'http://localhost:4004', required: true diff --git a/app/models/integrations/prometheus.rb b/app/models/integrations/prometheus.rb index 427034edb79..36060565317 100644 --- a/app/models/integrations/prometheus.rb +++ b/app/models/integrations/prometheus.rb @@ -84,6 +84,8 @@ module Integrations # Check we can connect to the Prometheus API def test(*args) + return { success: false, result: 'Prometheus configuration error' } unless prometheus_client + prometheus_client.ping { success: true, result: 'Checked API endpoint' } rescue Gitlab::PrometheusClient::Error => err diff --git a/app/models/integrations/teamcity.rb b/app/models/integrations/teamcity.rb index 1205173e40b..a23aa5f783d 100644 --- a/app/models/integrations/teamcity.rb +++ b/app/models/integrations/teamcity.rb @@ -9,21 +9,21 @@ module Integrations TEAMCITY_SAAS_HOSTNAME = /\A[^\.]+\.teamcity\.com\z/i.freeze field :teamcity_url, - title: s_('ProjectService|TeamCity server URL'), + title: -> { s_('ProjectService|TeamCity server URL') }, placeholder: 'https://teamcity.example.com', required: true field :build_type, - help: s_('ProjectService|The build configuration ID of the TeamCity project.'), + help: -> { s_('ProjectService|The build configuration ID of the TeamCity project.') }, required: true field :username, - help: s_('ProjectService|Must have permission to trigger a manual build in TeamCity.') + help: -> { s_('ProjectService|Must have permission to trigger a manual build in TeamCity.') } field :password, type: 'password', - non_empty_password_title: s_('ProjectService|Enter new password'), - non_empty_password_help: s_('ProjectService|Leave blank to use your current password') + non_empty_password_title: -> { s_('ProjectService|Enter new password') }, + non_empty_password_help: -> { s_('ProjectService|Leave blank to use your current password') } validates :teamcity_url, presence: true, public_url: true, if: :activated? validates :build_type, presence: true, if: :activated? diff --git a/app/models/integrations/zentao_tracker_data.rb b/app/models/integrations/zentao_tracker_data.rb index 468e4e5d7d7..e9d63abd66b 100644 --- a/app/models/integrations/zentao_tracker_data.rb +++ b/app/models/integrations/zentao_tracker_data.rb @@ -2,18 +2,7 @@ module Integrations class ZentaoTrackerData < ApplicationRecord - belongs_to :integration, inverse_of: :zentao_tracker_data, foreign_key: :integration_id - delegate :activated?, to: :integration - validates :integration, presence: true - - scope :encryption_options, -> do - { - key: Settings.attr_encrypted_db_key_base_32, - encode: true, - mode: :per_attribute_iv, - algorithm: 'aes-256-gcm' - } - end + include BaseDataFields attr_encrypted :url, encryption_options attr_encrypted :api_url, encryption_options |