Commit 4594e7d7 authored by George Koltsov's avatar George Koltsov

Add Push Rule to Project Migration

  - Add an ability to migrate project Push Rule
    to GitLab Group Migration that includes
    projects
parent 790eea67
# frozen_string_literal: true
module BulkImports
module Projects
module Pipelines
class PushRulePipeline
include NdjsonPipeline
relation_name 'push_rule'
extractor ::BulkImports::Common::Extractors::NdjsonExtractor, relation: relation
end
end
end
end
...@@ -9,7 +9,12 @@ module EE ...@@ -9,7 +9,12 @@ module EE
private private
def ee_config def ee_config
@ee_config ||= {} @ee_config ||= {
push_rule: {
pipeline: ::BulkImports::Projects::Pipelines::PushRulePipeline,
stage: 4
}
}
end end
override :config override :config
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Projects::Pipelines::PushRulePipeline do
let_it_be(:project) { create(:project) }
let_it_be(:bulk_import) { create(:bulk_import) }
let_it_be(:entity) { create(:bulk_import_entity, :project_entity, project: project, bulk_import: bulk_import) }
let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:push_rule) do
{
'force_push_regex' => 'MustContain',
'delete_branch_regex' => 'MustContain',
'commit_message_regex' => 'MustContain',
'author_email_regex' => 'MustContain',
'file_name_regex' => 'MustContain',
'branch_name_regex' => 'MustContain',
'commit_message_negative_regex' => 'MustNotContain',
'max_file_size' => 1,
'deny_delete_tag' => true,
'member_check' => true,
'is_sample' => true,
'prevent_secrets' => true,
'reject_unsigned_commits' => true,
'commit_committer_check' => true,
'regexp_uses_re2' => true
}
end
subject(:pipeline) { described_class.new(context) }
describe '#run' do
it 'imports push rules', :aggregate_failures do
allow_next_instance_of(BulkImports::Common::Extractors::NdjsonExtractor) do |extractor|
allow(extractor).to receive(:extract).and_return(BulkImports::Pipeline::ExtractedData.new(data: [[push_rule, 0]]))
end
expect { pipeline.run }.to change { PushRule.count }.from(0).to(1)
imported_push_rule = project.push_rule
push_rule.each_pair do |key, value|
expect(imported_push_rule.public_send(key)).to eq(value)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Projects::Stage do
let(:pipelines) do
[
[0, BulkImports::Projects::Pipelines::ProjectPipeline],
[1, BulkImports::Projects::Pipelines::RepositoryPipeline],
[2, BulkImports::Common::Pipelines::LabelsPipeline],
[2, BulkImports::Common::Pipelines::MilestonesPipeline],
[3, BulkImports::Projects::Pipelines::IssuesPipeline],
[4, BulkImports::Common::Pipelines::BoardsPipeline],
[4, BulkImports::Projects::Pipelines::MergeRequestsPipeline],
[4, BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline],
[4, BulkImports::Projects::Pipelines::PushRulePipeline],
[5, BulkImports::Common::Pipelines::WikiPipeline],
[5, BulkImports::Common::Pipelines::UploadsPipeline],
[6, BulkImports::Common::Pipelines::EntityFinisher]
]
end
subject do
bulk_import = build(:bulk_import)
described_class.new(bulk_import)
end
describe '#pipelines' do
it 'list all the pipelines with their stage number, ordered by stage' do
expect(subject.pipelines).to contain_exactly(*pipelines)
end
end
end
...@@ -13,7 +13,7 @@ module BulkImports ...@@ -13,7 +13,7 @@ module BulkImports
relation_hash, relation_index = data relation_hash, relation_index = data
relation_definition = import_export_config.top_relation_tree(relation) relation_definition = import_export_config.top_relation_tree(relation)
deep_transform_relation!(relation_hash, relation, relation_definition) do |key, hash| relation_object = deep_transform_relation!(relation_hash, relation, relation_definition) do |key, hash|
relation_factory.create( relation_factory.create(
relation_index: relation_index, relation_index: relation_index,
relation_sym: key.to_sym, relation_sym: key.to_sym,
...@@ -25,6 +25,9 @@ module BulkImports ...@@ -25,6 +25,9 @@ module BulkImports
excluded_keys: import_export_config.relation_excluded_keys(key) excluded_keys: import_export_config.relation_excluded_keys(key)
) )
end end
relation_object.assign_attributes(portable_class_sym => portable)
relation_object
end end
def load(_, object) def load(_, object)
...@@ -94,6 +97,10 @@ module BulkImports ...@@ -94,6 +97,10 @@ module BulkImports
def members_mapper def members_mapper
@members_mapper ||= BulkImports::UsersMapper.new(context: context) @members_mapper ||= BulkImports::UsersMapper.new(context: context)
end end
def portable_class_sym
portable.class.to_s.downcase.to_sym
end
end end
end end
end end
...@@ -111,6 +111,7 @@ RSpec.describe BulkImports::NdjsonPipeline do ...@@ -111,6 +111,7 @@ RSpec.describe BulkImports::NdjsonPipeline do
context = double(portable: group, current_user: user, import_export_config: config, bulk_import: import_double, entity: entity_double) context = double(portable: group, current_user: user, import_export_config: config, bulk_import: import_double, entity: entity_double)
allow(subject).to receive(:import_export_config).and_return(config) allow(subject).to receive(:import_export_config).and_return(config)
allow(subject).to receive(:context).and_return(context) allow(subject).to receive(:context).and_return(context)
relation_object = double
expect(Gitlab::ImportExport::Group::RelationFactory) expect(Gitlab::ImportExport::Group::RelationFactory)
.to receive(:create) .to receive(:create)
...@@ -124,6 +125,8 @@ RSpec.describe BulkImports::NdjsonPipeline do ...@@ -124,6 +125,8 @@ RSpec.describe BulkImports::NdjsonPipeline do
user: user, user: user,
excluded_keys: nil excluded_keys: nil
) )
.and_return(relation_object)
expect(relation_object).to receive(:assign_attributes).with(group: group)
subject.transform(context, data) subject.transform(context, data)
end end
......
...@@ -27,7 +27,8 @@ RSpec.describe BulkImports::Projects::Stage do ...@@ -27,7 +27,8 @@ RSpec.describe BulkImports::Projects::Stage do
describe '#pipelines' do describe '#pipelines' do
it 'list all the pipelines with their stage number, ordered by stage' do it 'list all the pipelines with their stage number, ordered by stage' do
expect(subject.pipelines).to eq(pipelines) expect(subject.pipelines & pipelines).to eq(pipelines)
expect(subject.pipelines.last.last).to eq(BulkImports::Common::Pipelines::EntityFinisher)
end end
end end
end end
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