Commit 7886d7db authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'georgekoltsov/project-migration-labels' into 'master'

Add Project Migration Labels

See merge request gitlab-org/gitlab!70810
parents e06b922e ab4c50ac
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
class BulkImports::Entity < ApplicationRecord class BulkImports::Entity < ApplicationRecord
self.table_name = 'bulk_import_entities' self.table_name = 'bulk_import_entities'
EXPORT_RELATIONS_URL = '/%{resource}/%{full_path}/export_relations'
belongs_to :bulk_import, optional: false belongs_to :bulk_import, optional: false
belongs_to :parent, class_name: 'BulkImports::Entity', optional: true belongs_to :parent, class_name: 'BulkImports::Entity', optional: true
...@@ -102,6 +104,14 @@ class BulkImports::Entity < ApplicationRecord ...@@ -102,6 +104,14 @@ class BulkImports::Entity < ApplicationRecord
end end
end end
def pluralized_name
source_type.gsub('_entity', '').pluralize
end
def export_relations_url_path
@export_relations_url_path ||= EXPORT_RELATIONS_URL % { resource: pluralized_name, full_path: encoded_source_full_path }
end
private private
def validate_parent_is_a_group def validate_parent_is_a_group
......
...@@ -41,7 +41,7 @@ module BulkImports ...@@ -41,7 +41,7 @@ module BulkImports
end end
def status_endpoint def status_endpoint
"/groups/#{entity.encoded_source_full_path}/export_relations/status" File.join(entity.export_relations_url_path, 'status')
end end
end end
end end
...@@ -26,7 +26,7 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -26,7 +26,7 @@ class BulkImportWorker # rubocop:disable Scalability/IdempotentWorker
created_entities.first(next_batch_size).each do |entity| created_entities.first(next_batch_size).each do |entity|
entity.create_pipeline_trackers! entity.create_pipeline_trackers!
BulkImports::ExportRequestWorker.perform_async(entity.id) if entity.group_entity? BulkImports::ExportRequestWorker.perform_async(entity.id)
BulkImports::EntityWorker.perform_async(entity.id) BulkImports::EntityWorker.perform_async(entity.id)
entity.start! entity.start!
......
...@@ -10,8 +10,6 @@ module BulkImports ...@@ -10,8 +10,6 @@ module BulkImports
worker_has_external_dependencies! worker_has_external_dependencies!
feature_category :importers feature_category :importers
GROUP_EXPORTED_URL_PATH = "/groups/%s/export_relations"
def perform(entity_id) def perform(entity_id)
entity = BulkImports::Entity.find(entity_id) entity = BulkImports::Entity.find(entity_id)
...@@ -21,8 +19,7 @@ module BulkImports ...@@ -21,8 +19,7 @@ module BulkImports
private private
def request_export(entity) def request_export(entity)
http_client(entity.bulk_import.configuration) http_client(entity.bulk_import.configuration).post(entity.export_relations_url_path)
.post(GROUP_EXPORTED_URL_PATH % entity.encoded_source_full_path)
end end
def http_client(configuration) def http_client(configuration)
......
...@@ -9,7 +9,7 @@ RSpec.describe BulkImports::Groups::Stage do ...@@ -9,7 +9,7 @@ RSpec.describe BulkImports::Groups::Stage do
[1, BulkImports::Groups::Pipelines::GroupAvatarPipeline], [1, BulkImports::Groups::Pipelines::GroupAvatarPipeline],
[1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline], [1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline],
[1, BulkImports::Groups::Pipelines::MembersPipeline], [1, BulkImports::Groups::Pipelines::MembersPipeline],
[1, BulkImports::Groups::Pipelines::LabelsPipeline], [1, BulkImports::Common::Pipelines::LabelsPipeline],
[1, BulkImports::Groups::Pipelines::MilestonesPipeline], [1, BulkImports::Groups::Pipelines::MilestonesPipeline],
[1, BulkImports::Groups::Pipelines::BadgesPipeline], [1, BulkImports::Groups::Pipelines::BadgesPipeline],
[1, BulkImports::Groups::Pipelines::IterationsPipeline], [1, BulkImports::Groups::Pipelines::IterationsPipeline],
......
...@@ -60,7 +60,7 @@ module BulkImports ...@@ -60,7 +60,7 @@ module BulkImports
def relative_resource_url(context) def relative_resource_url(context)
strong_memoize(:relative_resource_url) do strong_memoize(:relative_resource_url) do
resource = context.portable.class.name.downcase.pluralize resource = context.entity.pluralized_name
encoded_full_path = context.entity.encoded_source_full_path encoded_full_path = context.entity.encoded_source_full_path
EXPORT_DOWNLOAD_URL_PATH % { resource: resource, full_path: encoded_full_path, relation: relation } EXPORT_DOWNLOAD_URL_PATH % { resource: resource, full_path: encoded_full_path, relation: relation }
......
# frozen_string_literal: true # frozen_string_literal: true
module BulkImports module BulkImports
module Groups module Common
module Pipelines module Pipelines
class LabelsPipeline class LabelsPipeline
include NdjsonPipeline include NdjsonPipeline
......
...@@ -24,7 +24,7 @@ module BulkImports ...@@ -24,7 +24,7 @@ module BulkImports
stage: 1 stage: 1
}, },
labels: { labels: {
pipeline: BulkImports::Groups::Pipelines::LabelsPipeline, pipeline: BulkImports::Common::Pipelines::LabelsPipeline,
stage: 1 stage: 1
}, },
milestones: { milestones: {
......
...@@ -11,9 +11,13 @@ module BulkImports ...@@ -11,9 +11,13 @@ module BulkImports
pipeline: BulkImports::Projects::Pipelines::ProjectPipeline, pipeline: BulkImports::Projects::Pipelines::ProjectPipeline,
stage: 0 stage: 0
}, },
labels: {
pipeline: BulkImports::Common::Pipelines::LabelsPipeline,
stage: 1
},
finisher: { finisher: {
pipeline: BulkImports::Common::Pipelines::EntityFinisher, pipeline: BulkImports::Common::Pipelines::EntityFinisher,
stage: 1 stage: 2
} }
} }
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe BulkImports::Groups::Pipelines::LabelsPipeline do RSpec.describe BulkImports::Common::Pipelines::LabelsPipeline do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:bulk_import) { create(:bulk_import, user: user) } let_it_be(:bulk_import) { create(:bulk_import, user: user) }
......
...@@ -9,7 +9,7 @@ RSpec.describe BulkImports::Groups::Stage do ...@@ -9,7 +9,7 @@ RSpec.describe BulkImports::Groups::Stage do
[1, BulkImports::Groups::Pipelines::GroupAvatarPipeline], [1, BulkImports::Groups::Pipelines::GroupAvatarPipeline],
[1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline], [1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline],
[1, BulkImports::Groups::Pipelines::MembersPipeline], [1, BulkImports::Groups::Pipelines::MembersPipeline],
[1, BulkImports::Groups::Pipelines::LabelsPipeline], [1, BulkImports::Common::Pipelines::LabelsPipeline],
[1, BulkImports::Groups::Pipelines::MilestonesPipeline], [1, BulkImports::Groups::Pipelines::MilestonesPipeline],
[1, BulkImports::Groups::Pipelines::BadgesPipeline], [1, BulkImports::Groups::Pipelines::BadgesPipeline],
[2, BulkImports::Groups::Pipelines::BoardsPipeline] [2, BulkImports::Groups::Pipelines::BoardsPipeline]
......
...@@ -6,7 +6,8 @@ RSpec.describe BulkImports::Projects::Stage do ...@@ -6,7 +6,8 @@ RSpec.describe BulkImports::Projects::Stage do
let(:pipelines) do let(:pipelines) do
[ [
[0, BulkImports::Projects::Pipelines::ProjectPipeline], [0, BulkImports::Projects::Pipelines::ProjectPipeline],
[1, BulkImports::Common::Pipelines::EntityFinisher] [1, BulkImports::Common::Pipelines::LabelsPipeline],
[2, BulkImports::Common::Pipelines::EntityFinisher]
] ]
end end
......
...@@ -207,4 +207,40 @@ RSpec.describe BulkImports::Entity, type: :model do ...@@ -207,4 +207,40 @@ RSpec.describe BulkImports::Entity, type: :model do
expect(entity.pipeline_exists?('BulkImports::Groups::Pipelines::InexistentPipeline')).to eq(false) expect(entity.pipeline_exists?('BulkImports::Groups::Pipelines::InexistentPipeline')).to eq(false)
end end
end end
describe '#pluralized_name' do
context 'when entity is group' do
it 'returns groups' do
entity = build(:bulk_import_entity, :group_entity)
expect(entity.pluralized_name).to eq('groups')
end
end
context 'when entity is project' do
it 'returns projects' do
entity = build(:bulk_import_entity, :project_entity)
expect(entity.pluralized_name).to eq('projects')
end
end
end
describe '#export_relations_url_path' do
context 'when entity is group' do
it 'returns group export relations url' do
entity = build(:bulk_import_entity, :group_entity)
expect(entity.export_relations_url_path).to eq("/groups/#{entity.encoded_source_full_path}/export_relations")
end
end
context 'when entity is project' do
it 'returns project export relations url' do
entity = build(:bulk_import_entity, :project_entity)
expect(entity.export_relations_url_path).to eq("/projects/#{entity.encoded_source_full_path}/export_relations")
end
end
end
end end
...@@ -111,10 +111,10 @@ RSpec.describe BulkImportWorker do ...@@ -111,10 +111,10 @@ RSpec.describe BulkImportWorker do
end end
context 'when there are project entities to process' do context 'when there are project entities to process' do
it 'does not enqueue ExportRequestWorker' do it 'enqueues ExportRequestWorker' do
create(:bulk_import_entity, :created, :project_entity, bulk_import: bulk_import) create(:bulk_import_entity, :created, :project_entity, bulk_import: bulk_import)
expect(BulkImports::ExportRequestWorker).not_to receive(:perform_async) expect(BulkImports::ExportRequestWorker).to receive(:perform_async).once
subject.perform(bulk_import.id) subject.perform(bulk_import.id)
end end
......
...@@ -5,7 +5,6 @@ require 'spec_helper' ...@@ -5,7 +5,6 @@ require 'spec_helper'
RSpec.describe BulkImports::ExportRequestWorker do RSpec.describe BulkImports::ExportRequestWorker do
let_it_be(:bulk_import) { create(:bulk_import) } let_it_be(:bulk_import) { create(:bulk_import) }
let_it_be(:config) { create(:bulk_import_configuration, bulk_import: bulk_import) } let_it_be(:config) { create(:bulk_import_configuration, bulk_import: bulk_import) }
let_it_be(:entity) { create(:bulk_import_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) }
let_it_be(:version_url) { 'https://gitlab.example/api/v4/version' } let_it_be(:version_url) { 'https://gitlab.example/api/v4/version' }
let(:response_double) { double(code: 200, success?: true, parsed_response: {}) } let(:response_double) { double(code: 200, success?: true, parsed_response: {}) }
...@@ -20,10 +19,9 @@ RSpec.describe BulkImports::ExportRequestWorker do ...@@ -20,10 +19,9 @@ RSpec.describe BulkImports::ExportRequestWorker do
allow(Gitlab::HTTP).to receive(:post).and_return(response_double) allow(Gitlab::HTTP).to receive(:post).and_return(response_double)
end end
shared_examples 'requests relations export for api resource' do
include_examples 'an idempotent worker' do include_examples 'an idempotent worker' do
it 'requests relations export' do it 'requests relations export' do
expected = "/groups/foo%2Fbar/export_relations"
expect_next_instance_of(BulkImports::Clients::HTTP) do |client| expect_next_instance_of(BulkImports::Clients::HTTP) do |client|
expect(client).to receive(:post).with(expected).twice expect(client).to receive(:post).with(expected).twice
end end
...@@ -32,4 +30,19 @@ RSpec.describe BulkImports::ExportRequestWorker do ...@@ -32,4 +30,19 @@ RSpec.describe BulkImports::ExportRequestWorker do
end end
end end
end end
context 'when entity is group' do
let(:entity) { create(:bulk_import_entity, :group_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) }
let(:expected) { '/groups/foo%2Fbar/export_relations'}
include_examples 'requests relations export for api resource'
end
context 'when entity is project' do
let(:entity) { create(:bulk_import_entity, :project_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) }
let(:expected) { '/projects/foo%2Fbar/export_relations' }
include_examples 'requests relations export for api resource'
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