summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/unreleased/51747-gitlab-com-unable-to-import-a-project-that-was-just-exported.yml5
-rw-r--r--lib/gitlab/import_export/project_tree_restorer.rb15
-rw-r--r--lib/gitlab/import_export/relation_factory.rb3
-rw-r--r--spec/lib/gitlab/import_export/project.json4
-rw-r--r--spec/lib/gitlab/import_export/project_tree_restorer_spec.rb6
5 files changed, 29 insertions, 4 deletions
diff --git a/changelogs/unreleased/51747-gitlab-com-unable-to-import-a-project-that-was-just-exported.yml b/changelogs/unreleased/51747-gitlab-com-unable-to-import-a-project-that-was-just-exported.yml
new file mode 100644
index 00000000000..29f7fd872bc
--- /dev/null
+++ b/changelogs/unreleased/51747-gitlab-com-unable-to-import-a-project-that-was-just-exported.yml
@@ -0,0 +1,5 @@
+---
+title: Fix NULL pipeline import problem and pipeline user mapping issue
+merge_request: 21875
+author:
+type: fixed
diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb
index 00ea4b833e2..3d693d23c99 100644
--- a/lib/gitlab/import_export/project_tree_restorer.rb
+++ b/lib/gitlab/import_export/project_tree_restorer.rb
@@ -136,9 +136,18 @@ module Gitlab
return if tree_hash[relation_key].blank?
tree_array = [tree_hash[relation_key]].flatten
+ null_iid_pipelines = []
# Avoid keeping a possible heavy object in memory once we are done with it
- while relation_item = tree_array.shift
+ while relation_item = (tree_array.shift || null_iid_pipelines.shift)
+ if nil_iid_pipeline?(relation_key, relation_item) && tree_array.any?
+ # Move pipelines with NULL IIDs to the end
+ # so they don't clash with existing IIDs.
+ null_iid_pipelines << relation_item
+
+ next
+ end
+
# The transaction at this level is less speedy than one single transaction
# But we can't have it in the upper level or GC won't get rid of the AR objects
# after we save the batch.
@@ -201,6 +210,10 @@ module Gitlab
def excluded_keys_for_relation(relation)
reader.attributes_finder.find_excluded_keys(relation)
end
+
+ def nil_iid_pipeline?(relation_key, relation_item)
+ relation_key == 'pipelines' && relation_item['iid'].nil?
+ end
end
end
end
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index 81807ed659c..2486b1e4921 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -86,7 +86,6 @@ module Gitlab
case @relation_name
when :merge_request_diff_files then setup_diff
when :notes then setup_note
- when 'Ci::Pipeline' then setup_pipeline
end
update_user_references
@@ -94,6 +93,8 @@ module Gitlab
update_group_references
remove_duplicate_assignees
+ setup_pipeline if @relation_name == 'Ci::Pipeline'
+
reset_tokens!
remove_encrypted_attributes!
end
diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json
index eefd00e7383..3f2281f213f 100644
--- a/spec/lib/gitlab/import_export/project.json
+++ b/spec/lib/gitlab/import_export/project.json
@@ -6143,7 +6143,7 @@
"id": 36,
"project_id": 5,
"ref": "master",
- "sha": "be93687618e4b132087f430a4d8fc3a609c9b77c",
+ "sha": "sha-notes",
"before_sha": null,
"push_data": null,
"created_at": "2016-03-22T15:20:35.755Z",
@@ -6154,6 +6154,7 @@
"status": "failed",
"started_at": null,
"finished_at": null,
+ "user_id": 9999,
"duration": null,
"notes": [
{
@@ -6353,6 +6354,7 @@
},
{
"id": 38,
+ "iid": 1,
"project_id": 5,
"ref": "master",
"sha": "5f923865dde3436854e9ceb9cdb7815618d4e849",
diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
index 3ff6be595a8..7ebfc61f5e7 100644
--- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
@@ -59,7 +59,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
it 'creates a valid pipeline note' do
- expect(Ci::Pipeline.first.notes).not_to be_empty
+ expect(Ci::Pipeline.find_by_sha('sha-notes').notes).not_to be_empty
+ end
+
+ it 'pipeline has the correct user ID' do
+ expect(Ci::Pipeline.find_by_sha('sha-notes').user_id).to eq(@user.id)
end
it 'restores pipelines with missing ref' do