Commit 55b80dfa authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch 'ajk-rename-issue-methods-b' into 'master'

Rename project integration associations, group D [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!63995
parents 034d36ae 4eac6bc2
......@@ -43,8 +43,13 @@ class Integration < ApplicationRecord
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
......
......@@ -146,6 +146,14 @@ class Project < ApplicationRecord
has_one :last_event, -> {order 'events.created_at DESC'}, class_name: 'Event'
has_many :boards
def self.integration_association_name(name)
if ::Integration.renamed?(name)
"#{name}_integration"
else
"#{name}_service"
end
end
# Project integrations
has_one :asana_integration, class_name: 'Integrations::Asana'
has_one :assembla_integration, class_name: 'Integrations::Assembla'
......@@ -155,9 +163,9 @@ class Project < ApplicationRecord
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'
has_one :datadog_integration, class_name: 'Integrations::Datadog'
has_one :discord_integration, class_name: 'Integrations::Discord'
has_one :drone_ci_integration, class_name: 'Integrations::DroneCi'
has_one :emails_on_push_service, class_name: 'Integrations::EmailsOnPush'
has_one :ewm_service, class_name: 'Integrations::Ewm'
has_one :external_wiki_service, class_name: 'Integrations::ExternalWiki'
......
......@@ -156,15 +156,16 @@ module Gitlab
underscored_service = matched_login['service'].underscore
if Integration.available_services_names.include?(underscored_service)
# We treat underscored_service as a trusted input because it is included
# in the Integration.available_services_names allowlist.
service = project.public_send("#{underscored_service}_service") # rubocop:disable GitlabSecurity/PublicSend
return unless Integration.available_services_names.include?(underscored_service)
if service && service.activated? && service.valid_token?(password)
Gitlab::Auth::Result.new(nil, project, :ci, build_authentication_abilities)
end
end
# We treat underscored_service as a trusted input because it is included
# in the Integration.available_services_names allowlist.
accessor = Project.integration_association_name(underscored_service)
service = project.public_send(accessor) # rubocop:disable GitlabSecurity/PublicSend
return unless service && service.activated? && service.valid_token?(password)
Gitlab::Auth::Result.new(nil, project, :ci, build_authentication_abilities)
end
def user_with_password_for_git(login, password)
......
......@@ -5,13 +5,13 @@ require 'spec_helper'
RSpec.describe Projects::ServiceHookLogsController do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:service) { create(:drone_ci_service, project: project) }
let(:log) { create(:web_hook_log, web_hook: service.service_hook) }
let(:integration) { create(:drone_ci_integration, project: project) }
let(:log) { create(:web_hook_log, web_hook: integration.service_hook) }
let(:log_params) do
{
namespace_id: project.namespace,
project_id: project,
service_id: service.to_param,
service_id: integration.to_param,
id: log.id
}
end
......@@ -35,7 +35,7 @@ RSpec.describe Projects::ServiceHookLogsController do
it 'executes the hook and redirects to the service form' do
expect_any_instance_of(ServiceHook).to receive(:execute)
expect_any_instance_of(described_class).to receive(:set_hook_execution_notice)
expect(subject).to redirect_to(edit_project_service_path(project, service))
expect(subject).to redirect_to(edit_project_service_path(project, integration))
end
end
end
......@@ -38,7 +38,7 @@ FactoryBot.define do
end
end
factory :drone_ci_service, class: 'Integrations::DroneCi' do
factory :drone_ci_integration, class: 'Integrations::DroneCi' do
project
active { true }
drone_url { 'https://bamboo.example.com' }
......
......@@ -9,7 +9,7 @@ RSpec.describe Types::Projects::ServiceType do
it 'resolves the corresponding type for objects' 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(:drone_ci_integration), {})).to eq(Types::Projects::Services::BaseServiceType)
expect(described_class.resolve_type(build(:custom_issue_tracker_integration), {})).to eq(Types::Projects::Services::BaseServiceType)
end
end
......
......@@ -196,8 +196,8 @@ RSpec.describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
end
it 'recognizes other ci services' do
project.create_drone_ci_service(active: true)
project.drone_ci_service.update(token: 'token')
project.create_drone_ci_integration(active: true)
project.drone_ci_integration.update(token: 'token')
expect(gl_auth.find_for_git_client('drone-ci-token', 'token', project: project, ip: 'ip')).to eq(Gitlab::Auth::Result.new(nil, project, :ci, described_class.build_authentication_abilities))
end
......
......@@ -363,9 +363,9 @@ project:
- integrations
- campfire_integration
- confluence_integration
- datadog_service
- discord_service
- drone_ci_service
- datadog_integration
- discord_integration
- drone_ci_integration
- emails_on_push_service
- pipelines_email_service
- mattermost_slash_commands_service
......
......@@ -31,7 +31,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
end
end
shared_context :drone_ci_service do
shared_context :drone_ci_integration do
let(:drone) { described_class.new }
let(:project) { create(:project, :repository, name: 'project') }
let(:path) { project.full_path }
......@@ -67,14 +67,14 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
end
describe "service page/path methods" do
include_context :drone_ci_service
include_context :drone_ci_integration
it { expect(drone.build_page(sha, branch)).to eq(build_page) }
it { expect(drone.commit_status_path(sha, branch)).to eq(commit_status_path) }
end
describe '#commit_status' do
include_context :drone_ci_service
include_context :drone_ci_integration
it 'returns the contents of the reactive cache' do
stub_reactive_cache(drone, { commit_status: 'foo' }, 'sha', 'ref')
......@@ -84,7 +84,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
end
describe '#calculate_reactive_cache' do
include_context :drone_ci_service
include_context :drone_ci_integration
describe '#commit_status' do
subject { drone.calculate_reactive_cache(sha, branch)[:commit_status] }
......@@ -130,7 +130,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do
end
describe "execute" do
include_context :drone_ci_service
include_context :drone_ci_integration
let(:user) { create(:user, username: 'username') }
let(:push_sample_data) do
......
......@@ -46,9 +46,9 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:asana_integration) }
it { is_expected.to have_many(:boards) }
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) }
it { is_expected.to have_one(:datadog_integration) }
it { is_expected.to have_one(:discord_integration) }
it { is_expected.to have_one(:drone_ci_integration) }
it { is_expected.to have_one(:emails_on_push_service) }
it { is_expected.to have_one(:pipelines_email_service) }
it { is_expected.to have_one(:irker_service) }
......
......@@ -4,15 +4,15 @@ require 'spec_helper'
RSpec.describe ServiceHookPresenter do
let(:web_hook_log) { create(:web_hook_log, web_hook: service_hook) }
let(:service_hook) { create(:service_hook, integration: service) }
let(:service) { create(:drone_ci_service, project: project) }
let(:service_hook) { create(:service_hook, integration: integration) }
let(:integration) { create(:drone_ci_integration, project: project) }
let(:project) { create(:project) }
describe '#logs_details_path' do
subject { service_hook.present.logs_details_path(web_hook_log) }
let(:expected_path) do
"/#{project.namespace.path}/#{project.name}/-/services/#{service.to_param}/hook_logs/#{web_hook_log.id}"
"/#{project.namespace.path}/#{project.name}/-/services/#{integration.to_param}/hook_logs/#{web_hook_log.id}"
end
it { is_expected.to eq(expected_path) }
......@@ -22,7 +22,7 @@ RSpec.describe ServiceHookPresenter do
subject { service_hook.present.logs_retry_path(web_hook_log) }
let(:expected_path) do
"/#{project.namespace.path}/#{project.name}/-/services/#{service.to_param}/hook_logs/#{web_hook_log.id}/retry"
"/#{project.namespace.path}/#{project.name}/-/services/#{integration.to_param}/hook_logs/#{web_hook_log.id}/retry"
end
it { is_expected.to eq(expected_path) }
......
......@@ -18,10 +18,10 @@ RSpec.describe WebHookLogPresenter do
end
context 'service hook' do
let(:web_hook) { create(:service_hook, integration: service) }
let(:service) { create(:drone_ci_service, project: project) }
let(:web_hook) { create(:service_hook, integration: integration) }
let(:integration) { create(:drone_ci_integration, project: project) }
it { is_expected.to eq(project_service_hook_log_path(project, service, web_hook_log)) }
it { is_expected.to eq(project_service_hook_log_path(project, integration, web_hook_log)) }
end
end
......@@ -38,10 +38,10 @@ RSpec.describe WebHookLogPresenter do
end
context 'service hook' do
let(:web_hook) { create(:service_hook, integration: service) }
let(:service) { create(:drone_ci_service, project: project) }
let(:web_hook) { create(:service_hook, integration: integration) }
let(:integration) { create(:drone_ci_integration, project: project) }
it { is_expected.to eq(retry_project_service_hook_log_path(project, service, web_hook_log)) }
it { is_expected.to eq(retry_project_service_hook_log_path(project, integration, web_hook_log)) }
end
end
end
......@@ -5,7 +5,7 @@ Integration.available_services_names.each do |service|
include JiraServiceHelper if service == 'jira'
let(:dashed_service) { service.dasherize }
let(:service_method) { integration_association(service) }
let(:service_method) { Project.integration_association_name(service) }
let(:service_klass) { Integration.integration_name_to_model(service) }
let(:service_instance) { service_klass.new }
let(:service_fields) { service_instance.fields }
......@@ -57,16 +57,6 @@ 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)
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe 'projects/services/edit' do
let(:integration) { create(:drone_ci_service, project: project) }
let(:integration) { create(:drone_ci_integration, project: project) }
let(:project) { create(:project) }
before 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