Commit 7db1a691 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch '339400-gitlab-migration-wiki-repositories-with-projects' into 'master'

Resolve "GitLab Migration - Wiki repositories with Projects"

See merge request gitlab-org/gitlab!72146
parents a90adab3 9acfe49a
...@@ -18,6 +18,10 @@ module EE ...@@ -18,6 +18,10 @@ module EE
pipeline: ::BulkImports::Groups::Pipelines::EpicsPipeline, pipeline: ::BulkImports::Groups::Pipelines::EpicsPipeline,
stage: 2 stage: 2
}, },
wiki: {
pipeline: ::BulkImports::Common::Pipelines::WikiPipeline,
stage: 2
},
# Override the CE stage value for the EntityFinisher Pipeline # Override the CE stage value for the EntityFinisher Pipeline
finisher: { finisher: {
stage: 4 stage: 4
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Common::Pipelines::WikiPipeline do
describe '#run' do
let_it_be(:user) { create(:user) }
let_it_be(:parent) { create(:group) }
let_it_be(:bulk_import) { create(:bulk_import, user: user) }
let_it_be(:entity) do
create(
:bulk_import_entity,
:group_entity,
bulk_import: bulk_import,
source_full_path: 'source/full/path',
destination_name: 'My Destination Wiki',
destination_namespace: parent.full_path,
group: parent
)
end
it_behaves_like 'wiki pipeline imports a wiki for an entity'
end
end
...@@ -16,6 +16,7 @@ RSpec.describe BulkImports::Groups::Stage do ...@@ -16,6 +16,7 @@ RSpec.describe BulkImports::Groups::Stage do
[1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline], [1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline],
[2, BulkImports::Common::Pipelines::BoardsPipeline], [2, BulkImports::Common::Pipelines::BoardsPipeline],
[2, BulkImports::Groups::Pipelines::EpicsPipeline], [2, BulkImports::Groups::Pipelines::EpicsPipeline],
[2, BulkImports::Common::Pipelines::WikiPipeline],
[4, BulkImports::Common::Pipelines::EntityFinisher] [4, BulkImports::Common::Pipelines::EntityFinisher]
] ]
end end
......
# frozen_string_literal: true
module BulkImports
module Common
module Pipelines
class WikiPipeline
include Pipeline
def extract(*)
BulkImports::Pipeline::ExtractedData.new(data: { url: url_from_parent_path(context.entity.source_full_path) })
end
def transform(_, data)
data&.slice(:url)
end
def load(context, data)
return unless context.portable.wiki
url = data[:url].sub("://", "://oauth2:#{context.configuration.access_token}@")
Gitlab::UrlBlocker.validate!(url, allow_local_network: allow_local_requests?, allow_localhost: allow_local_requests?)
context.portable.wiki.ensure_repository
context.portable.wiki.repository.fetch_as_mirror(url)
end
private
def url_from_parent_path(parent_path)
wiki_path = parent_path + ".wiki.git"
root = context.configuration.url
Gitlab::Utils.append_path(root, wiki_path)
end
def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end
end
end
end
end
...@@ -35,6 +35,10 @@ module BulkImports ...@@ -35,6 +35,10 @@ module BulkImports
pipeline: BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline, pipeline: BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline,
stage: 4 stage: 4
}, },
wiki: {
pipeline: BulkImports::Common::Pipelines::WikiPipeline,
stage: 5
},
uploads: { uploads: {
pipeline: BulkImports::Common::Pipelines::UploadsPipeline, pipeline: BulkImports::Common::Pipelines::UploadsPipeline,
stage: 5 stage: 5
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Common::Pipelines::WikiPipeline do
describe '#run' do
let_it_be(:user) { create(:user) }
let_it_be(:bulk_import) { create(:bulk_import, user: user) }
let_it_be(:parent) { create(:project) }
let_it_be(:entity) do
create(
:bulk_import_entity,
:project_entity,
bulk_import: bulk_import,
source_full_path: 'source/full/path',
destination_name: 'My Destination Wiki',
destination_namespace: parent.full_path,
project: parent
)
end
it_behaves_like 'wiki pipeline imports a wiki for an entity'
end
end
...@@ -12,6 +12,7 @@ RSpec.describe BulkImports::Projects::Stage do ...@@ -12,6 +12,7 @@ RSpec.describe BulkImports::Projects::Stage do
[4, BulkImports::Common::Pipelines::BoardsPipeline], [4, BulkImports::Common::Pipelines::BoardsPipeline],
[4, BulkImports::Projects::Pipelines::MergeRequestsPipeline], [4, BulkImports::Projects::Pipelines::MergeRequestsPipeline],
[4, BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline], [4, BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline],
[5, BulkImports::Common::Pipelines::WikiPipeline],
[5, BulkImports::Common::Pipelines::UploadsPipeline], [5, BulkImports::Common::Pipelines::UploadsPipeline],
[6, BulkImports::Common::Pipelines::EntityFinisher] [6, BulkImports::Common::Pipelines::EntityFinisher]
] ]
......
# frozen_string_literal: true
RSpec.shared_examples 'wiki pipeline imports a wiki for an entity' do
describe '#run' do
let_it_be(:bulk_import_configuration) { create(:bulk_import_configuration, bulk_import: bulk_import) }
let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:extracted_data) { BulkImports::Pipeline::ExtractedData.new(data: {}) }
context 'successfully imports wiki for an entity' do
subject { described_class.new(context) }
before do
allow_next_instance_of(BulkImports::Common::Extractors::GraphqlExtractor) do |extractor|
allow(extractor).to receive(:extract).and_return(extracted_data)
end
end
it 'imports new wiki into destination project' do
expect_next_instance_of(Gitlab::GitalyClient::RepositoryService) do |repository_service|
url = "https://oauth2:token@gitlab.example/#{entity.source_full_path}.wiki.git"
expect(repository_service).to receive(:fetch_remote).with(url, any_args).and_return 0
end
subject.run
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