Commit 18ecbebf authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'ld-make-GitlabSlackApplication-available-to-test' into 'master'

Make GitlabSlackApplication available to test env

See merge request gitlab-org/gitlab!79381
parents d3a5796e 0b6593ce
...@@ -5,8 +5,19 @@ module Types ...@@ -5,8 +5,19 @@ module Types
class ServiceTypeEnum < BaseEnum class ServiceTypeEnum < BaseEnum
graphql_name 'ServiceType' graphql_name 'ServiceType'
class << self
private
def type_description(type)
"#{type} type"
end
end
# This prepend must stay here because the dynamic block below depends on it.
prepend_mod # rubocop: disable Cop/InjectEnterpriseEditionModule
::Integration.available_integration_types(include_dev: false).each do |type| ::Integration.available_integration_types(include_dev: false).each do |type|
value type.underscore.upcase, value: type, description: "#{type} type" value type.underscore.upcase, value: type, description: type_description(type)
end end
end end
end end
......
...@@ -18018,6 +18018,7 @@ State of a Sentry error. ...@@ -18018,6 +18018,7 @@ State of a Sentry error.
| <a id="servicetypeexternal_wiki_service"></a>`EXTERNAL_WIKI_SERVICE` | ExternalWikiService type. | | <a id="servicetypeexternal_wiki_service"></a>`EXTERNAL_WIKI_SERVICE` | ExternalWikiService type. |
| <a id="servicetypeflowdock_service"></a>`FLOWDOCK_SERVICE` | FlowdockService type. | | <a id="servicetypeflowdock_service"></a>`FLOWDOCK_SERVICE` | FlowdockService type. |
| <a id="servicetypegithub_service"></a>`GITHUB_SERVICE` | GithubService type. | | <a id="servicetypegithub_service"></a>`GITHUB_SERVICE` | GithubService type. |
| <a id="servicetypegitlab_slack_application_service"></a>`GITLAB_SLACK_APPLICATION_SERVICE` | GitlabSlackApplicationService type (Gitlab.com only). |
| <a id="servicetypehangouts_chat_service"></a>`HANGOUTS_CHAT_SERVICE` | HangoutsChatService type. | | <a id="servicetypehangouts_chat_service"></a>`HANGOUTS_CHAT_SERVICE` | HangoutsChatService type. |
| <a id="servicetypeirker_service"></a>`IRKER_SERVICE` | IrkerService type. | | <a id="servicetypeirker_service"></a>`IRKER_SERVICE` | IrkerService type. |
| <a id="servicetypejenkins_service"></a>`JENKINS_SERVICE` | JenkinsService type. | | <a id="servicetypejenkins_service"></a>`JENKINS_SERVICE` | JenkinsService type. |
# frozen_string_literal: true
module EE
module Types
module Projects
module ServiceTypeEnum
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
private
override :type_description
def type_description(type)
description = super
description = [description, ' (Gitlab.com only)'].join if saas_only?(type)
description
end
def saas_only?(type)
name = ::Integration.integration_type_to_name(type)
::Integration.saas_only_integration_names.include?(name)
end
end
end
end
end
end
...@@ -8,12 +8,13 @@ module EE ...@@ -8,12 +8,13 @@ module EE
scope :vulnerability_hooks, -> { where(vulnerability_events: true, active: true) } scope :vulnerability_hooks, -> { where(vulnerability_events: true, active: true) }
end end
EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[ EE_PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[
github
gitlab_slack_application gitlab_slack_application
].freeze ].freeze
EE_PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[ EE_SAAS_ONLY_INTEGRATION_NAMES = %w[
github gitlab_slack_application
].freeze ].freeze
class_methods do class_methods do
...@@ -21,9 +22,31 @@ module EE ...@@ -21,9 +22,31 @@ module EE
override :project_specific_integration_names override :project_specific_integration_names
def project_specific_integration_names def project_specific_integration_names
integrations = super + EE_PROJECT_SPECIFIC_INTEGRATION_NAMES super + EE_PROJECT_SPECIFIC_INTEGRATION_NAMES
integrations += EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES if ::Gitlab.dev_env_or_com? end
integrations
def saas_only_integration_names
EE_SAAS_ONLY_INTEGRATION_NAMES
end
override :available_integration_names
def available_integration_names(*)
names = super
names -= saas_only_integration_names unless include_saas_only?
names
end
# Returns the integration name for the given type.
# Example: "AsanaService" => "asana".
def integration_type_to_name(type)
type.delete_suffix('Service').underscore
end
private
# Returns true if this instance can show SaaS-only integrations.
def include_saas_only?
::Gitlab.dev_or_test_env? || ::Gitlab.com?
end end
end end
end end
......
...@@ -27,12 +27,7 @@ RSpec.describe 'Every metric definition' do ...@@ -27,12 +27,7 @@ RSpec.describe 'Every metric definition' do
mock_ci mock_ci
mock_monitoring mock_monitoring
user_auth_by_provider user_auth_by_provider
groups_gitlab_slack_application_active
projects_gitlab_slack_application_active
instances_gitlab_slack_application_active
templates_gitlab_slack_application_active templates_gitlab_slack_application_active
groups_inheriting_gitlab_slack_application_active
projects_inheriting_gitlab_slack_application_active
p_ci_templates_5_min_production_app p_ci_templates_5_min_production_app
p_ci_templates_aws_cf_deploy_ec2 p_ci_templates_aws_cf_deploy_ec2
p_ci_templates_auto_devops_build p_ci_templates_auto_devops_build
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['ServiceType'] do
context 'GitLabSlackApplicationService' do
subject { described_class.values['GITLAB_SLACK_APPLICATION_SERVICE'] }
it 'appends a note to the description' do
expect(subject.description).to end_with(' (Gitlab.com only)')
end
end
end
...@@ -4,35 +4,41 @@ require 'spec_helper' ...@@ -4,35 +4,41 @@ require 'spec_helper'
RSpec.describe Integration do RSpec.describe Integration do
describe '.available_integration_names' do describe '.available_integration_names' do
it { expect(described_class.available_integration_names).to include('github') } let(:include_saas_only) { true }
end
describe '.project_specific_integration_names' do subject { described_class.available_integration_names }
subject { described_class.project_specific_integration_names }
before do before do
allow(::Gitlab).to receive(:com?).and_return(com) allow(described_class).to receive(:integration_names).and_return(%w(foo saas_only))
allow(described_class).to receive(:saas_only_integration_names).and_return(['saas_only'])
allow(described_class).to receive(:include_saas_only?).and_return(include_saas_only)
end end
context 'when not on gitlab.com' do it { is_expected.to include('foo', 'saas_only') }
let(:com) { false }
it { is_expected.to include(*described_class::EE_PROJECT_SPECIFIC_INTEGRATION_NAMES) } context 'when instance is not SaaS' do
it { is_expected.not_to include(*described_class::EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES) } let(:include_saas_only) { false }
context 'when on dev' do it { is_expected.to include('foo') }
before do it { is_expected.not_to include('saas_only') }
allow(Rails.env).to receive(:development?).and_return(true) end
end end
it { is_expected.to include(*described_class::EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES) } describe '.project_specific_integration_names' do
specify do
stub_const("EE::#{described_class.name}::EE_PROJECT_SPECIFIC_INTEGRATION_NAMES", ['ee_project_specific_name'])
expect(described_class.project_specific_integration_names)
.to include('ee_project_specific_name')
end end
end end
context 'when on gitlab.com' do describe '.saas_only_integration_names' do
let(:com) { true } specify do
stub_const("EE::#{described_class.name}::EE_SAAS_ONLY_INTEGRATION_NAMES", ['ee_sass_only_name'])
it { is_expected.to include(*described_class::EE_PROJECT_SPECIFIC_INTEGRATION_NAMES, *Integration::EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES) } expect(described_class.saas_only_integration_names)
.to eq(['ee_sass_only_name'])
end end
end end
...@@ -49,4 +55,10 @@ RSpec.describe Integration do ...@@ -49,4 +55,10 @@ RSpec.describe Integration do
expect(described_class.vulnerability_hooks.count).to eq 0 expect(described_class.vulnerability_hooks.count).to eq 0
end end
end end
describe '.integration_type_to_name' do
it 'transforms the type to a name' do
expect(described_class.integration_type_to_name('MyServiceService')).to eq('my_service')
end
end
end end
...@@ -566,6 +566,12 @@ RSpec.describe Integration do ...@@ -566,6 +566,12 @@ RSpec.describe Integration do
end end
end end
describe '.integration_name_to_type' do
it 'transforms the name to a type' do
expect(described_class.integration_name_to_type('asana')).to eq('AsanaService')
end
end
describe "{property}_changed?" do describe "{property}_changed?" do
let(:integration) do let(:integration) do
Integrations::Bamboo.create!( Integrations::Bamboo.create!(
...@@ -774,35 +780,33 @@ RSpec.describe Integration do ...@@ -774,35 +780,33 @@ RSpec.describe Integration do
end end
describe '.available_integration_names' do describe '.available_integration_names' do
it 'calls the right methods' do subject { described_class.available_integration_names }
expect(described_class).to receive(:integration_names).and_call_original
expect(described_class).to receive(:dev_integration_names).and_call_original
expect(described_class).to receive(:project_specific_integration_names).and_call_original
described_class.available_integration_names before do
allow(described_class).to receive(:integration_names).and_return(%w(foo))
allow(described_class).to receive(:project_specific_integration_names).and_return(['bar'])
allow(described_class).to receive(:dev_integration_names).and_return(['baz'])
end end
it 'does not call project_specific_integration_names with include_project_specific false' do it { is_expected.to include('foo', 'bar', 'baz') }
expect(described_class).to receive(:integration_names).and_call_original
expect(described_class).to receive(:dev_integration_names).and_call_original context 'when `include_project_specific` is false' do
expect(described_class).not_to receive(:project_specific_integration_names) subject { described_class.available_integration_names(include_project_specific: false) }
described_class.available_integration_names(include_project_specific: false) it { is_expected.to include('foo', 'baz') }
it { is_expected.not_to include('bar') }
end end
it 'does not call dev_integration_names with include_dev false' do context 'when `include_dev` is false' do
expect(described_class).to receive(:integration_names).and_call_original subject { described_class.available_integration_names(include_dev: false) }
expect(described_class).not_to receive(:dev_integration_names)
expect(described_class).to receive(:project_specific_integration_names).and_call_original
described_class.available_integration_names(include_dev: false) it { is_expected.to include('foo', 'bar') }
it { is_expected.not_to include('baz') }
end end
it { expect(described_class.available_integration_names).to include('jenkins') }
end end
describe '.project_specific_integration_names' do describe '.project_specific_integration_names' do
it do specify do
expect(described_class.project_specific_integration_names) expect(described_class.project_specific_integration_names)
.to include(*described_class::PROJECT_SPECIFIC_INTEGRATION_NAMES) .to include(*described_class::PROJECT_SPECIFIC_INTEGRATION_NAMES)
end end
......
...@@ -10,6 +10,14 @@ RSpec.describe API::Integrations do ...@@ -10,6 +10,14 @@ RSpec.describe API::Integrations do
create(:project, creator_id: user.id, namespace: user.namespace) create(:project, creator_id: user.id, namespace: user.namespace)
end end
# The API supports all integrations except the GitLab Slack Application
# integration; this integration must be installed via the UI.
def self.integration_names
names = Integration.available_integration_names
names.delete(Integrations::GitlabSlackApplication.to_param) if Gitlab.ee?
names
end
%w[integrations services].each do |endpoint| %w[integrations services].each do |endpoint|
describe "GET /projects/:id/#{endpoint}" do describe "GET /projects/:id/#{endpoint}" do
it 'returns authentication error when unauthenticated' do it 'returns authentication error when unauthenticated' do
...@@ -43,7 +51,7 @@ RSpec.describe API::Integrations do ...@@ -43,7 +51,7 @@ RSpec.describe API::Integrations do
end end
end end
Integration.available_integration_names.each do |integration| integration_names.each do |integration|
describe "PUT /projects/:id/#{endpoint}/#{integration.dasherize}" do describe "PUT /projects/:id/#{endpoint}/#{integration.dasherize}" do
include_context integration include_context integration
......
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