Commit e21c54e1 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'georgekoltsov/add-more-project-migration-relations' into 'master'

Add external pull requests to Project Migration

See merge request gitlab-org/gitlab!73470
parents a162dd21 32819109
# frozen_string_literal: true
module BulkImports
module Projects
module Pipelines
class ExternalPullRequestsPipeline
include NdjsonPipeline
relation_name 'external_pull_requests'
extractor ::BulkImports::Common::Extractors::NdjsonExtractor, relation: relation
end
end
end
end
......@@ -31,6 +31,10 @@ module BulkImports
pipeline: BulkImports::Projects::Pipelines::MergeRequestsPipeline,
stage: 4
},
external_pull_requests: {
pipeline: BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline,
stage: 4
},
uploads: {
pipeline: BulkImports::Common::Pipelines::UploadsPipeline,
stage: 5
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline do
let_it_be(:project) { create(:project) }
let_it_be(:bulk_import) { create(:bulk_import) }
let_it_be(:entity) { create(:bulk_import_entity, :project_entity, project: project, bulk_import: bulk_import) }
let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:attributes) { {} }
let(:external_pr) { project.external_pull_requests.last }
let(:external_pull_request) do
{
'pull_request_iid' => 4,
'source_branch' => 'feature',
'target_branch' => 'main',
'source_repository' => 'repository',
'target_repository' => 'repository',
'source_sha' => 'abc',
'target_sha' => 'xyz',
'status' => 'open',
'created_at' => '2019-12-24T14:04:50.053Z',
'updated_at' => '2019-12-24T14:05:18.138Z'
}.merge(attributes)
end
subject(:pipeline) { described_class.new(context) }
describe '#run' do
before do
allow_next_instance_of(BulkImports::Common::Extractors::NdjsonExtractor) do |extractor|
allow(extractor).to receive(:remove_tmp_dir)
allow(extractor).to receive(:extract).and_return(BulkImports::Pipeline::ExtractedData.new(data: [[external_pull_request, 0]]))
end
pipeline.run
end
it 'imports external pull request', :aggregate_failures do
expect(external_pr.pull_request_iid).to eq(external_pull_request['pull_request_iid'])
expect(external_pr.source_branch).to eq(external_pull_request['source_branch'])
expect(external_pr.target_branch).to eq(external_pull_request['target_branch'])
expect(external_pr.status).to eq(external_pull_request['status'])
expect(external_pr.created_at).to eq(external_pull_request['created_at'])
expect(external_pr.updated_at).to eq(external_pull_request['updated_at'])
end
context 'when status is closed' do
let(:attributes) { { 'status' => 'closed' } }
it 'imports closed external pull request' do
expect(external_pr.status).to eq(attributes['status'])
end
end
context 'when from fork' do
let(:attributes) { { 'source_repository' => 'source' } }
it 'does not create external pull request' do
expect(external_pr).to be_nil
end
end
end
end
......@@ -11,6 +11,7 @@ RSpec.describe BulkImports::Projects::Stage do
[3, BulkImports::Projects::Pipelines::IssuesPipeline],
[4, BulkImports::Common::Pipelines::BoardsPipeline],
[4, BulkImports::Projects::Pipelines::MergeRequestsPipeline],
[4, BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline],
[5, BulkImports::Common::Pipelines::UploadsPipeline],
[6, BulkImports::Common::Pipelines::EntityFinisher]
]
......
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