diff options
Diffstat (limited to 'app/models/integration.rb')
-rw-r--r-- | app/models/integration.rb | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/app/models/integration.rb b/app/models/integration.rb index 13203cd4e95..238ecbbf209 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -6,7 +6,7 @@ class Integration < ApplicationRecord include Sortable include Importable include ProjectServicesLoggable - include DataFields + include Integrations::HasDataFields include FromUnion include EachBatch @@ -29,6 +29,27 @@ class Integration < ApplicationRecord mock_ci mock_monitoring ].freeze + # Base classes which aren't actual integrations. + BASE_CLASSES = %w[ + Integrations::BaseChatNotification + Integrations::BaseCi + Integrations::BaseIssueTracker + Integrations::BaseMonitoring + Integrations::BaseSlashCommands + ].freeze + + # used as part of the renaming effort (https://gitlab.com/groups/gitlab-org/-/epics/2504) + RENAMED_TO_INTEGRATION = %w[ + asana assembla + bamboo bugzilla buildkite + campfire confluence custom_issue_tracker + datadog discord drone_ci + ].to_set.freeze + + def self.renamed?(name) + RENAMED_TO_INTEGRATION.include?(name) + end + serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize attribute :type, Gitlab::Integrations::StiType.new @@ -59,7 +80,7 @@ class Integration < ApplicationRecord validates :project_id, presence: true, unless: -> { template? || instance_level? || group_level? } validates :group_id, presence: true, unless: -> { template? || instance_level? || project_level? } validates :project_id, :group_id, absence: true, if: -> { template? || instance_level? } - validates :type, presence: true + validates :type, presence: true, exclusion: BASE_CLASSES validates :type, uniqueness: { scope: :template }, if: :template? validates :type, uniqueness: { scope: :instance }, if: :instance_level? validates :type, uniqueness: { scope: :project_id }, if: :project_level? @@ -185,7 +206,7 @@ class Integration < ApplicationRecord def self.find_or_initialize_non_project_specific_integration(name, instance: false, group_id: nil) return unless name.in?(available_services_names(include_project_specific: false)) - service_name_to_model(name).find_or_initialize_by(instance: instance, group_id: group_id) + integration_name_to_model(name).find_or_initialize_by(instance: instance, group_id: group_id) end def self.find_or_initialize_all_non_project_specific(scope) @@ -194,7 +215,7 @@ class Integration < ApplicationRecord def self.build_nonexistent_services_for(scope) nonexistent_services_types_for(scope).map do |service_type| - service_type_to_model(service_type).new + integration_type_to_model(service_type).new end end private_class_method :build_nonexistent_services_for @@ -210,6 +231,7 @@ class Integration < ApplicationRecord # Returns a list of available service names. # Example: ["asana", ...] + # @deprecated def self.available_services_names(include_project_specific: true, include_dev: true) service_names = services_names service_names += project_specific_services_names if include_project_specific @@ -218,10 +240,14 @@ class Integration < ApplicationRecord service_names.sort_by(&:downcase) end - def self.services_names + def self.integration_names INTEGRATION_NAMES end + def self.services_names + integration_names + end + def self.dev_services_names return [] unless Rails.env.development? @@ -236,29 +262,29 @@ class Integration < ApplicationRecord # Example: ["AsanaService", ...] def self.available_services_types(include_project_specific: true, include_dev: true) available_services_names(include_project_specific: include_project_specific, include_dev: include_dev).map do |service_name| - service_name_to_type(service_name) + integration_name_to_type(service_name) end end # Returns the model for the given service name. # Example: "asana" => Integrations::Asana - def self.service_name_to_model(name) - type = service_name_to_type(name) - service_type_to_model(type) + def self.integration_name_to_model(name) + type = integration_name_to_type(name) + integration_type_to_model(type) end # Returns the STI type for the given service name. # Example: "asana" => "AsanaService" - def self.service_name_to_type(name) + def self.integration_name_to_type(name) "#{name}_service".camelize end # Returns the model for the given STI type. # Example: "AsanaService" => Integrations::Asana - def self.service_type_to_model(type) + def self.integration_type_to_model(type) Gitlab::Integrations::StiType.new.cast(type).constantize end - private_class_method :service_type_to_model + private_class_method :integration_type_to_model def self.build_from_integration(integration, project_id: nil, group_id: nil) new_integration = integration.dup @@ -480,10 +506,6 @@ class Integration < ApplicationRecord ProjectServiceWorker.perform_async(id, data) end - def external_wiki? - type == 'ExternalWikiService' && active? - end - # override if needed def supports_data_fields? false |