Commit 05ddb259 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Assign stage and pipeline to a status when importing

parent 099a59e8
......@@ -79,7 +79,7 @@ module Ci
before_save :ensure_token
before_destroy { unscoped_project }
after_create do |build|
after_create unless: :importing? do |build|
run_after_commit { BuildHooksWorker.perform_async(build.id) }
end
......
......@@ -49,8 +49,8 @@ project_tree:
- :author
- events:
- :push_event_payload
- :stages
- :statuses
- stages:
- :statuses
- :auto_devops
- :triggers
- :pipeline_schedules
......
......@@ -62,6 +62,7 @@ module Gitlab
when :notes then setup_note
when :project_label, :project_labels then setup_label
when :milestone, :milestones then setup_milestone
when 'Ci::Pipeline' then setup_pipeline
else
@relation_hash['project_id'] = @project.id
end
......@@ -112,9 +113,7 @@ module Gitlab
@relation_hash.delete('trace') # old export files have trace
@relation_hash.delete('token')
imported_object do |object|
object.commit_id = nil
end
imported_object
elsif @relation_name == :merge_requests
MergeRequestParser.new(@project, @relation_hash.delete('diff_head_sha'), imported_object, @relation_hash).parse!
else
......@@ -182,8 +181,9 @@ module Gitlab
end
def imported_object
yield(existing_or_new_object) if block_given?
existing_or_new_object.importing = true if existing_or_new_object.respond_to?(:importing)
if existing_or_new_object.respond_to?(:importing)
existing_or_new_object.importing = true
end
existing_or_new_object
rescue ActiveRecord::RecordNotUnique
......@@ -211,6 +211,14 @@ module Gitlab
@relation_hash['diff'] = @relation_hash.delete('utf8_diff')
end
def setup_pipeline
@relation_hash.fetch('stages').each do |stage|
stage.statuses.each do |status|
status.pipeline = imported_object
end
end
end
def existing_or_new_object
# Only find existing records to avoid mapping tables such as milestones
# Otherwise always create the record, skipping the extra SELECT clause.
......
This diff is collapsed.
......@@ -181,14 +181,20 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
context 'when restoring hierarchy of pipeline, stages and jobs' do
let(:pipeline) { Ci::Pipeline.first }
it 'restores statuses' do
expect(CommitStatus.all.count).to be 10
end
it 'restores pipeline stages' do
expect(pipeline.stages.count).to be 2
expect(Ci::Stage.all.count).to be 6
end
it 'correctly restores association between a stage and a job' do
expect(pipeline.statuses).to all(have_attributes(stage_id: a_value > 0))
expect(CommitStatus.all).to all(have_attributes(stage_id: a_value > 0))
end
it 'correctly restores association between a stage and a pipeline' do
expect(CommitStatus.all).to all(have_attributes(pipeline_id: a_value > 0))
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