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