Commit 0ad79b06 authored by João Alexandre Cunha's avatar João Alexandre Cunha Committed by Vasilii Iakliushin

Resolve "GitLab Migration - Migrate Milestones and Events"

parent f7aae684
...@@ -10,7 +10,7 @@ RSpec.describe BulkImports::Groups::Stage do ...@@ -10,7 +10,7 @@ RSpec.describe BulkImports::Groups::Stage do
[1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline], [1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline],
[1, BulkImports::Groups::Pipelines::MembersPipeline], [1, BulkImports::Groups::Pipelines::MembersPipeline],
[1, BulkImports::Common::Pipelines::LabelsPipeline], [1, BulkImports::Common::Pipelines::LabelsPipeline],
[1, BulkImports::Groups::Pipelines::MilestonesPipeline], [1, BulkImports::Common::Pipelines::MilestonesPipeline],
[1, BulkImports::Groups::Pipelines::BadgesPipeline], [1, BulkImports::Groups::Pipelines::BadgesPipeline],
[1, BulkImports::Groups::Pipelines::IterationsPipeline], [1, BulkImports::Groups::Pipelines::IterationsPipeline],
[1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline], [1, BulkImports::Groups::Pipelines::ProjectEntitiesPipeline],
......
# frozen_string_literal: true # frozen_string_literal: true
module BulkImports module BulkImports
module Groups module Common
module Pipelines module Pipelines
class MilestonesPipeline class MilestonesPipeline
include NdjsonPipeline include NdjsonPipeline
......
...@@ -28,7 +28,7 @@ module BulkImports ...@@ -28,7 +28,7 @@ module BulkImports
stage: 1 stage: 1
}, },
milestones: { milestones: {
pipeline: BulkImports::Groups::Pipelines::MilestonesPipeline, pipeline: BulkImports::Common::Pipelines::MilestonesPipeline,
stage: 1 stage: 1
}, },
badges: { badges: {
......
...@@ -19,6 +19,10 @@ module BulkImports ...@@ -19,6 +19,10 @@ module BulkImports
pipeline: BulkImports::Common::Pipelines::LabelsPipeline, pipeline: BulkImports::Common::Pipelines::LabelsPipeline,
stage: 2 stage: 2
}, },
milestones: {
pipeline: BulkImports::Common::Pipelines::MilestonesPipeline,
stage: 2
},
issues: { issues: {
pipeline: BulkImports::Projects::Pipelines::IssuesPipeline, pipeline: BulkImports::Projects::Pipelines::IssuesPipeline,
stage: 3 stage: 3
......
{"id":7642,"title":"v4.0","project_id":null,"description":"Et laudantium enim omnis ea reprehenderit iure.","due_date":null,"created_at":"2019-11-20T17:02:14.336Z","updated_at":"2019-11-20T17:02:14.336Z","state":"closed","iid":5,"start_date":null,"group_id":4351}
{"id":7641,"title":"v3.0","project_id":null,"description":"Et repellat culpa nemo consequatur ut reprehenderit.","due_date":null,"created_at":"2019-11-20T17:02:14.323Z","updated_at":"2019-11-20T17:02:14.323Z","state":"active","iid":4,"start_date":null,"group_id":4351}
{"id":7640,"title":"v2.0","project_id":null,"description":"Velit cupiditate est neque voluptates iste rem sunt.","due_date":null,"created_at":"2019-11-20T17:02:14.309Z","updated_at":"2019-11-20T17:02:14.309Z","state":"active","iid":3,"start_date":null,"group_id":4351}
{"id":7639,"title":"v1.0","project_id":null,"description":"Amet velit repellat ut rerum aut cum.","due_date":null,"created_at":"2019-11-20T17:02:14.296Z","updated_at":"2019-11-20T17:02:14.296Z","state":"active","iid":2,"start_date":null,"group_id":4351}
{"id":7638,"title":"v0.0","project_id":null,"description":"Ea quia asperiores ut modi dolorem sunt non numquam.","due_date":null,"created_at":"2019-11-20T17:02:14.282Z","updated_at":"2019-11-20T17:02:14.282Z","state":"active","iid":1,"start_date":null,"group_id":4351}
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Common::Pipelines::MilestonesPipeline do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:bulk_import) { create(:bulk_import, user: user) }
let(:tracker) { create(:bulk_import_tracker, entity: entity) }
let(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:source_project_id) { nil } # if set, then exported_milestone is a project milestone
let(:source_group_id) { nil } # if set, then exported_milestone is a group milestone
let(:exported_milestone_for_project) do
exported_milestone_for_group.merge(
'events' => [{
'project_id' => source_project_id,
'author_id' => 9,
'created_at' => "2021-08-12T19:12:49.810Z",
'updated_at' => "2021-08-12T19:12:49.810Z",
'target_type' => "Milestone",
'group_id' => source_group_id,
'fingerprint' => 'f270eb9b27d0',
'id' => 66,
'action' => "created"
}]
)
end
let(:exported_milestone_for_group) do
{
'id' => 1,
'title' => "v1.0",
'project_id' => source_project_id,
'description' => "Amet velit repellat ut rerum aut cum.",
'due_date' => "2019-11-22",
'created_at' => "2019-11-20T17:02:14.296Z",
'updated_at' => "2019-11-20T17:02:14.296Z",
'state' => "active",
'iid' => 2,
'start_date' => "2019-11-21",
'group_id' => source_group_id
}
end
before do
group.add_owner(user)
allow_next_instance_of(BulkImports::Common::Extractors::NdjsonExtractor) do |extractor|
allow(extractor).to receive(:extract).and_return(BulkImports::Pipeline::ExtractedData.new(data: exported_milestones))
end
end
subject { described_class.new(context) }
shared_examples 'bulk_imports milestones pipeline' do
let(:tested_entity) { nil }
describe '#run' do
it 'imports milestones into destination' do
expect { subject.run }.to change(Milestone, :count).by(1)
imported_milestone = tested_entity.milestones.first
expect(imported_milestone.title).to eq("v1.0")
expect(imported_milestone.description).to eq("Amet velit repellat ut rerum aut cum.")
expect(imported_milestone.due_date.to_s).to eq("2019-11-22")
expect(imported_milestone.created_at).to eq("2019-11-20T17:02:14.296Z")
expect(imported_milestone.updated_at).to eq("2019-11-20T17:02:14.296Z")
expect(imported_milestone.start_date.to_s).to eq("2019-11-21")
end
end
describe '#load' do
context 'when milestone is not persisted' do
it 'saves the milestone' do
milestone = build(:milestone, group: group)
expect(milestone).to receive(:save!)
subject.load(context, milestone)
end
end
context 'when milestone is persisted' do
it 'does not save milestone' do
milestone = create(:milestone, group: group)
expect(milestone).not_to receive(:save!)
subject.load(context, milestone)
end
end
context 'when milestone is missing' do
it 'returns' do
expect(subject.load(context, nil)).to be_nil
end
end
end
end
context 'group milestone' do
let(:exported_milestones) { [[exported_milestone_for_group, 0]] }
let(:entity) do
create(
:bulk_import_entity,
group: group,
bulk_import: bulk_import,
source_full_path: 'source/full/path',
destination_name: 'My Destination Group',
destination_namespace: group.full_path
)
end
it_behaves_like 'bulk_imports milestones pipeline' do
let(:tested_entity) { group }
let(:source_group_id) { 1 }
end
end
context 'project milestone' do
let(:project) { create(:project, group: group) }
let(:exported_milestones) { [[exported_milestone_for_project, 0]] }
let(:entity) do
create(
:bulk_import_entity,
:project_entity,
project: project,
bulk_import: bulk_import,
source_full_path: 'source/full/path',
destination_name: 'My Destination Project',
destination_namespace: group.full_path
)
end
it_behaves_like 'bulk_imports milestones pipeline' do
let(:tested_entity) { project }
let(:source_project_id) { 1 }
it 'imports events' do
subject.run
imported_event = tested_entity.milestones.first.events.first
expect(imported_event.created_at).to eq("2021-08-12T19:12:49.810Z")
expect(imported_event.updated_at).to eq("2021-08-12T19:12:49.810Z")
expect(imported_event.target_type).to eq("Milestone")
expect(imported_event.fingerprint).to eq("f270eb9b27d0")
expect(imported_event.action).to eq("created")
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Groups::Pipelines::MilestonesPipeline do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:bulk_import) { create(:bulk_import, user: user) }
let_it_be(:filepath) { 'spec/fixtures/bulk_imports/gz/milestones.ndjson.gz' }
let_it_be(:entity) do
create(
:bulk_import_entity,
group: group,
bulk_import: bulk_import,
source_full_path: 'source/full/path',
destination_name: 'My Destination Group',
destination_namespace: group.full_path
)
end
let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }
let(:tmpdir) { Dir.mktmpdir }
before do
FileUtils.copy_file(filepath, File.join(tmpdir, 'milestones.ndjson.gz'))
group.add_owner(user)
end
subject { described_class.new(context) }
describe '#run' do
it 'imports group milestones into destination group and removes tmpdir' do
allow(Dir).to receive(:mktmpdir).and_return(tmpdir)
allow_next_instance_of(BulkImports::FileDownloadService) do |service|
allow(service).to receive(:execute)
end
expect { subject.run }.to change(Milestone, :count).by(5)
expect(group.milestones.pluck(:title)).to contain_exactly('v4.0', 'v3.0', 'v2.0', 'v1.0', 'v0.0')
expect(File.directory?(tmpdir)).to eq(false)
end
end
describe '#load' do
context 'when milestone is not persisted' do
it 'saves the milestone' do
milestone = build(:milestone, group: group)
expect(milestone).to receive(:save!)
subject.load(context, milestone)
end
end
context 'when milestone is persisted' do
it 'does not save milestone' do
milestone = create(:milestone, group: group)
expect(milestone).not_to receive(:save!)
subject.load(context, milestone)
end
end
context 'when milestone is missing' do
it 'returns' do
expect(subject.load(context, nil)).to be_nil
end
end
end
end
...@@ -12,7 +12,7 @@ RSpec.describe BulkImports::Groups::Stage do ...@@ -12,7 +12,7 @@ RSpec.describe BulkImports::Groups::Stage do
[1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline], [1, BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline],
[1, BulkImports::Groups::Pipelines::MembersPipeline], [1, BulkImports::Groups::Pipelines::MembersPipeline],
[1, BulkImports::Common::Pipelines::LabelsPipeline], [1, BulkImports::Common::Pipelines::LabelsPipeline],
[1, BulkImports::Groups::Pipelines::MilestonesPipeline], [1, BulkImports::Common::Pipelines::MilestonesPipeline],
[1, BulkImports::Groups::Pipelines::BadgesPipeline], [1, BulkImports::Groups::Pipelines::BadgesPipeline],
[2, BulkImports::Common::Pipelines::BoardsPipeline] [2, BulkImports::Common::Pipelines::BoardsPipeline]
] ]
......
...@@ -8,6 +8,7 @@ RSpec.describe BulkImports::Projects::Stage do ...@@ -8,6 +8,7 @@ RSpec.describe BulkImports::Projects::Stage do
[0, BulkImports::Projects::Pipelines::ProjectPipeline], [0, BulkImports::Projects::Pipelines::ProjectPipeline],
[1, BulkImports::Projects::Pipelines::RepositoryPipeline], [1, BulkImports::Projects::Pipelines::RepositoryPipeline],
[2, BulkImports::Common::Pipelines::LabelsPipeline], [2, BulkImports::Common::Pipelines::LabelsPipeline],
[2, BulkImports::Common::Pipelines::MilestonesPipeline],
[3, BulkImports::Projects::Pipelines::IssuesPipeline], [3, BulkImports::Projects::Pipelines::IssuesPipeline],
[4, BulkImports::Common::Pipelines::BoardsPipeline], [4, BulkImports::Common::Pipelines::BoardsPipeline],
[4, BulkImports::Projects::Pipelines::MergeRequestsPipeline], [4, BulkImports::Projects::Pipelines::MergeRequestsPipeline],
......
...@@ -123,6 +123,24 @@ RSpec.describe Gitlab::ImportExport::Project::ObjectBuilder do ...@@ -123,6 +123,24 @@ RSpec.describe Gitlab::ImportExport::Project::ObjectBuilder do
expect(milestone.persisted?).to be true expect(milestone.persisted?).to be true
end end
context 'with clashing iid' do
it 'creates milestone and claims iid for the new milestone' do
clashing_iid = 1
create(:milestone, iid: clashing_iid, project: project)
milestone = described_class.build(Milestone,
'iid' => clashing_iid,
'title' => 'milestone',
'project' => project,
'group' => nil,
'group_id' => nil)
expect(milestone.persisted?).to be true
expect(Milestone.count).to eq(2)
expect(milestone.iid).to eq(clashing_iid)
end
end
end end
context 'merge_request' do context 'merge_request' do
......
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