Commit 0b6593ce authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Fabio Pitino

Make GitlabSlackApplication available to test env

fdf31bb2 made the Integrations::GitlabSlackApplication integration
available to development in addition to GitLab.com.

When a user now generates the GraphQL docs with
`rake gitlab:graphql:compile_docs` locally, the new integration appears
as a value in the enum `ServiceType`
https://gitlab.com/gitlab-org/gitlab/-/blob/b8c957ad50e4ffafe66b6869fc42a936e8aab5ac/app/graphql/types/projects/service_type_enum.rb
however because the integration is not available to the test environment
the `graphql-verify` job will fail because
`rake gitlab:graphql:validate` will check the commited changes against
its own version of the GraphQL docs, where the integration value will be
absent from the enum.

This change makes the integration available to test so the integrations
are consistent between a developer's local environment and the
`graphql-verify` job.

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79304/diffs#note_822981597
parent 632a455d
......@@ -5,8 +5,19 @@ module Types
class ServiceTypeEnum < BaseEnum
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|
value type.underscore.upcase, value: type, description: "#{type} type"
value type.underscore.upcase, value: type, description: type_description(type)
end
end
end
......
......@@ -18017,6 +18017,7 @@ State of a Sentry error.
| <a id="servicetypeexternal_wiki_service"></a>`EXTERNAL_WIKI_SERVICE` | ExternalWikiService type. |
| <a id="servicetypeflowdock_service"></a>`FLOWDOCK_SERVICE` | FlowdockService 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="servicetypeirker_service"></a>`IRKER_SERVICE` | IrkerService 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
scope :vulnerability_hooks, -> { where(vulnerability_events: true, active: true) }
end
EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[
EE_PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[
github
gitlab_slack_application
].freeze
EE_PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[
github
EE_SAAS_ONLY_INTEGRATION_NAMES = %w[
gitlab_slack_application
].freeze
class_methods do
......@@ -21,9 +22,31 @@ module EE
override :project_specific_integration_names
def project_specific_integration_names
integrations = super + EE_PROJECT_SPECIFIC_INTEGRATION_NAMES
integrations += EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES if ::Gitlab.dev_env_or_com?
integrations
super + EE_PROJECT_SPECIFIC_INTEGRATION_NAMES
end
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
......
......@@ -27,12 +27,7 @@ RSpec.describe 'Every metric definition' do
mock_ci
mock_monitoring
user_auth_by_provider
groups_gitlab_slack_application_active
projects_gitlab_slack_application_active
instances_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_aws_cf_deploy_ec2
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'
RSpec.describe Integration do
describe '.available_integration_names' do
it { expect(described_class.available_integration_names).to include('github') }
end
let(:include_saas_only) { true }
describe '.project_specific_integration_names' do
subject { described_class.project_specific_integration_names }
subject { described_class.available_integration_names }
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
context 'when not on gitlab.com' do
let(:com) { false }
it { is_expected.to include('foo', 'saas_only') }
context 'when instance is not SaaS' do
let(:include_saas_only) { false }
it { is_expected.to include(*described_class::EE_PROJECT_SPECIFIC_INTEGRATION_NAMES) }
it { is_expected.not_to include(*described_class::EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES) }
it { is_expected.to include('foo') }
it { is_expected.not_to include('saas_only') }
end
end
context 'when on dev' do
before do
allow(Rails.env).to receive(:development?).and_return(true)
end
describe '.project_specific_integration_names' do
specify do
stub_const("EE::#{described_class.name}::EE_PROJECT_SPECIFIC_INTEGRATION_NAMES", ['ee_project_specific_name'])
it { is_expected.to include(*described_class::EE_COM_PROJECT_SPECIFIC_INTEGRATION_NAMES) }
end
expect(described_class.project_specific_integration_names)
.to include('ee_project_specific_name')
end
end
context 'when on gitlab.com' do
let(:com) { true }
describe '.saas_only_integration_names' do
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
......@@ -49,4 +55,10 @@ RSpec.describe Integration do
expect(described_class.vulnerability_hooks.count).to eq 0
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
......@@ -566,6 +566,12 @@ RSpec.describe Integration do
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
let(:integration) do
Integrations::Bamboo.create!(
......@@ -774,35 +780,33 @@ RSpec.describe Integration do
end
describe '.available_integration_names' do
it 'calls the right methods' do
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
subject { described_class.available_integration_names }
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
it 'does not call project_specific_integration_names with include_project_specific false' do
expect(described_class).to receive(:integration_names).and_call_original
expect(described_class).to receive(:dev_integration_names).and_call_original
expect(described_class).not_to receive(:project_specific_integration_names)
it { is_expected.to include('foo', 'bar', 'baz') }
described_class.available_integration_names(include_project_specific: false)
context 'when `include_project_specific` is false' do
subject { described_class.available_integration_names(include_project_specific: false) }
it { is_expected.to include('foo', 'baz') }
it { is_expected.not_to include('bar') }
end
it 'does not call dev_integration_names with include_dev false' do
expect(described_class).to receive(:integration_names).and_call_original
expect(described_class).not_to receive(:dev_integration_names)
expect(described_class).to receive(:project_specific_integration_names).and_call_original
context 'when `include_dev` is false' do
subject { described_class.available_integration_names(include_dev: false) }
described_class.available_integration_names(include_dev: false)
it { is_expected.to include('foo', 'bar') }
it { is_expected.not_to include('baz') }
end
it { expect(described_class.available_integration_names).to include('jenkins') }
end
describe '.project_specific_integration_names' do
it do
specify do
expect(described_class.project_specific_integration_names)
.to include(*described_class::PROJECT_SPECIFIC_INTEGRATION_NAMES)
end
......
......@@ -10,6 +10,14 @@ RSpec.describe API::Integrations do
create(:project, creator_id: user.id, namespace: user.namespace)
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|
describe "GET /projects/:id/#{endpoint}" do
it 'returns authentication error when unauthenticated' do
......@@ -43,7 +51,7 @@ RSpec.describe API::Integrations do
end
end
Integration.available_integration_names.each do |integration|
integration_names.each do |integration|
describe "PUT /projects/:id/#{endpoint}/#{integration.dasherize}" do
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