Commit 74736916 authored by Markus Koller's avatar Markus Koller

Merge branch '330300-rename-methods-called-service-to-integration' into 'master'

Rename batch of integration methods [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!62224
parents 5c6d40a1 858b0da2
......@@ -12,19 +12,19 @@ module Resolvers
argument :active,
GraphQL::BOOLEAN_TYPE,
required: false,
description: 'Indicates if the service is active.'
description: 'Indicates if the integration is active.'
argument :type,
Types::Projects::ServiceTypeEnum,
required: false,
description: 'Class name of the service.'
description: 'Type of integration.'
alias_method :project, :object
def resolve(active: nil, type: nil)
servs = project.integrations
servs = servs.by_active_flag(active) unless active.nil?
servs = servs.by_type(type) unless type.blank?
servs
items = project.integrations
items = items.by_active_flag(active) unless active.nil?
items = items.by_type(type) unless type.blank?
items
end
end
end
......
......@@ -5,8 +5,8 @@ module Types
class ServiceTypeEnum < BaseEnum
graphql_name 'ServiceType'
::Integration.available_services_types(include_dev: false).each do |service_type|
value service_type.underscore.upcase, value: service_type, description: "#{service_type} type"
::Integration.available_services_types(include_dev: false).each do |type|
value type.underscore.upcase, value: type, description: "#{type} type"
end
end
end
......
......@@ -38,6 +38,13 @@ class Integration < ApplicationRecord
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
].to_set.freeze
serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize
attribute :type, Gitlab::Integrations::StiType.new
......@@ -194,7 +201,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)
......@@ -203,7 +210,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
......@@ -219,6 +226,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
......@@ -227,10 +235,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?
......@@ -245,29 +257,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
......
......@@ -155,14 +155,14 @@ class Project < ApplicationRecord
has_many :boards
# Project integrations
has_one :asana_service, class_name: 'Integrations::Asana'
has_one :assembla_service, class_name: 'Integrations::Assembla'
has_one :bamboo_service, class_name: 'Integrations::Bamboo'
has_one :bugzilla_service, class_name: 'Integrations::Bugzilla'
has_one :buildkite_service, class_name: 'Integrations::Buildkite'
has_one :campfire_service, class_name: 'Integrations::Campfire'
has_one :confluence_service, class_name: 'Integrations::Confluence'
has_one :custom_issue_tracker_service, class_name: 'Integrations::CustomIssueTracker'
has_one :asana_integration, class_name: 'Integrations::Asana'
has_one :assembla_integration, class_name: 'Integrations::Assembla'
has_one :bamboo_integration, class_name: 'Integrations::Bamboo'
has_one :bugzilla_integration, class_name: 'Integrations::Bugzilla'
has_one :buildkite_integration, class_name: 'Integrations::Buildkite'
has_one :campfire_integration, class_name: 'Integrations::Campfire'
has_one :confluence_integration, class_name: 'Integrations::Confluence'
has_one :custom_issue_tracker_integration, class_name: 'Integrations::CustomIssueTracker'
has_one :datadog_service, class_name: 'Integrations::Datadog'
has_one :discord_service, class_name: 'Integrations::Discord'
has_one :drone_ci_service, class_name: 'Integrations::DroneCi'
......@@ -2645,7 +2645,7 @@ class Project < ApplicationRecord
end
def build_service(name)
Integration.service_name_to_model(name).new(project_id: id)
Integration.integration_name_to_model(name).new(project_id: id)
end
def services_templates
......
......@@ -6,9 +6,9 @@
= s_('WikiEmpty|Confluence is enabled')
%p
- wiki_confluence_epic_link_url = 'https://gitlab.com/groups/gitlab-org/-/epics/3629'
- wiki_confluence_epic_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: wiki_confluence_epic_link_url }
= s_("WikiEmpty|You've enabled the Confluence Workspace integration. Your wiki will be viewable directly within Confluence. We are hard at work integrating Confluence more seamlessly into GitLab. If you'd like to stay up to date, follow our %{wiki_confluence_epic_link_start}Confluence epic%{wiki_confluence_epic_link_end}.").html_safe % { wiki_confluence_epic_link_start: wiki_confluence_epic_link_start, wiki_confluence_epic_link_end: '</a>'.html_safe }
= link_to @project.confluence_service.confluence_url, target: '_blank', rel: 'noopener noreferrer', class: 'gl-button btn btn-success external-url', title: s_('WikiEmpty|Go to Confluence') do
- wiki_confluence_epic_link_start = format('<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe, url: wiki_confluence_epic_link_url)
= format(s_("WikiEmpty|You've enabled the Confluence Workspace integration. Your wiki will be viewable directly within Confluence. We are hard at work integrating Confluence more seamlessly into GitLab. If you'd like to stay up to date, follow our %{wiki_confluence_epic_link_start}Confluence epic%{wiki_confluence_epic_link_end}.").html_safe, wiki_confluence_epic_link_start: wiki_confluence_epic_link_start, wiki_confluence_epic_link_end: '</a>'.html_safe)
= link_to @project.confluence_integration.confluence_url, target: '_blank', rel: 'noopener noreferrer', class: 'gl-button btn btn-success external-url', title: s_('WikiEmpty|Go to Confluence') do
= sprite_icon('external-link')
= s_('WikiEmpty|Go to Confluence')
......@@ -11928,8 +11928,8 @@ four standard [pagination arguments](#connection-pagination-arguments):
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="projectservicesactive"></a>`active` | [`Boolean`](#boolean) | Indicates if the service is active. |
| <a id="projectservicestype"></a>`type` | [`ServiceType`](#servicetype) | Class name of the service. |
| <a id="projectservicesactive"></a>`active` | [`Boolean`](#boolean) | Indicates if the integration is active. |
| <a id="projectservicestype"></a>`type` | [`ServiceType`](#servicetype) | Type of integration. |
##### `Project.snippets`
......
......@@ -1075,6 +1075,16 @@ expect(json_string).to be_valid_json
expect(json_string).to be_valid_json.and match_schema(schema)
```
#### `be_one_of(collection)`
The inverse of `include`, tests that the `collection` includes the expected
value:
```ruby
expect(:a).to be_one_of(%i[a b c])
expect(:z).not_to be_one_of(%i[a b c])
```
### Testing query performance
Testing query performance allows us to:
......
......@@ -14,7 +14,7 @@ RSpec.describe Sidebars::Projects::Menus::JiraMenu do
describe 'render?' do
context 'when issue tracker is not Jira' do
it 'returns false' do
create(:custom_issue_tracker_service, active: true, project: project, project_url: 'http://test.com')
create(:custom_issue_tracker_integration, active: true, project: project, project_url: 'http://test.com')
expect(subject.render?).to eq false
end
......
......@@ -403,15 +403,15 @@ module Gitlab
def services_usage
# rubocop: disable UsageData/LargeTable:
Integration.available_services_names(include_dev: false).each_with_object({}) do |service_name, response|
service_type = Integration.service_name_to_type(service_name)
response["projects_#{service_name}_active".to_sym] = count(Integration.active.where.not(project: nil).where(type: service_type))
response["groups_#{service_name}_active".to_sym] = count(Integration.active.where.not(group: nil).where(type: service_type))
response["templates_#{service_name}_active".to_sym] = count(Integration.active.where(template: true, type: service_type))
response["instances_#{service_name}_active".to_sym] = count(Integration.active.where(instance: true, type: service_type))
response["projects_inheriting_#{service_name}_active".to_sym] = count(Integration.active.where.not(project: nil).where.not(inherit_from_id: nil).where(type: service_type))
response["groups_inheriting_#{service_name}_active".to_sym] = count(Integration.active.where.not(group: nil).where.not(inherit_from_id: nil).where(type: service_type))
Integration.available_services_names(include_dev: false).each_with_object({}) do |name, response|
type = Integration.integration_name_to_type(name)
response[:"projects_#{name}_active"] = count(Integration.active.where.not(project: nil).where(type: type))
response[:"groups_#{name}_active"] = count(Integration.active.where.not(group: nil).where(type: type))
response[:"templates_#{name}_active"] = count(Integration.active.where(template: true, type: type))
response[:"instances_#{name}_active"] = count(Integration.active.where(instance: true, type: type))
response[:"projects_inheriting_#{name}_active"] = count(Integration.active.where.not(project: nil).where.not(inherit_from_id: nil).where(type: type))
response[:"groups_inheriting_#{name}_active"] = count(Integration.active.where.not(group: nil).where.not(inherit_from_id: nil).where(type: type))
end.merge(jira_usage, jira_import_usage)
# rubocop: enable UsageData/LargeTable:
end
......
......@@ -310,7 +310,7 @@ RSpec.describe Projects::IssuesController do
context 'external issue tracker' do
let!(:service) do
create(:custom_issue_tracker_service, project: project, new_issue_url: 'http://test.com')
create(:custom_issue_tracker_integration, project: project, new_issue_url: 'http://test.com')
end
before do
......
......@@ -6,7 +6,7 @@ FactoryBot.define do
type { 'Integration' }
end
factory :custom_issue_tracker_service, class: 'Integrations::CustomIssueTracker' do
factory :custom_issue_tracker_integration, class: 'Integrations::CustomIssueTracker' do
project
active { true }
issue_tracker
......@@ -79,13 +79,13 @@ FactoryBot.define do
end
end
factory :confluence_service, class: 'Integrations::Confluence' do
factory :confluence_integration, class: 'Integrations::Confluence' do
project
active { true }
confluence_url { 'https://example.atlassian.net/wiki' }
end
factory :bugzilla_service, class: 'Integrations::Bugzilla' do
factory :bugzilla_integration, class: 'Integrations::Bugzilla' do
project
active { true }
issue_tracker
......
......@@ -12,7 +12,7 @@ RSpec.describe 'User views the Confluence page' do
end
it 'shows the page when the Confluence integration is enabled' do
service = create(:confluence_service, project: project)
service = create(:confluence_integration, project: project)
visit project_wikis_confluence_path(project)
......
......@@ -75,7 +75,7 @@ RSpec.describe 'Project > User views empty wiki' do
context 'and Confluence is already enabled' do
before do
create(:confluence_service, project: project)
create(:confluence_integration, project: project)
end
it_behaves_like 'empty wiki message', writable: true, issuable: true, confluence: false
......
......@@ -7,7 +7,7 @@ RSpec.describe Projects::ServicesController, '(JavaScript fixtures)', type: :con
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project_empty_repo, namespace: namespace, path: 'services-project') }
let!(:service) { create(:custom_issue_tracker_service, project: project) }
let!(:service) { create(:custom_issue_tracker_integration, project: project) }
let(:user) { project.owner }
render_views
......
......@@ -10,7 +10,7 @@ RSpec.describe Types::Projects::ServiceType do
expect(described_class.resolve_type(build(:jira_service), {})).to eq(Types::Projects::Services::JiraServiceType)
expect(described_class.resolve_type(build(:service), {})).to eq(Types::Projects::Services::BaseServiceType)
expect(described_class.resolve_type(build(:drone_ci_service), {})).to eq(Types::Projects::Services::BaseServiceType)
expect(described_class.resolve_type(build(:custom_issue_tracker_service), {})).to eq(Types::Projects::Services::BaseServiceType)
expect(described_class.resolve_type(build(:custom_issue_tracker_integration), {})).to eq(Types::Projects::Services::BaseServiceType)
end
end
end
......@@ -3,13 +3,11 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['ServiceType'] do
specify { expect(described_class.graphql_name).to eq('ServiceType') }
it 'exposes all the existing project services' do
expect(described_class.values.keys).to match_array(available_services_enum)
end
end
def available_services_enum
::Integration.available_services_types(include_dev: false).map(&:underscore).map(&:upcase)
def available_services_enum
::Integration.available_services_types(include_dev: false).map(&:underscore).map(&:upcase)
end
end
......@@ -291,7 +291,7 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
services.create!(id: 20, type: 'JiraService', properties: jira_properties.to_json, category: 'issue_tracker')
end
let!(:bugzilla_service_valid) do
let!(:bugzilla_integration_valid) do
services.create!(id: 11, type: 'BugzillaService', title: nil, properties: tracker_properties.to_json, category: 'issue_tracker')
end
......@@ -314,14 +314,14 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
expect(jira_service_valid.title).to eq(title)
expect(jira_service_valid.description).to eq(description)
bugzilla_service_valid.reload
data = IssueTrackerData.find_by(service_id: bugzilla_service_valid.id)
bugzilla_integration_valid.reload
data = IssueTrackerData.find_by(service_id: bugzilla_integration_valid.id)
expect(data.project_url).to eq(url)
expect(data.issues_url).to eq(issues_url)
expect(data.new_issue_url).to eq(new_issue_url)
expect(bugzilla_service_valid.title).to eq(title)
expect(bugzilla_service_valid.description).to eq(description)
expect(bugzilla_integration_valid.title).to eq(title)
expect(bugzilla_integration_valid.description).to eq(description)
end
end
end
......@@ -362,8 +362,8 @@ project:
- boards
- last_event
- integrations
- campfire_service
- confluence_service
- campfire_integration
- confluence_integration
- datadog_service
- discord_service
- drone_ci_service
......@@ -376,22 +376,22 @@ project:
- pivotaltracker_service
- prometheus_service
- flowdock_service
- assembla_service
- asana_service
- assembla_integration
- asana_integration
- slack_service
- microsoft_teams_service
- mattermost_service
- hangouts_chat_service
- unify_circuit_service
- buildkite_service
- bamboo_service
- buildkite_integration
- bamboo_integration
- teamcity_service
- pushover_service
- jira_service
- redmine_service
- youtrack_service
- custom_issue_tracker_service
- bugzilla_service
- custom_issue_tracker_integration
- bugzilla_integration
- ewm_service
- external_wiki_service
- mock_ci_service
......
......@@ -18,7 +18,7 @@ RSpec.describe Sidebars::Projects::Menus::ConfluenceMenu do
end
context 'when Confluence integration is present' do
let!(:confluence) { create(:confluence_service, project: project, active: active) }
let!(:confluence) { create(:confluence_integration, project: project, active: active) }
context 'when integration is disabled' do
let(:active) { false }
......
......@@ -20,7 +20,7 @@ RSpec.describe Sidebars::Projects::Menus::ExternalIssueTrackerMenu do
end
context 'when active external issue tracker' do
let(:external_issue_tracker) { build(:custom_issue_tracker_service, project: project) }
let(:external_issue_tracker) { build(:custom_issue_tracker_integration, project: project) }
context 'is present' do
it 'returns true' do
......
......@@ -16,7 +16,7 @@ RSpec.describe Sidebars::Projects::Panel do
subject { described_class.new(context).instance_variable_get(:@menus) }
context 'when integration is present and active' do
let_it_be(:confluence) { create(:confluence_service, active: true) }
let_it_be(:confluence) { create(:confluence_integration, active: true) }
let(:project) { confluence.project }
......
......@@ -22,7 +22,7 @@ RSpec.describe MigrateIssueTrackersData do
services.create!(type: 'JiraService', properties: nil, category: 'issue_tracker')
end
let!(:bugzilla_service) do
let!(:bugzilla_integration) do
services.create!(type: 'BugzillaService', properties: properties, category: 'issue_tracker')
end
......@@ -55,7 +55,7 @@ RSpec.describe MigrateIssueTrackersData do
freeze_time do
migrate!
expect(migration_name).to be_scheduled_delayed_migration(3.minutes, jira_service.id, bugzilla_service.id)
expect(migration_name).to be_scheduled_delayed_migration(3.minutes, jira_service.id, bugzilla_integration.id)
expect(migration_name).to be_scheduled_delayed_migration(6.minutes, youtrack_service.id, gitlab_service.id)
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
end
......
......@@ -22,7 +22,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
services.create!(id: 11, type: 'JiraService', properties: nil, category: 'issue_tracker')
end
let!(:bugzilla_service) do
let!(:bugzilla_integration) do
services.create!(id: 12, type: 'BugzillaService', properties: properties, category: 'issue_tracker')
end
......@@ -56,7 +56,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
freeze_time do
migrate!
expect(migration_name).to be_scheduled_delayed_migration(3.minutes, jira_service.id, bugzilla_service.id)
expect(migration_name).to be_scheduled_delayed_migration(3.minutes, jira_service.id, bugzilla_integration.id)
expect(migration_name).to be_scheduled_delayed_migration(6.minutes, youtrack_service.id, gitlab_service.id)
expect(BackgroundMigrationWorker.jobs.size).to eq(2)
end
......@@ -70,7 +70,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
let!(:valid_issue_tracker_data) do
issue_tracker_data.create!(
service_id: bugzilla_service.id,
service_id: bugzilla_integration.id,
encrypted_issues_url: 'http://url.com',
encrypted_issues_url_iv: 'somevalue'
)
......@@ -78,7 +78,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
let!(:invalid_issue_tracker_data) do
issue_tracker_data.create!(
service_id: bugzilla_service.id,
service_id: bugzilla_integration.id,
encrypted_issues_url: 'http:url.com',
encrypted_issues_url_iv: nil
)
......@@ -86,7 +86,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
let!(:valid_jira_tracker_data) do
jira_tracker_data.create!(
service_id: bugzilla_service.id,
service_id: bugzilla_integration.id,
encrypted_url: 'http://url.com',
encrypted_url_iv: 'somevalue'
)
......@@ -94,7 +94,7 @@ RSpec.describe RescheduleMigrateIssueTrackersData do
let!(:invalid_jira_tracker_data) do
jira_tracker_data.create!(
service_id: bugzilla_service.id,
service_id: bugzilla_integration.id,
encrypted_url: 'http://url.com',
encrypted_url_iv: nil
)
......
......@@ -4822,7 +4822,7 @@ RSpec.describe Ci::Build do
context 'with project services' do
before do
create(:service, active: true, job_events: true, project: project)
create(:integration, active: true, job_events: true, project: project)
end
it 'executes services' do
......@@ -4836,7 +4836,7 @@ RSpec.describe Ci::Build do
context 'without relevant project services' do
before do
create(:service, active: true, job_events: false, project: project)
create(:integration, active: true, job_events: false, project: project)
end
it 'does not execute services' do
......
......@@ -160,7 +160,7 @@ RSpec.describe Integration do
context 'when instance-level service' do
Integration.available_services_types.each do |service_type|
let(:service) do
described_class.send(:service_type_to_model, service_type).new(instance: true)
described_class.send(:integration_type_to_model, service_type).new(instance: true)
end
it { is_expected.to be_falsey }
......@@ -170,7 +170,7 @@ RSpec.describe Integration do
context 'when group-level service' do
Integration.available_services_types.each do |service_type|
let(:service) do
described_class.send(:service_type_to_model, service_type).new(group_id: group.id)
described_class.send(:integration_type_to_model, service_type).new(group_id: group.id)
end
it { is_expected.to be_falsey }
......@@ -668,16 +668,16 @@ RSpec.describe Integration do
end
end
describe '.service_name_to_model' do
describe '.integration_name_to_model' do
it 'returns the model for the given service name', :aggregate_failures do
expect(described_class.service_name_to_model('asana')).to eq(Integrations::Asana)
expect(described_class.integration_name_to_model('asana')).to eq(Integrations::Asana)
# TODO We can remove this test when all models have been namespaced:
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60968#note_570994955
expect(described_class.service_name_to_model('prometheus')).to eq(PrometheusService)
expect(described_class.integration_name_to_model('prometheus')).to eq(PrometheusService)
end
it 'raises an error if service name is invalid' do
expect { described_class.service_name_to_model('foo') }.to raise_exception(NameError, /uninitialized constant FooService/)
expect { described_class.integration_name_to_model('foo') }.to raise_exception(NameError, /uninitialized constant FooService/)
end
end
......
......@@ -15,8 +15,8 @@ RSpec.describe Integrations::Assembla do
let(:project) { create(:project, :repository) }
before do
@assembla_service = described_class.new
allow(@assembla_service).to receive_messages(
@assembla_integration = described_class.new
allow(@assembla_integration).to receive_messages(
project_id: project.id,
project: project,
service_hook: true,
......@@ -29,7 +29,7 @@ RSpec.describe Integrations::Assembla do
end
it "calls Assembla API" do
@assembla_service.execute(@sample_data)
@assembla_integration.execute(@sample_data)
expect(WebMock).to have_requested(:post, stubbed_hostname(@api_url)).with(
body: /#{@sample_data[:before]}.*#{@sample_data[:after]}.*#{project.path}/
).once
......
......@@ -82,45 +82,45 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do
describe 'before_update :reset_password' do
context 'when a password was previously set' do
it 'resets password if url changed' do
bamboo_service = service
bamboo_integration = service
bamboo_service.bamboo_url = 'http://gitlab1.com'
bamboo_service.save!
bamboo_integration.bamboo_url = 'http://gitlab1.com'
bamboo_integration.save!
expect(bamboo_service.password).to be_nil
expect(bamboo_integration.password).to be_nil
end
it 'does not reset password if username changed' do
bamboo_service = service
bamboo_integration = service
bamboo_service.username = 'some_name'
bamboo_service.save!
bamboo_integration.username = 'some_name'
bamboo_integration.save!
expect(bamboo_service.password).to eq('password')
expect(bamboo_integration.password).to eq('password')
end
it "does not reset password if new url is set together with password, even if it's the same password" do
bamboo_service = service
bamboo_integration = service
bamboo_service.bamboo_url = 'http://gitlab_edited.com'
bamboo_service.password = 'password'
bamboo_service.save!
bamboo_integration.bamboo_url = 'http://gitlab_edited.com'
bamboo_integration.password = 'password'
bamboo_integration.save!
expect(bamboo_service.password).to eq('password')
expect(bamboo_service.bamboo_url).to eq('http://gitlab_edited.com')
expect(bamboo_integration.password).to eq('password')
expect(bamboo_integration.bamboo_url).to eq('http://gitlab_edited.com')
end
end
it 'saves password if new url is set together with password when no password was previously set' do
bamboo_service = service
bamboo_service.password = nil
bamboo_integration = service
bamboo_integration.password = nil
bamboo_service.bamboo_url = 'http://gitlab_edited.com'
bamboo_service.password = 'password'
bamboo_service.save!
bamboo_integration.bamboo_url = 'http://gitlab_edited.com'
bamboo_integration.password = 'password'
bamboo_integration.save!
expect(bamboo_service.password).to eq('password')
expect(bamboo_service.bamboo_url).to eq('http://gitlab_edited.com')
expect(bamboo_integration.password).to eq('password')
expect(bamboo_integration.bamboo_url).to eq('http://gitlab_edited.com')
end
end
end
......
......@@ -10,7 +10,7 @@ RSpec.describe Integrations::BaseIssueTracker do
let(:service) { Integrations::Redmine.new(project: project, active: true, issue_tracker_data: build(:issue_tracker_data)) }
before do
create(:custom_issue_tracker_service, project: project)
create(:custom_issue_tracker_integration, project: project)
end
context 'when service is changed manually by user' do
......
......@@ -33,8 +33,8 @@ RSpec.describe Integrations::Campfire do
let(:project) { create(:project, :repository) }
before do
@campfire_service = described_class.new
allow(@campfire_service).to receive_messages(
@campfire_integration = described_class.new
allow(@campfire_integration).to receive_messages(
project_id: project.id,
project: project,
service_hook: true,
......@@ -62,7 +62,7 @@ RSpec.describe Integrations::Campfire do
speak_url = 'https://project-name.campfirenow.com/room/123/speak.json'
stub_full_request(speak_url, method: :post).with(basic_auth: @auth)
@campfire_service.execute(@sample_data)
@campfire_integration.execute(@sample_data)
expect(WebMock).to have_requested(:get, stubbed_hostname(@rooms_url)).once
expect(WebMock).to have_requested(:post, stubbed_hostname(speak_url))
......@@ -78,7 +78,7 @@ RSpec.describe Integrations::Campfire do
headers: @headers
)
@campfire_service.execute(@sample_data)
@campfire_integration.execute(@sample_data)
expect(WebMock).to have_requested(:get, 'https://8.8.8.9/rooms.json').once
expect(WebMock).not_to have_requested(:post, '*/room/.*/speak.json')
......
......@@ -72,19 +72,19 @@ RSpec.describe Integrations::Confluence do
subject { project.project_setting.has_confluence? }
it 'sets the property to true when service is active' do
create(:confluence_service, project: project, active: true)
create(:confluence_integration, project: project, active: true)
is_expected.to be(true)
end
it 'sets the property to false when service is not active' do
create(:confluence_service, project: project, active: false)
create(:confluence_integration, project: project, active: false)
is_expected.to be(false)
end
it 'creates a project_setting record if one was not already created' do
expect { create(:confluence_service) }.to change { ProjectSetting.count }.by(1)
expect { create(:confluence_integration) }.to change(ProjectSetting, :count).by(1)
end
end
end
......@@ -43,9 +43,9 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:webex_teams_service) }
it { is_expected.to have_one(:packagist_service) }
it { is_expected.to have_one(:pushover_service) }
it { is_expected.to have_one(:asana_service) }
it { is_expected.to have_one(:asana_integration) }
it { is_expected.to have_many(:boards) }
it { is_expected.to have_one(:campfire_service) }
it { is_expected.to have_one(:campfire_integration) }
it { is_expected.to have_one(:datadog_service) }
it { is_expected.to have_one(:discord_service) }
it { is_expected.to have_one(:drone_ci_service) }
......@@ -54,20 +54,20 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:irker_service) }
it { is_expected.to have_one(:pivotaltracker_service) }
it { is_expected.to have_one(:flowdock_service) }
it { is_expected.to have_one(:assembla_service) }
it { is_expected.to have_one(:assembla_integration) }
it { is_expected.to have_one(:slack_slash_commands_service) }
it { is_expected.to have_one(:mattermost_slash_commands_service) }
it { is_expected.to have_one(:buildkite_service) }
it { is_expected.to have_one(:bamboo_service) }
it { is_expected.to have_one(:buildkite_integration) }
it { is_expected.to have_one(:bamboo_integration) }
it { is_expected.to have_one(:teamcity_service) }
it { is_expected.to have_one(:jira_service) }
it { is_expected.to have_one(:redmine_service) }
it { is_expected.to have_one(:youtrack_service) }
it { is_expected.to have_one(:custom_issue_tracker_service) }
it { is_expected.to have_one(:bugzilla_service) }
it { is_expected.to have_one(:custom_issue_tracker_integration) }
it { is_expected.to have_one(:bugzilla_integration) }
it { is_expected.to have_one(:ewm_service) }
it { is_expected.to have_one(:external_wiki_service) }
it { is_expected.to have_one(:confluence_service) }
it { is_expected.to have_one(:confluence_integration) }
it { is_expected.to have_one(:project_feature) }
it { is_expected.to have_one(:project_repository) }
it { is_expected.to have_one(:container_expiration_policy) }
......@@ -5311,7 +5311,7 @@ RSpec.describe Project, factory_default: :keep do
it { expect(project.has_active_services?).to be_falsey }
it 'returns true when a matching service exists' do
create(:custom_issue_tracker_service, push_events: true, merge_requests_events: false, project: project)
create(:custom_issue_tracker_integration, push_events: true, merge_requests_events: false, project: project)
expect(project.has_active_services?(:merge_request_hooks)).to be_falsey
expect(project.has_active_services?).to be_truthy
......
......@@ -8,7 +8,7 @@ RSpec.describe 'query Jira service' do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:jira_service) { create(:jira_service, project: project) }
let_it_be(:bugzilla_service) { create(:bugzilla_service, project: project) }
let_it_be(:bugzilla_integration) { create(:bugzilla_integration, project: project) }
let_it_be(:redmine_service) { create(:redmine_service, project: project) }
let(:query) do
......
......@@ -26,7 +26,7 @@ RSpec.describe API::Services do
context 'project with services' do
let!(:active_service) { create(:emails_on_push_service, project: project, active: true) }
let!(:service) { create(:custom_issue_tracker_service, project: project, active: false) }
let!(:service) { create(:custom_issue_tracker_integration, project: project, active: false) }
it "returns a list of all active services" do
get api("/projects/#{project.id}/services", user)
......
......@@ -103,7 +103,7 @@ RSpec.describe Issues::CloseService do
end
context 'with an active external issue tracker not supporting close_issue' do
let!(:external_issue_tracker) { create(:bugzilla_service, project: project) }
let!(:external_issue_tracker) { create(:bugzilla_integration, project: project) }
it 'does not close the issue on the external issue tracker' do
project.reload
......
......@@ -251,22 +251,22 @@ RSpec.describe MergeRequests::BuildService do
end
context 'when the source branch matches an issue' do
where(:issue_tracker, :source_branch, :closing_message) do
:jira | 'FOO-123-fix-issue' | 'Closes FOO-123'
:jira | 'fix-issue' | nil
:custom_issue_tracker | '123-fix-issue' | 'Closes #123'
:custom_issue_tracker | 'fix-issue' | nil
:internal | '123-fix-issue' | 'Closes #123'
:internal | 'fix-issue' | nil
where(:factory, :source_branch, :closing_message) do
:jira_service | 'FOO-123-fix-issue' | 'Closes FOO-123'
:jira_service | 'fix-issue' | nil
:custom_issue_tracker_integration | '123-fix-issue' | 'Closes #123'
:custom_issue_tracker_integration | 'fix-issue' | nil
nil | '123-fix-issue' | 'Closes #123'
nil | 'fix-issue' | nil
end
with_them do
before do
if issue_tracker == :internal
issue.update!(iid: 123)
else
create(:"#{issue_tracker}_service", project: project)
if factory
create(factory, project: project)
project.reload
else
issue.update!(iid: 123)
end
end
......@@ -350,23 +350,23 @@ RSpec.describe MergeRequests::BuildService do
end
context 'when the source branch matches an issue' do
where(:issue_tracker, :source_branch, :title, :closing_message) do
:jira | 'FOO-123-fix-issue' | 'Resolve FOO-123 "Fix issue"' | 'Closes FOO-123'
:jira | 'fix-issue' | 'Fix issue' | nil
:custom_issue_tracker | '123-fix-issue' | 'Resolve #123 "Fix issue"' | 'Closes #123'
:custom_issue_tracker | 'fix-issue' | 'Fix issue' | nil
:internal | '123-fix-issue' | 'Resolve "A bug"' | 'Closes #123'
:internal | 'fix-issue' | 'Fix issue' | nil
:internal | '124-fix-issue' | '124 fix issue' | nil
where(:factory, :source_branch, :title, :closing_message) do
:jira_service | 'FOO-123-fix-issue' | 'Resolve FOO-123 "Fix issue"' | 'Closes FOO-123'
:jira_service | 'fix-issue' | 'Fix issue' | nil
:custom_issue_tracker_integration | '123-fix-issue' | 'Resolve #123 "Fix issue"' | 'Closes #123'
:custom_issue_tracker_integration | 'fix-issue' | 'Fix issue' | nil
nil | '123-fix-issue' | 'Resolve "A bug"' | 'Closes #123'
nil | 'fix-issue' | 'Fix issue' | nil
nil | '124-fix-issue' | '124 fix issue' | nil
end
with_them do
before do
if issue_tracker == :internal
issue.update!(iid: 123)
else
create(:"#{issue_tracker}_service", project: project)
if factory
create(factory, project: project)
project.reload
else
issue.update!(iid: 123)
end
end
......@@ -399,23 +399,23 @@ RSpec.describe MergeRequests::BuildService do
end
context 'when the source branch matches an issue' do
where(:issue_tracker, :source_branch, :title, :closing_message) do
:jira | 'FOO-123-fix-issue' | 'Resolve FOO-123 "Fix issue"' | 'Closes FOO-123'
:jira | 'fix-issue' | 'Fix issue' | nil
:custom_issue_tracker | '123-fix-issue' | 'Resolve #123 "Fix issue"' | 'Closes #123'
:custom_issue_tracker | 'fix-issue' | 'Fix issue' | nil
:internal | '123-fix-issue' | 'Resolve "A bug"' | 'Closes #123'
:internal | 'fix-issue' | 'Fix issue' | nil
:internal | '124-fix-issue' | '124 fix issue' | nil
where(:factory, :source_branch, :title, :closing_message) do
:jira_service | 'FOO-123-fix-issue' | 'Resolve FOO-123 "Fix issue"' | 'Closes FOO-123'
:jira_service | 'fix-issue' | 'Fix issue' | nil
:custom_issue_tracker_integration | '123-fix-issue' | 'Resolve #123 "Fix issue"' | 'Closes #123'
:custom_issue_tracker_integration | 'fix-issue' | 'Fix issue' | nil
nil | '123-fix-issue' | 'Resolve "A bug"' | 'Closes #123'
nil | 'fix-issue' | 'Fix issue' | nil
nil | '124-fix-issue' | '124 fix issue' | nil
end
with_them do
before do
if issue_tracker == :internal
issue.update!(iid: 123)
else
create(:"#{issue_tracker}_service", project: project)
if factory
create(factory, project: project)
project.reload
else
issue.update!(iid: 123)
end
end
......
......@@ -735,7 +735,7 @@ RSpec.describe ::SystemNotes::IssuablesService do
end
it 'is true with issue tracker not supporting referencing' do
create(:bugzilla_service, project: project)
create(:bugzilla_integration, project: project)
project.reload
expect(service.cross_reference_disallowed?(noteable)).to be_truthy
......
# frozen_string_literal: true
RSpec::Matchers.define :be_one_of do |collection|
match do |item|
expect(collection).to include(item)
end
failure_message do |item|
"expected #{item} to be one of #{collection}"
end
end
......@@ -5,8 +5,8 @@ Integration.available_services_names.each do |service|
include JiraServiceHelper if service == 'jira'
let(:dashed_service) { service.dasherize }
let(:service_method) { "#{service}_service".to_sym }
let(:service_klass) { Integration.service_name_to_model(service) }
let(:service_method) { integration_association(service) }
let(:service_klass) { Integration.integration_name_to_model(service) }
let(:service_instance) { service_klass.new }
let(:service_fields) { service_instance.fields }
let(:service_attrs_list) { service_fields.inject([]) {|arr, hash| arr << hash[:name].to_sym } }
......@@ -57,6 +57,16 @@ Integration.available_services_names.each do |service|
service_item
end
# Returns the association name for the given integration.
# Example: 'asana' => 'asana_integration'
def integration_association(name)
if Integration::RENAMED_TO_INTEGRATION.include?(name)
"#{name}_integration".to_sym
else
"#{name}_service".to_sym
end
end
private
def enable_license_for_service(service)
......
......@@ -288,7 +288,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
let(:external_issue_tracker_url) { 'http://test.com' }
let!(:external_issue_tracker) do
create(:custom_issue_tracker_service, active: external_issue_tracker_active, project: project, project_url: external_issue_tracker_url)
create(:custom_issue_tracker_integration, active: external_issue_tracker_active, project: project, project_url: external_issue_tracker_url)
end
context 'when external issue tracker is configured and active' do
......@@ -1005,7 +1005,7 @@ RSpec.describe 'layouts/nav/sidebar/_project' do
end
describe 'Confluence' do
let!(:service) { create(:confluence_service, project: project, active: active) }
let!(:service) { create(:confluence_integration, project: project, active: active) }
before do
render
......
......@@ -375,7 +375,7 @@ RSpec.describe PostReceive do
it 'asks the project to trigger all hooks' do
create(:project_hook, push_events: true, tag_push_events: true, project: project)
create(:custom_issue_tracker_service, push_events: true, merge_requests_events: false, project: project)
create(:custom_issue_tracker_integration, push_events: true, merge_requests_events: false, project: project)
allow(Project).to receive(:find_by).and_return(project)
expect(project).to receive(:execute_hooks).twice
......
......@@ -6,7 +6,7 @@ RSpec.describe PropagateIntegrationInheritWorker do
describe '#perform' do
let_it_be(:integration) { create(:redmine_service, :instance) }
let_it_be(:integration1) { create(:redmine_service, inherit_from_id: integration.id) }
let_it_be(:integration2) { create(:bugzilla_service, inherit_from_id: integration.id) }
let_it_be(:integration2) { create(:bugzilla_integration, inherit_from_id: integration.id) }
let_it_be(:integration3) { create(:redmine_service) }
it_behaves_like 'an idempotent worker' do
......
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