Commit 1157a81f authored by George Koltsov's avatar George Koltsov

Update bulk_import_projects feature flag to enable on per actor basis

  - It should be possible to enable bulk_import_projects feature flag
    on per actor basis
parent 2fca1510
...@@ -92,9 +92,9 @@ class BulkImports::Entity < ApplicationRecord ...@@ -92,9 +92,9 @@ class BulkImports::Entity < ApplicationRecord
def pipelines def pipelines
@pipelines ||= case source_type @pipelines ||= case source_type
when 'group_entity' when 'group_entity'
BulkImports::Groups::Stage.new(bulk_import).pipelines BulkImports::Groups::Stage.new(self).pipelines
when 'project_entity' when 'project_entity'
BulkImports::Projects::Stage.new(bulk_import).pipelines BulkImports::Projects::Stage.new(self).pipelines
end end
end end
......
...@@ -22,9 +22,9 @@ RSpec.describe BulkImports::Groups::Stage do ...@@ -22,9 +22,9 @@ RSpec.describe BulkImports::Groups::Stage do
end end
subject do subject do
bulk_import = build(:bulk_import) entity = build(:bulk_import_entity)
described_class.new(bulk_import) described_class.new(entity)
end end
describe '#each' do describe '#each' do
......
...@@ -34,9 +34,9 @@ RSpec.describe BulkImports::Projects::Stage do ...@@ -34,9 +34,9 @@ RSpec.describe BulkImports::Projects::Stage do
end end
subject do subject do
bulk_import = build(:bulk_import) entity = build(:bulk_import_entity)
described_class.new(bulk_import) described_class.new(entity)
end end
describe '#pipelines' do describe '#pipelines' do
......
...@@ -47,7 +47,7 @@ module BulkImports ...@@ -47,7 +47,7 @@ module BulkImports
end end
def project_entities_pipeline def project_entities_pipeline
if project_pipeline_available? && ::Feature.enabled?(:bulk_import_projects, default_enabled: :yaml) if project_pipeline_available? && feature_flag_enabled?
{ {
project_entities: { project_entities: {
pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline, pipeline: BulkImports::Groups::Pipelines::ProjectEntitiesPipeline,
...@@ -62,6 +62,18 @@ module BulkImports ...@@ -62,6 +62,18 @@ module BulkImports
def project_pipeline_available? def project_pipeline_available?
@bulk_import.source_version_info >= BulkImport.min_gl_version_for_project_migration @bulk_import.source_version_info >= BulkImport.min_gl_version_for_project_migration
end end
def feature_flag_enabled?
destination_namespace = @bulk_import_entity.destination_namespace
if destination_namespace.present?
root_ancestor = Namespace.find_by_full_path(destination_namespace)&.root_ancestor
::Feature.enabled?(:bulk_import_projects, root_ancestor, default_enabled: :yaml)
else
::Feature.enabled?(:bulk_import_projects, default_enabled: :yaml)
end
end
end end
end end
end end
......
...@@ -2,10 +2,13 @@ ...@@ -2,10 +2,13 @@
module BulkImports module BulkImports
class Stage class Stage
def initialize(bulk_import) def initialize(bulk_import_entity)
raise(ArgumentError, 'Expected an argument of type ::BulkImport') unless bulk_import.is_a?(::BulkImport) unless bulk_import_entity.is_a?(::BulkImports::Entity)
raise(ArgumentError, 'Expected an argument of type ::BulkImports::Entity')
end
@bulk_import = bulk_import @bulk_import_entity = bulk_import_entity
@bulk_import = bulk_import_entity.bulk_import
end end
def pipelines def pipelines
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe BulkImports::Groups::Stage do RSpec.describe BulkImports::Groups::Stage do
let(:ancestor) { create(:group) }
let(:group) { create(:group, parent: ancestor) }
let(:bulk_import) { build(:bulk_import) } 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 let(:pipelines) do
[ [
...@@ -19,26 +22,46 @@ RSpec.describe BulkImports::Groups::Stage do ...@@ -19,26 +22,46 @@ RSpec.describe BulkImports::Groups::Stage do
end end
it 'raises error when initialized without a BulkImport' do it 'raises error when initialized without a BulkImport' do
expect { described_class.new({}) }.to raise_error(ArgumentError, 'Expected an argument of type ::BulkImport') expect { described_class.new({}) }.to raise_error(ArgumentError, 'Expected an argument of type ::BulkImports::Entity')
end end
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(described_class.new(bulk_import).pipelines & pipelines).to contain_exactly(*pipelines) expect(described_class.new(entity).pipelines & pipelines).to contain_exactly(*pipelines)
expect(described_class.new(bulk_import).pipelines.last.last).to eq(BulkImports::Common::Pipelines::EntityFinisher) expect(described_class.new(entity).pipelines.last.last).to eq(BulkImports::Common::Pipelines::EntityFinisher)
end end
context 'when bulk_import_projects feature flag is enabled' do
it 'includes project entities pipeline' do it 'includes project entities pipeline' do
stub_feature_flags(bulk_import_projects: true) stub_feature_flags(bulk_import_projects: true)
expect(described_class.new(bulk_import).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline]) expect(described_class.new(entity).pipelines).to include([1, 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])
end
end
context 'when destination namespace is not present' do
it 'includes project entities pipeline' do
stub_feature_flags(bulk_import_projects: true)
entity = create(:bulk_import_entity, destination_namespace: '')
expect(described_class.new(entity).pipelines).to include([1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline])
end
end
end end
context 'when bulk_import_projects feature flag is disabled' do context 'when bulk_import_projects feature flag is disabled' do
it 'does not include project entities pipeline' do it 'does not include project entities pipeline' do
stub_feature_flags(bulk_import_projects: false) stub_feature_flags(bulk_import_projects: false)
expect(described_class.new(bulk_import).pipelines.flatten).not_to include(BulkImports::Groups::Pipelines::ProjectEntitiesPipeline) expect(described_class.new(entity).pipelines.flatten).not_to include(BulkImports::Groups::Pipelines::ProjectEntitiesPipeline)
end end
end end
end end
......
...@@ -34,9 +34,9 @@ RSpec.describe BulkImports::Projects::Stage do ...@@ -34,9 +34,9 @@ RSpec.describe BulkImports::Projects::Stage do
end end
subject do subject do
bulk_import = build(:bulk_import) entity = build(:bulk_import_entity, :project_entity)
described_class.new(bulk_import) described_class.new(entity)
end end
describe '#pipelines' do describe '#pipelines' do
......
...@@ -179,7 +179,7 @@ RSpec.describe BulkImports::Entity, type: :model do ...@@ -179,7 +179,7 @@ RSpec.describe BulkImports::Entity, type: :model do
entity = create(:bulk_import_entity, :group_entity) entity = create(:bulk_import_entity, :group_entity)
entity.create_pipeline_trackers! entity.create_pipeline_trackers!
expect(entity.trackers.count).to eq(BulkImports::Groups::Stage.new(entity.bulk_import).pipelines.count) 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) expect(entity.trackers.map(&:pipeline_name)).to include(BulkImports::Groups::Pipelines::GroupPipeline.to_s)
end end
end end
...@@ -189,7 +189,7 @@ RSpec.describe BulkImports::Entity, type: :model do ...@@ -189,7 +189,7 @@ RSpec.describe BulkImports::Entity, type: :model do
entity = create(:bulk_import_entity, :project_entity) entity = create(:bulk_import_entity, :project_entity)
entity.create_pipeline_trackers! entity.create_pipeline_trackers!
expect(entity.trackers.count).to eq(BulkImports::Projects::Stage.new(entity.bulk_import).pipelines.count) 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.trackers.map(&:pipeline_name)).to include(BulkImports::Projects::Pipelines::ProjectPipeline.to_s)
end end
end end
......
...@@ -66,8 +66,8 @@ RSpec.describe BulkImports::Tracker, type: :model do ...@@ -66,8 +66,8 @@ RSpec.describe BulkImports::Tracker, type: :model do
describe '#pipeline_class' do describe '#pipeline_class' do
it 'returns the pipeline class' do it 'returns the pipeline class' do
bulk_import = create(:bulk_import) entity = create(:bulk_import_entity)
pipeline_class = BulkImports::Groups::Stage.new(bulk_import).pipelines.first[1] pipeline_class = BulkImports::Groups::Stage.new(entity).pipelines.first[1]
tracker = create(:bulk_import_tracker, pipeline_name: pipeline_class) tracker = create(:bulk_import_tracker, pipeline_name: pipeline_class)
expect(tracker.pipeline_class).to eq(pipeline_class) expect(tracker.pipeline_class).to eq(pipeline_class)
......
...@@ -73,7 +73,7 @@ RSpec.describe BulkImportWorker do ...@@ -73,7 +73,7 @@ RSpec.describe BulkImportWorker do
expect { subject.perform(bulk_import.id) } expect { subject.perform(bulk_import.id) }
.to change(BulkImports::Tracker, :count) .to change(BulkImports::Tracker, :count)
.by(BulkImports::Groups::Stage.new(bulk_import).pipelines.size * 2) .by(BulkImports::Groups::Stage.new(entity_1).pipelines.size * 2)
expect(entity_1.trackers).not_to be_empty expect(entity_1.trackers).not_to be_empty
expect(entity_2.trackers).not_to be_empty expect(entity_2.trackers).not_to be_empty
......
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