Commit e247eac4 authored by Mark Chao's avatar Mark Chao

Merge branch '331181-rename-issue-tracker' into 'master'

Rename base class for issue tracker integrations

See merge request gitlab-org/gitlab!63019
parents 4ac72f3a 165b80bd
......@@ -29,7 +29,7 @@ module Mentionable
def self.external_pattern
strong_memoize(:external_pattern) do
issue_pattern = Integrations::IssueTracker.reference_pattern
issue_pattern = Integrations::BaseIssueTracker.reference_pattern
link_patterns = URI::DEFAULT_PARSER.make_regexp(%w(http https))
reference_pattern(link_patterns, issue_pattern)
end
......
......@@ -29,6 +29,15 @@ 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
serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize
attribute :type, Gitlab::Integrations::StiType.new
......@@ -59,7 +68,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?
......
# frozen_string_literal: true
module Integrations
class IssueTracker < Integration
class BaseIssueTracker < Integration
validate :one_issue_tracker, if: :activated?, on: :manual_change
# TODO: we can probably just delegate as part of
......@@ -128,6 +128,10 @@ module Integrations
false
end
def create_cross_reference_note(mentioned, noteable, author)
# implement inside child
end
private
def enabled_in_gitlab_config
......@@ -150,5 +154,3 @@ module Integrations
end
end
end
Integrations::IssueTracker.prepend_mod_with('Integrations::IssueTracker')
# frozen_string_literal: true
module Integrations
class Bugzilla < IssueTracker
class Bugzilla < BaseIssueTracker
include ActionView::Helpers::UrlHelper
validates :project_url, :issues_url, :new_issue_url, presence: true, public_url: true, if: :activated?
......
# frozen_string_literal: true
module Integrations
class CustomIssueTracker < IssueTracker
class CustomIssueTracker < BaseIssueTracker
include ActionView::Helpers::UrlHelper
validates :project_url, :issues_url, :new_issue_url, presence: true, public_url: true, if: :activated?
......
# frozen_string_literal: true
module Integrations
class Ewm < IssueTracker
class Ewm < BaseIssueTracker
include ActionView::Helpers::UrlHelper
validates :project_url, :issues_url, :new_issue_url, presence: true, public_url: true, if: :activated?
......
......@@ -2,7 +2,7 @@
# Accessible as Project#external_issue_tracker
module Integrations
class Jira < IssueTracker
class Jira < BaseIssueTracker
extend ::Gitlab::Utils::Override
include Gitlab::Routing
include ApplicationHelper
......@@ -205,6 +205,7 @@ module Integrations
log_usage(:close_issue, current_user)
end
override :create_cross_reference_note
def create_cross_reference_note(mentioned, noteable, author)
unless can_cross_reference?(noteable)
return s_("JiraService|Events for %{noteable_model_name} are disabled.") % { noteable_model_name: noteable.model_name.plural.humanize(capitalize: false) }
......
# frozen_string_literal: true
module Integrations
class OpenProject < IssueTracker
class OpenProject < BaseIssueTracker
validates :url, public_url: true, presence: true, if: :activated?
validates :api_url, public_url: true, allow_blank: true, if: :activated?
validates :token, presence: true, if: :activated?
......
# frozen_string_literal: true
module Integrations
class Redmine < IssueTracker
class Redmine < BaseIssueTracker
include ActionView::Helpers::UrlHelper
validates :project_url, :issues_url, :new_issue_url, presence: true, public_url: true, if: :activated?
......
# frozen_string_literal: true
module Integrations
class Youtrack < IssueTracker
class Youtrack < BaseIssueTracker
include ActionView::Helpers::UrlHelper
validates :project_url, :issues_url, presence: true, public_url: true, if: :activated?
......
# frozen_string_literal: true
module EE
module Integrations
module IssueTracker
def create_cross_reference_note
# implement inside child
end
end
end
end
......@@ -5,7 +5,7 @@ module Gitlab
class StiType < ActiveRecord::Type::String
NAMESPACED_INTEGRATIONS = Set.new(%w(
Asana Assembla Bamboo Bugzilla Buildkite Campfire Confluence CustomIssueTracker Datadog
Discord DroneCi EmailsOnPush Ewm ExternalWiki Flowdock HangoutsChat IssueTracker Irker
Discord DroneCi EmailsOnPush Ewm ExternalWiki Flowdock HangoutsChat Irker
Jenkins Jira Mattermost MattermostSlashCommands MicrosoftTeams MockCi Packagist PipelinesEmail Pivotaltracker
Pushover Redmine Slack SlackSlashCommands Teamcity UnifyCircuit Youtrack WebexTeams
)).freeze
......
......@@ -188,13 +188,13 @@ FactoryBot.define do
create_data { false }
after(:build) do
Integrations::IssueTracker.skip_callback(:validation, :before, :handle_properties)
Integrations::BaseIssueTracker.skip_callback(:validation, :before, :handle_properties)
end
to_create { |instance| instance.save!(validate: false) }
after(:create) do
Integrations::IssueTracker.set_callback(:validation, :before, :handle_properties)
Integrations::BaseIssueTracker.set_callback(:validation, :before, :handle_properties)
end
end
......
......@@ -18,6 +18,7 @@ RSpec.describe Integration do
describe 'validations' do
it { is_expected.to validate_presence_of(:type) }
it { is_expected.to validate_exclusion_of(:type).in_array(described_class::BASE_CLASSES) }
where(:project_id, :group_id, :template, :instance, :valid) do
1 | nil | false | false | true
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Integrations::IssueTracker do
RSpec.describe Integrations::BaseIssueTracker do
describe 'Validations' do
let(:project) { create :project }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment