summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-06-22 09:48:44 +0200
committerJames Lopez <james@jameslopez.es>2018-06-22 09:48:44 +0200
commit35d69ccf95e18031cd232c594282a1671d97d1ae (patch)
treec5a1a2847f812ba83a9e28bc7a82747ea85c02fc /lib/gitlab/import_export
parent3d3e441c91ac793272723b5f20eae5b9cf19fcc2 (diff)
downloadgitlab-ce-35d69ccf95e18031cd232c594282a1671d97d1ae.tar.gz
add more specs and refactor more relation factory code
Diffstat (limited to 'lib/gitlab/import_export')
-rw-r--r--lib/gitlab/import_export/project_tree_restorer.rb8
-rw-r--r--lib/gitlab/import_export/relation_factory.rb12
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb
index 25661a42ad5..8b30483a5e2 100644
--- a/lib/gitlab/import_export/project_tree_restorer.rb
+++ b/lib/gitlab/import_export/project_tree_restorer.rb
@@ -178,7 +178,7 @@ module Gitlab
def create_relation(relation, relation_hash_list)
relation_array = [relation_hash_list].flatten.map do |relation_hash|
Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym,
- relation_hash: parsed_relation_hash(relation_hash, relation.to_sym),
+ relation_hash: relation_hash,
members_mapper: members_mapper,
user: @user,
project: @restored_project,
@@ -188,12 +188,6 @@ module Gitlab
relation_hash_list.is_a?(Array) ? relation_array : relation_array.first
end
- def parsed_relation_hash(relation_hash, relation_type)
- params = { 'group_id' => restored_project.group.try(:id), 'project_id' => restored_project.id }
-
- relation_hash.merge(params)
- end
-
def reader
@reader ||= Gitlab::ImportExport::Reader.new(shared: @shared)
end
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index c5e8aa54f5d..f5a20a4d333 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -54,6 +54,8 @@ module Gitlab
@project = project
@imported_object_retries = 0
+ @relation_hash['project_id'] = @project.id
+
# Remove excluded keys from relation_hash
# We don't do this in the parsed_relation_hash because of the 'transformed attributes'
# For example, MergeRequestDiffFiles exports its diff attribute as utf8_diff. Then,
@@ -81,12 +83,11 @@ module Gitlab
when :merge_request_diff_files then setup_diff
when :notes then setup_note
when 'Ci::Pipeline' then setup_pipeline
- else
- @relation_hash['project_id'] = @project.id
end
update_user_references
update_project_references
+ update_group_references
remove_duplicate_assignees
reset_tokens!
@@ -161,6 +162,13 @@ module Gitlab
@relation_hash['target_project_id'] = project_id if @relation_hash['target_project_id']
end
+ def update_group_references
+ return unless EXISTING_OBJECT_CHECK.include?(@relation_name)
+ return unless @relation_hash['group_id']
+
+ @relation_hash['group_id'] = @project.group&.id
+ end
+
def same_source_and_target?
@relation_hash['target_project_id'] && @relation_hash['target_project_id'] == @relation_hash['source_project_id']
end