Commit a09aa50a authored by Stan Hu's avatar Stan Hu

Merge branch 'georgekoltsov/better-way-to-load-ee-pipelines' into 'master'

Add better way to load EE specific pipelines for Bulk Imports

See merge request gitlab-org/gitlab!50991
parents 7ccd6cea a9a75cc5
# frozen_string_literal: true
module BulkImports
module EE
module EE
module BulkImports
module Groups
module Graphql
module GetEpicsQuery
......
# frozen_string_literal: true
module BulkImports
module EE
module EE
module BulkImports
module Groups
module Loaders
class EpicsLoader
......
# frozen_string_literal: true
module BulkImports
module EE
module EE
module BulkImports
module Groups
module Pipelines
class EpicsPipeline
include ::BulkImports::Pipeline
extractor ::BulkImports::Common::Extractors::GraphqlExtractor,
query: BulkImports::EE::Groups::Graphql::GetEpicsQuery
query: EE::BulkImports::Groups::Graphql::GetEpicsQuery
transformer ::BulkImports::Common::Transformers::HashKeyDigger,
key_path: %w[data group epics]
transformer ::BulkImports::Common::Transformers::HashKeyDigger, key_path: %w[data group epics]
transformer ::BulkImports::Common::Transformers::UnderscorifyKeysTransformer
transformer ::BulkImports::Common::Transformers::ProhibitedAttributesTransformer
loader BulkImports::EE::Groups::Loaders::EpicsLoader
loader EE::BulkImports::Groups::Loaders::EpicsLoader
after_run do |context|
if context.entity.has_next_page?(:epics)
......
# frozen_string_literal: true
module EE
module BulkImports
module Importers
module GroupImporter
extend ::Gitlab::Utils::Override
private
override :pipelines
def pipelines
super << EE::BulkImports::Groups::Pipelines::EpicsPipeline
end
end
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe BulkImports::EE::Groups::Loaders::EpicsLoader do
RSpec.describe EE::BulkImports::Groups::Loaders::EpicsLoader do
describe '#load' do
let(:user) { create(:user) }
let(:group) { create(:group) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe BulkImports::EE::Groups::Pipelines::EpicsPipeline do
RSpec.describe EE::BulkImports::Groups::Pipelines::EpicsPipeline do
describe '#run' do
let(:user) { create(:user) }
let(:group) { create(:group) }
......@@ -51,7 +51,7 @@ RSpec.describe BulkImports::EE::Groups::Pipelines::EpicsPipeline do
{
klass: BulkImports::Common::Extractors::GraphqlExtractor,
options: {
query: BulkImports::EE::Groups::Graphql::GetEpicsQuery
query: EE::BulkImports::Groups::Graphql::GetEpicsQuery
}
}
)
......@@ -68,7 +68,7 @@ RSpec.describe BulkImports::EE::Groups::Pipelines::EpicsPipeline do
it 'has loaders' do
expect(described_class.loaders).to contain_exactly({
klass: BulkImports::EE::Groups::Loaders::EpicsLoader, options: nil
klass: EE::BulkImports::Groups::Loaders::EpicsLoader, options: nil
})
end
end
......
......@@ -23,9 +23,9 @@ RSpec.describe BulkImports::Importers::GroupImporter do
describe '#execute' do
it "starts the entity and run its pipelines" do
expect(bulk_import_entity).to receive(:start).and_call_original
expect(bulk_import_entity).to receive(:start!).and_call_original
expect_to_run_pipeline BulkImports::Groups::Pipelines::GroupPipeline, context: context
expect_to_run_pipeline BulkImports::EE::Groups::Pipelines::EpicsPipeline, context: context
expect_to_run_pipeline EE::BulkImports::Groups::Pipelines::EpicsPipeline, context: context
expect_to_run_pipeline BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline, context: context
subject.execute
......
......@@ -18,9 +18,7 @@ module BulkImports
configuration: configuration
)
BulkImports::Groups::Pipelines::GroupPipeline.new.run(context)
'BulkImports::EE::Groups::Pipelines::EpicsPipeline'.constantize.new.run(context) if Gitlab.ee?
BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline.new.run(context)
pipelines.each { |pipeline| pipeline.new.run(context) }
entity.finish!
end
......@@ -28,6 +26,15 @@ module BulkImports
private
attr_reader :entity
def pipelines
[
BulkImports::Groups::Pipelines::GroupPipeline,
BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline
]
end
end
end
end
BulkImports::Importers::GroupImporter.prepend_if_ee('EE::BulkImports::Importers::GroupImporter')
......@@ -18,14 +18,14 @@ RSpec.describe BulkImports::Importers::GroupImporter do
subject { described_class.new(bulk_import_entity) }
before do
allow(Gitlab).to receive(:ee?).and_return(false)
allow(BulkImports::Pipeline::Context).to receive(:new).and_return(context)
end
describe '#execute' do
it 'starts the entity and run its pipelines' do
expect(bulk_import_entity).to receive(:start).and_call_original
expect(bulk_import_entity).to receive(:start!).and_call_original
expect_to_run_pipeline BulkImports::Groups::Pipelines::GroupPipeline, context: context
expect_to_run_pipeline('EE::BulkImports::Groups::Pipelines::EpicsPipeline'.constantize, context: context) if Gitlab.ee?
expect_to_run_pipeline BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline, context: context
subject.execute
......
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