Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2022-05-27 03:08:03 +00:00
parent 17f6b320a1
commit c258498bd2
20 changed files with 396 additions and 170 deletions

View File

@ -4785,7 +4785,6 @@ Layout/LineLength:
- 'spec/lib/bulk_imports/groups/loaders/group_loader_spec.rb'
- 'spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb'
- 'spec/lib/bulk_imports/groups/pipelines/subgroup_entities_pipeline_spec.rb'
- 'spec/lib/bulk_imports/groups/stage_spec.rb'
- 'spec/lib/bulk_imports/ndjson_pipeline_spec.rb'
- 'spec/lib/bulk_imports/pipeline_spec.rb'
- 'spec/lib/bulk_imports/projects/pipelines/external_pull_requests_pipeline_spec.rb'

View File

@ -1,4 +1,3 @@
import $ from 'jquery';
import { escape } from 'lodash';
import { __, sprintf } from '~/locale';
import eventHub from '~/projects/new/event_hub';
@ -63,9 +62,8 @@ export default function initProjectVisibilitySelector() {
const namespaceSelector = document.querySelector('select.js-select-namespace');
if (namespaceSelector) {
$('.select2.js-select-namespace').on('change', () =>
handleSelect2DropdownChange(namespaceSelector),
);
const el = document.querySelector('.select2.js-select-namespace');
el.addEventListener('change', () => handleSelect2DropdownChange(namespaceSelector));
handleSelect2DropdownChange(namespaceSelector);
}
}

View File

@ -113,7 +113,7 @@ export default {
data-testid="ok"
category="primary"
class="gl-mt-2"
variant="info"
variant="confirm"
:href="pipelinePath"
:data-track-property="humanAccess"
:data-track-value="$options.SP_SHOW_TRACK_VALUE"

View File

@ -99,18 +99,7 @@ class BulkImports::Entity < ApplicationRecord
end
def pipeline_exists?(name)
pipelines.any? { |_, pipeline| pipeline.to_s == name.to_s }
end
def create_pipeline_trackers!
self.class.transaction do
pipelines.each do |stage, pipeline|
trackers.create!(
stage: stage,
pipeline_name: pipeline
)
end
end
pipelines.any? { _1[:pipeline].to_s == name.to_s }
end
def entity_type

View File

@ -128,20 +128,6 @@ class MergeRequestWidgetEntity < Grape::Entity
end
end
expose :codeclimate, if: -> (mr, _) { head_pipeline_downloadable_path_for_report_type(:codequality) } do
expose :head_path do |merge_request|
head_pipeline_downloadable_path_for_report_type(:codequality)
end
expose :base_path do |merge_request|
if use_merge_base_with_merged_results?
merge_base_pipeline_downloadable_path_for_report_type(:codequality)
else
base_pipeline_downloadable_path_for_report_type(:codequality)
end
end
end
expose :security_reports_docs_path do |merge_request|
help_page_path('user/application_security/index.md', anchor: 'view-security-scan-information-in-merge-requests')
end

View File

@ -0,0 +1,68 @@
# frozen_string_literal: true
module BulkImports
class CreatePipelineTrackersService
def initialize(entity)
@entity = entity
end
def execute!
entity.class.transaction do
entity.pipelines.each do |pipeline|
status = skip_pipeline?(pipeline) ? -2 : 0
entity.trackers.create!(
stage: pipeline[:stage],
pipeline_name: pipeline[:pipeline],
status: status
)
end
end
end
private
attr_reader :entity
def skip_pipeline?(pipeline)
return false unless source_version.valid?
minimum_version, maximum_version = pipeline.values_at(:minimum_source_version, :maximum_source_version)
if minimum_version && non_patch_source_version < Gitlab::VersionInfo.parse(minimum_version)
log_skipped_pipeline(pipeline, minimum_version, maximum_version)
return true
end
if maximum_version && non_patch_source_version > Gitlab::VersionInfo.parse(maximum_version)
log_skipped_pipeline(pipeline, minimum_version, maximum_version)
return true
end
false
end
def source_version
@source_version ||= entity.bulk_import.source_version_info
end
def non_patch_source_version
Gitlab::VersionInfo.new(source_version.major, source_version.minor, 0)
end
def log_skipped_pipeline(pipeline, minimum_version, maximum_version)
logger.info(
message: 'Pipeline skipped as source instance version not compatible with pipeline',
entity_id: entity.id,
pipeline_name: pipeline[:pipeline],
minimum_source_version: minimum_version,
maximum_source_version: maximum_version,
source_version: source_version.to_s
)
end
def logger
@logger ||= Gitlab::Import::Logger.build
end
end
end

View File

@ -20,7 +20,7 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker
@bulk_import.start! if @bulk_import.created?
created_entities.find_each do |entity|
entity.create_pipeline_trackers!
BulkImports::CreatePipelineTrackersService.new(entity).execute!
BulkImports::ExportRequestWorker.perform_async(entity.id)
BulkImports::EntityWorker.perform_async(entity.id)

View File

@ -13,7 +13,7 @@ info: To determine the technical writer assigned to the Stage/Group associated w
Use the dependency list to review your project's dependencies and key
details about those dependencies, including their known vulnerabilities. It is a collection of dependencies in your project, including existing and new findings.
To see the dependency list, go to your project and select **Security & Compliance > Dependency List**.
To see the dependency list, go to your project and select **Security & Compliance > Dependency list**.
This information is sometimes referred to as a Software Bill of Materials, SBOM, or BOM.

View File

@ -5,6 +5,21 @@ module BulkImports
class Stage < ::BulkImports::Stage
private
# To skip the execution of a pipeline in a specific source instance version, define the attributes
# `minimum_source_version` and `maximum_source_version`.
#
# Use the `minimum_source_version` to inform that the pipeline needs to run when importing from source instances
# version greater than or equal to the specified minimum source version. For example, if the
# `minimum_source_version` is equal to 15.1.0, the pipeline will be executed when importing from source instances
# running versions 15.1.0, 15.1.1, 15.2.0, 16.0.0, etc. And it won't be executed when the source instance version
# is 15.0.1, 15.0.0, 14.10.0, etc.
#
# Use the `maximum_source_version` to inform that the pipeline needs to run when importing from source instance
# versions less than or equal to the specified maximum source version. For example, if the
# `maximum_source_version` is equal to 15.1.0, the pipeline will be executed when importing from source instances
# running versions 15.1.1 (patch), 15.1.0, 15.0.1, 15.0.0, 14.10.0, etc. And it won't be executed when the source
# instance version is 15.2.0, 15.2.1, 16.0.0, etc.
def config
@config ||= {
group: {
@ -21,7 +36,8 @@ module BulkImports
},
namespace_settings: {
pipeline: BulkImports::Groups::Pipelines::NamespaceSettingsPipeline,
stage: 1
stage: 1,
minimum_source_version: '15.0.0'
},
members: {
pipeline: BulkImports::Common::Pipelines::MembersPipeline,

View File

@ -5,6 +5,21 @@ module BulkImports
class Stage < ::BulkImports::Stage
private
# To skip the execution of a pipeline in a specific source instance version, define the attributes
# `minimum_source_version` and `maximum_source_version`.
#
# Use the `minimum_source_version` to inform that the pipeline needs to run when importing from source instances
# version greater than or equal to the specified minimum source version. For example, if the
# `minimum_source_version` is equal to 15.1.0, the pipeline will be executed when importing from source instances
# running versions 15.1.0, 15.1.1, 15.2.0, 16.0.0, etc. And it won't be executed when the source instance version
# is 15.0.1, 15.0.0, 14.10.0, etc.
#
# Use the `maximum_source_version` to inform that the pipeline needs to run when importing from source instance
# versions less than or equal to the specified maximum source version. For example, if the
# `maximum_source_version` is equal to 15.1.0, the pipeline will be executed when importing from source instances
# running versions 15.1.1 (patch), 15.1.0, 15.0.1, 15.0.0, 14.10.0, etc. And it won't be executed when the source
# instance version is 15.2.0, 15.2.1, 16.0.0, etc.
def config
@config ||= {
project: {
@ -97,7 +112,8 @@ module BulkImports
},
design: {
pipeline: BulkImports::Projects::Pipelines::DesignBundlePipeline,
stage: 5
stage: 5,
minimum_source_version: '15.1.0'
},
auto_devops: {
pipeline: BulkImports::Projects::Pipelines::AutoDevopsPipeline,

View File

@ -15,9 +15,6 @@ module BulkImports
@pipelines ||= config
.values
.sort_by { |entry| entry[:stage] }
.map do |entry|
[entry[:stage], entry[:pipeline]]
end
end
private

View File

@ -12190,9 +12190,6 @@ msgstr ""
msgid "Dependencies|All"
msgstr ""
msgid "Dependencies|Based on the %{linkStart}latest successful%{linkEnd} scan"
msgstr ""
msgid "Dependencies|Component"
msgstr ""
@ -12223,6 +12220,9 @@ msgstr ""
msgid "Dependencies|Packager"
msgstr ""
msgid "Dependencies|Software Bill of Materials (SBOM) based on the %{linkStart}latest successful%{linkEnd} scan"
msgstr ""
msgid "Dependencies|The %{codeStartTag}dependency_scanning%{codeEndTag} job has failed and cannot generate the list. Please ensure the job is running properly and run the pipeline again."
msgstr ""

View File

@ -71,7 +71,7 @@ describe('MRWidgetSuggestPipeline', () => {
const button = findOkBtn();
expect(button.exists()).toBe(true);
expect(button.classes('btn-info')).toEqual(true);
expect(button.classes('btn-confirm')).toEqual(true);
expect(button.attributes('href')).toBe(suggestProps.pipelinePath);
});

View File

@ -4,47 +4,86 @@ require 'spec_helper'
RSpec.describe BulkImports::Groups::Stage do
let(:ancestor) { create(:group) }
let(:group) { create(:group, parent: ancestor) }
let(:group) { build(:group, parent: ancestor) }
let(:bulk_import) { build(:bulk_import) }
let(:entity) { build(:bulk_import_entity, bulk_import: bulk_import, group: group, destination_namespace: ancestor.full_path) }
let(:pipelines) do
[
[0, BulkImports::Groups::Pipelines::GroupPipeline],
[1, BulkImports::Groups::Pipelines::GroupAttributesPipeline],
[1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline],
[1, BulkImports::Groups::Pipelines::NamespaceSettingsPipeline],
[1, BulkImports::Common::Pipelines::MembersPipeline],
[1, BulkImports::Common::Pipelines::LabelsPipeline],
[1, BulkImports::Common::Pipelines::MilestonesPipeline],
[1, BulkImports::Common::Pipelines::BadgesPipeline],
[2, BulkImports::Common::Pipelines::BoardsPipeline],
[2, BulkImports::Common::Pipelines::UploadsPipeline]
]
let(:entity) do
build(:bulk_import_entity, bulk_import: bulk_import, group: group, destination_namespace: ancestor.full_path)
end
it 'raises error when initialized without a BulkImport' do
expect { described_class.new({}) }.to raise_error(ArgumentError, 'Expected an argument of type ::BulkImports::Entity')
expect { described_class.new({}) }.to raise_error(
ArgumentError, 'Expected an argument of type ::BulkImports::Entity'
)
end
describe '.pipelines' do
it 'list all the pipelines with their stage number, ordered by stage' do
expect(described_class.new(entity).pipelines & pipelines).to contain_exactly(*pipelines)
expect(described_class.new(entity).pipelines.last.last).to eq(BulkImports::Common::Pipelines::EntityFinisher)
describe '#pipelines' do
it 'lists all the pipelines' do
pipelines = described_class.new(entity).pipelines
expect(pipelines).to include(
hash_including({
pipeline: BulkImports::Groups::Pipelines::GroupPipeline,
stage: 0
}),
hash_including({
pipeline: BulkImports::Groups::Pipelines::GroupAttributesPipeline,
stage: 1
})
)
expect(pipelines.last).to match(hash_including({ pipeline: BulkImports::Common::Pipelines::EntityFinisher }))
end
it 'only has pipelines with valid keys' do
pipeline_keys = described_class.new(entity).pipelines.collect(&:keys).flatten.uniq
allowed_keys = %i[pipeline stage minimum_source_version maximum_source_version]
expect(pipeline_keys - allowed_keys).to be_empty
end
it 'only has pipelines with valid versions' do
pipelines = described_class.new(entity).pipelines
minimum_source_versions = pipelines.collect { _1[:minimum_source_version] }.flatten.compact
maximum_source_versions = pipelines.collect { _1[:maximum_source_version] }.flatten.compact
version_regex = /^(\d+)\.(\d+)\.0$/
expect(minimum_source_versions.all? { version_regex =~ _1 }).to eq(true)
expect(maximum_source_versions.all? { version_regex =~ _1 }).to eq(true)
end
context 'when stages are out of order in the config hash' do
it 'lists all the pipelines ordered by stage' do
allow_next_instance_of(BulkImports::Groups::Stage) do |stage|
allow(stage).to receive(:config).and_return(
{
a: { stage: 2 },
b: { stage: 1 },
c: { stage: 0 },
d: { stage: 2 }
}
)
end
expected_stages = described_class.new(entity).pipelines.collect { _1[:stage] }
expect(expected_stages).to eq([0, 1, 2, 2])
end
end
context 'when bulk_import_projects feature flag is enabled' do
it 'includes project entities pipeline' do
stub_feature_flags(bulk_import_projects: true)
expect(described_class.new(entity).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline])
expect(described_class.new(entity).pipelines).to include(
hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline })
)
end
context 'when feature flag is enabled on root ancestor level' do
it 'includes project entities pipeline' do
stub_feature_flags(bulk_import_projects: ancestor)
expect(described_class.new(entity).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline])
expect(described_class.new(entity).pipelines).to include(
hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline })
)
end
end
@ -54,7 +93,9 @@ RSpec.describe BulkImports::Groups::Stage do
entity = create(:bulk_import_entity, destination_namespace: '')
expect(described_class.new(entity).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline])
expect(described_class.new(entity).pipelines).to include(
hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline })
)
end
end
end
@ -63,7 +104,9 @@ RSpec.describe BulkImports::Groups::Stage do
it 'does not include project entities pipeline' do
stub_feature_flags(bulk_import_projects: false)
expect(described_class.new(entity).pipelines.flatten).not_to include(BulkImports::Groups::Pipelines::ProjectEntitiesPipeline)
expect(described_class.new(entity).pipelines).not_to include(
hash_including({ pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline })
)
end
end
end

View File

@ -2,39 +2,7 @@
require 'spec_helper'
# Any new stages must be added to
# `ee/spec/lib/ee/bulk_imports/projects/stage_spec.rb` as well.
RSpec.describe BulkImports::Projects::Stage do
let(:pipelines) do
[
[0, BulkImports::Projects::Pipelines::ProjectPipeline],
[1, BulkImports::Projects::Pipelines::RepositoryPipeline],
[1, BulkImports::Projects::Pipelines::ProjectAttributesPipeline],
[2, BulkImports::Common::Pipelines::LabelsPipeline],
[2, BulkImports::Common::Pipelines::MilestonesPipeline],
[2, BulkImports::Common::Pipelines::BadgesPipeline],
[3, BulkImports::Projects::Pipelines::IssuesPipeline],
[3, BulkImports::Projects::Pipelines::SnippetsPipeline],
[4, BulkImports::Projects::Pipelines::SnippetsRepositoryPipeline],
[4, BulkImports::Common::Pipelines::BoardsPipeline],
[4, BulkImports::Projects::Pipelines::MergeRequestsPipeline],
[4, BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline],
[4, BulkImports::Projects::Pipelines::ProtectedBranchesPipeline],
[4, BulkImports::Projects::Pipelines::ProjectFeaturePipeline],
[4, BulkImports::Projects::Pipelines::ContainerExpirationPolicyPipeline],
[4, BulkImports::Projects::Pipelines::ServiceDeskSettingPipeline],
[4, BulkImports::Projects::Pipelines::ReleasesPipeline],
[5, BulkImports::Projects::Pipelines::CiPipelinesPipeline],
[5, BulkImports::Common::Pipelines::WikiPipeline],
[5, BulkImports::Common::Pipelines::UploadsPipeline],
[5, BulkImports::Common::Pipelines::LfsObjectsPipeline],
[5, BulkImports::Projects::Pipelines::DesignBundlePipeline],
[5, BulkImports::Projects::Pipelines::AutoDevopsPipeline],
[5, BulkImports::Projects::Pipelines::PipelineSchedulesPipeline],
[6, BulkImports::Common::Pipelines::EntityFinisher]
]
end
subject do
entity = build(:bulk_import_entity, :project_entity)
@ -42,9 +10,49 @@ RSpec.describe BulkImports::Projects::Stage do
end
describe '#pipelines' do
it 'list all the pipelines with their stage number, ordered by stage' do
expect(subject.pipelines & pipelines).to contain_exactly(*pipelines)
expect(subject.pipelines.last.last).to eq(BulkImports::Common::Pipelines::EntityFinisher)
it 'list all the pipelines' do
pipelines = subject.pipelines
expect(pipelines).to include(
hash_including({ stage: 0, pipeline: BulkImports::Projects::Pipelines::ProjectPipeline }),
hash_including({ stage: 1, pipeline: BulkImports::Projects::Pipelines::RepositoryPipeline })
)
expect(pipelines.last).to match(hash_including({ pipeline: BulkImports::Common::Pipelines::EntityFinisher }))
end
it 'only have pipelines with valid keys' do
pipeline_keys = subject.pipelines.collect(&:keys).flatten.uniq
allowed_keys = %i[pipeline stage minimum_source_version maximum_source_version]
expect(pipeline_keys - allowed_keys).to be_empty
end
it 'only has pipelines with valid versions' do
pipelines = subject.pipelines
minimum_source_versions = pipelines.collect { _1[:minimum_source_version] }.flatten.compact
maximum_source_versions = pipelines.collect { _1[:maximum_source_version] }.flatten.compact
version_regex = /^(\d+)\.(\d+)\.0$/
expect(minimum_source_versions.all? { version_regex =~ _1 }).to eq(true)
expect(maximum_source_versions.all? { version_regex =~ _1 }).to eq(true)
end
context 'when stages are out of order in the config hash' do
it 'list all the pipelines ordered by stage' do
allow_next_instance_of(BulkImports::Projects::Stage) do |stage|
allow(stage).to receive(:config).and_return(
{
a: { stage: 2 },
b: { stage: 1 },
c: { stage: 0 },
d: { stage: 2 }
}
)
end
expected_stages = subject.pipelines.collect { _1[:stage] }
expect(expected_stages).to eq([0, 1, 2, 2])
end
end
end
end

View File

@ -160,7 +160,7 @@ RSpec.describe BulkImports::Entity, type: :model do
it 'returns group pipelines' do
entity = build(:bulk_import_entity, :group_entity)
expect(entity.pipelines.flatten).to include(BulkImports::Groups::Pipelines::GroupPipeline)
expect(entity.pipelines.collect { _1[:pipeline] }).to include(BulkImports::Groups::Pipelines::GroupPipeline)
end
end
@ -168,29 +168,7 @@ RSpec.describe BulkImports::Entity, type: :model do
it 'returns project pipelines' do
entity = build(:bulk_import_entity, :project_entity)
expect(entity.pipelines.flatten).to include(BulkImports::Projects::Pipelines::ProjectPipeline)
end
end
end
describe '#create_pipeline_trackers!' do
context 'when entity is group' do
it 'creates trackers for group entity' do
entity = create(:bulk_import_entity, :group_entity)
entity.create_pipeline_trackers!
expect(entity.trackers.count).to eq(BulkImports::Groups::Stage.new(entity).pipelines.count)
expect(entity.trackers.map(&:pipeline_name)).to include(BulkImports::Groups::Pipelines::GroupPipeline.to_s)
end
end
context 'when entity is project' do
it 'creates trackers for project entity' do
entity = create(:bulk_import_entity, :project_entity)
entity.create_pipeline_trackers!
expect(entity.trackers.count).to eq(BulkImports::Projects::Stage.new(entity).pipelines.count)
expect(entity.trackers.map(&:pipeline_name)).to include(BulkImports::Projects::Pipelines::ProjectPipeline.to_s)
expect(entity.pipelines.collect { _1[:pipeline] }).to include(BulkImports::Projects::Pipelines::ProjectPipeline)
end
end
end

View File

@ -67,7 +67,7 @@ RSpec.describe BulkImports::Tracker, type: :model do
describe '#pipeline_class' do
it 'returns the pipeline class' do
entity = create(:bulk_import_entity)
pipeline_class = BulkImports::Groups::Stage.new(entity).pipelines.first[1]
pipeline_class = BulkImports::Groups::Stage.new(entity).pipelines.first[:pipeline]
tracker = create(:bulk_import_tracker, pipeline_name: pipeline_class)
expect(tracker.pipeline_class).to eq(pipeline_class)

View File

@ -77,46 +77,6 @@ RSpec.describe MergeRequestWidgetEntity do
.to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.diff")
end
describe 'codequality report artifacts', :request_store do
let(:merge_base_pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
before do
project.add_developer(user)
allow(resource).to receive_messages(
merge_base_pipeline: merge_base_pipeline,
base_pipeline: pipeline,
head_pipeline: pipeline
)
end
context 'with report artifacts' do
let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
let(:generic_job_id) { pipeline.builds.first.id }
let(:merge_base_job_id) { merge_base_pipeline.builds.first.id }
it 'has head_path and base_path entries' do
expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality")
expect(subject[:codeclimate][:base_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality")
end
context 'on pipelines for merged results' do
let(:pipeline) { create(:ci_pipeline, :merged_result_pipeline, :with_codequality_reports, project: project) }
it 'returns URLs from the head_pipeline and merge_base_pipeline' do
expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality")
expect(subject[:codeclimate][:base_path]).to include("/jobs/#{merge_base_job_id}/artifacts/download?file_type=codequality")
end
end
end
context 'without artifacts' do
it 'does not have data entry' do
expect(subject).not_to include(:codeclimate)
end
end
end
describe 'merge_request_add_ci_config_path' do
let!(:project_auto_devops) { create(:project_auto_devops, :disabled, project: project) }

View File

@ -0,0 +1,168 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::CreatePipelineTrackersService do
describe '#execute!' do
context 'when entity is group' do
it 'creates trackers for group entity' do
bulk_import = create(:bulk_import)
entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import)
described_class.new(entity).execute!
expect(entity.trackers.to_a).to include(
have_attributes(
stage: 0, status_name: :created, relation: BulkImports::Groups::Pipelines::GroupPipeline.to_s
),
have_attributes(
stage: 1, status_name: :created, relation: BulkImports::Groups::Pipelines::GroupAttributesPipeline.to_s
)
)
end
end
context 'when entity is project' do
it 'creates trackers for project entity' do
bulk_import = create(:bulk_import)
entity = create(:bulk_import_entity, :project_entity, bulk_import: bulk_import)
described_class.new(entity).execute!
expect(entity.trackers.to_a).to include(
have_attributes(
stage: 0, status_name: :created, relation: BulkImports::Projects::Pipelines::ProjectPipeline.to_s
),
have_attributes(
stage: 1, status_name: :created, relation: BulkImports::Projects::Pipelines::RepositoryPipeline.to_s
)
)
end
end
context 'when tracker configuration has a minimum version defined' do
before do
allow_next_instance_of(BulkImports::Groups::Stage) do |stage|
allow(stage).to receive(:config).and_return(
{
pipeline1: { pipeline: 'PipelineClass1', stage: 0 },
pipeline2: { pipeline: 'PipelineClass2', stage: 1, minimum_source_version: '14.10.0' },
pipeline3: { pipeline: 'PipelineClass3', stage: 1, minimum_source_version: '15.0.0' },
pipeline5: { pipeline: 'PipelineClass4', stage: 1, minimum_source_version: '15.1.0' },
pipeline6: { pipeline: 'PipelineClass5', stage: 1, minimum_source_version: '16.0.0' }
}
)
end
end
context 'when the source instance version is older than the tracker mininum version' do
let_it_be(:bulk_import) { create(:bulk_import, source_version: '15.0.0') }
let_it_be(:entity) { create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) }
it 'creates trackers as skipped if version requirement does not meet' do
described_class.new(entity).execute!
expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly(
[:created, 'PipelineClass1'],
[:created, 'PipelineClass2'],
[:created, 'PipelineClass3'],
[:skipped, 'PipelineClass4'],
[:skipped, 'PipelineClass5']
)
end
it 'logs an info message for the skipped pipelines' do
expect_next_instance_of(Gitlab::Import::Logger) do |logger|
expect(logger).to receive(:info).with({
message: 'Pipeline skipped as source instance version not compatible with pipeline',
entity_id: entity.id,
pipeline_name: 'PipelineClass4',
minimum_source_version: '15.1.0',
maximum_source_version: nil,
source_version: '15.0.0'
})
expect(logger).to receive(:info).with({
message: 'Pipeline skipped as source instance version not compatible with pipeline',
entity_id: entity.id,
pipeline_name: 'PipelineClass5',
minimum_source_version: '16.0.0',
maximum_source_version: nil,
source_version: '15.0.0'
})
end
described_class.new(entity).execute!
end
end
context 'when the source instance version is undefined' do
it 'creates trackers as created' do
bulk_import = create(:bulk_import, source_version: nil)
entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import)
described_class.new(entity).execute!
expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly(
[:created, 'PipelineClass1'],
[:created, 'PipelineClass2'],
[:created, 'PipelineClass3'],
[:created, 'PipelineClass4'],
[:created, 'PipelineClass5']
)
end
end
end
context 'when tracker configuration has a maximum version defined' do
before do
allow_next_instance_of(BulkImports::Groups::Stage) do |stage|
allow(stage).to receive(:config).and_return(
{
pipeline1: { pipeline: 'PipelineClass1', stage: 0 },
pipeline2: { pipeline: 'PipelineClass2', stage: 1, maximum_source_version: '14.10.0' },
pipeline3: { pipeline: 'PipelineClass3', stage: 1, maximum_source_version: '15.0.0' },
pipeline5: { pipeline: 'PipelineClass4', stage: 1, maximum_source_version: '15.1.0' },
pipeline6: { pipeline: 'PipelineClass5', stage: 1, maximum_source_version: '16.0.0' }
}
)
end
end
context 'when the source instance version is older than the tracker maximum version' do
it 'creates trackers as skipped if version requirement does not meet' do
bulk_import = create(:bulk_import, source_version: '15.0.0')
entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import)
described_class.new(entity).execute!
expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly(
[:created, 'PipelineClass1'],
[:skipped, 'PipelineClass2'],
[:created, 'PipelineClass3'],
[:created, 'PipelineClass4'],
[:created, 'PipelineClass5']
)
end
end
context 'when the source instance version is a patch version' do
it 'creates trackers with the same status as the non-patch source version' do
bulk_import_1 = create(:bulk_import, source_version: '15.0.1')
entity_1 = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import_1)
bulk_import_2 = create(:bulk_import, source_version: '15.0.0')
entity_2 = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import_2)
described_class.new(entity_1).execute!
described_class.new(entity_2).execute!
trackers_1 = entity_1.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }
trackers_2 = entity_2.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }
expect(trackers_1).to eq(trackers_2)
end
end
end
end
end

View File

@ -24,7 +24,7 @@ RSpec.describe BulkImports::PipelineWorker do
allow_next_instance_of(BulkImports::Groups::Stage) do |instance|
allow(instance).to receive(:pipelines)
.and_return([[0, pipeline_class]])
.and_return([{ stage: 0, pipeline: pipeline_class }])
end
end
@ -253,7 +253,7 @@ RSpec.describe BulkImports::PipelineWorker do
allow_next_instance_of(BulkImports::Groups::Stage) do |instance|
allow(instance).to receive(:pipelines)
.and_return([[0, file_extraction_pipeline]])
.and_return([{ stage: 0, pipeline: file_extraction_pipeline }])
end
end