summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/relation_factory.rb
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-05-18 15:15:14 +0200
committerJames Lopez <james@jameslopez.es>2016-05-18 15:15:14 +0200
commit0df21ac712d7afd99b0d38a52e7375b11a4fe269 (patch)
tree1ccf9c6114e2eead9c3b4000a56030c7f9fc43e2 /lib/gitlab/import_export/relation_factory.rb
parent4d894a7a953f18d8a71f003677b5f8ea5bbc1779 (diff)
downloadgitlab-ce-0df21ac712d7afd99b0d38a52e7375b11a4fe269.tar.gz
revert changes as builds are related to statuses which are already there
Diffstat (limited to 'lib/gitlab/import_export/relation_factory.rb')
-rw-r--r--lib/gitlab/import_export/relation_factory.rb66
1 files changed, 20 insertions, 46 deletions
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb
index 7f0f8f8077d..082398d1f0f 100644
--- a/lib/gitlab/import_export/relation_factory.rb
+++ b/lib/gitlab/import_export/relation_factory.rb
@@ -3,27 +3,21 @@ module Gitlab
module RelationFactory
extend self
- OVERRIDES = { snippets: :project_snippets,
- ci_commits: 'Ci::Commit',
- statuses: 'commit_status',
- variables: 'Ci::Variable',
- triggers: 'Ci::Trigger',
- builds: 'Ci::Build',
- hooks: 'ProjectHook' }.freeze
- USER_REFERENCES = %w(author_id assignee_id updated_by_id user_id).freeze
-
- def create(relation_sym:, relation_hash:, members_mapper:, commits_mapper:, user_admin:)
+ OVERRIDES = { snippets: :project_snippets, ci_commits: 'Ci::Commit', statuses: 'commit_status' }.freeze
+ USER_REFERENCES = %w(author_id assignee_id updated_by_id).freeze
+
+ def create(relation_sym:, relation_hash:, members_mapper:, user_admin:)
relation_sym = parse_relation_sym(relation_sym)
klass = parse_relation(relation_hash, relation_sym)
update_missing_author(relation_hash, members_mapper, user_admin) if relation_sym == :notes
update_user_references(relation_hash, members_mapper.map)
update_project_references(relation_hash, klass)
- update_commit_references(relation_hash, commits_mapper.ids_map) if commits_mapper
- generate_imported_object(klass, relation_hash, relation_sym)
+ imported_object(klass, relation_hash)
end
+ private
def update_user_references(relation_hash, members_map)
USER_REFERENCES.each do |reference|
@@ -33,32 +27,6 @@ module Gitlab
end
end
- def update_project_references(relation_hash, klass)
- project_id = relation_hash.delete('project_id')
-
- if relation_hash['source_project_id'] && relation_hash['target_project_id']
- # If source and target are the same, populate them with the new project ID.
- if relation_hash['target_project_id'] == relation_hash['source_project_id']
- relation_hash['source_project_id'] = project_id
- else
- relation_hash['source_project_id'] = -1
- end
- end
- relation_hash['target_project_id'] = project_id if relation_hash['target_project_id']
-
- # project_id may not be part of the export, but we always need to populate it if required.
- relation_hash['project_id'] = project_id if klass.column_names.include?('project_id')
- relation_hash['gl_project_id'] = project_id if relation_hash['gl_project_id']
- end
-
- private
-
- def update_commit_references(relation_hash, commit_ids_map)
- return unless relation_hash['commit_id']
- old_commit_id = relation_hash['commit_id']
- relation_hash['commit_id'] = commit_ids_map[old_commit_id]
- end
-
def update_missing_author(relation_hash, members_map, user_admin)
old_author_id = relation_hash['author_id']
@@ -82,15 +50,22 @@ module Gitlab
"\n\n *By #{author_name} on #{timestamp} (imported from GitLab project)*"
end
- def generate_imported_object(klass, relation_hash, relation_sym)
- if relation_sym == 'Ci::Build' # call #trace= method after assigning the other attributes
- trace = relation_hash.delete('trace')
- imported_object(klass, relation_hash) do |imported_object|
- imported_object.trace = trace
+ def update_project_references(relation_hash, klass)
+ project_id = relation_hash.delete('project_id')
+
+ if relation_hash['source_project_id'] && relation_hash['target_project_id']
+ # If source and target are the same, populate them with the new project ID.
+ if relation_hash['target_project_id'] == relation_hash['source_project_id']
+ relation_hash['source_project_id'] = project_id
+ else
+ relation_hash['source_project_id'] = -1
end
- else
- imported_object(klass, relation_hash)
end
+ relation_hash['target_project_id'] = project_id if relation_hash['target_project_id']
+
+ # project_id may not be part of the export, but we always need to populate it if required.
+ relation_hash['project_id'] = project_id if klass.column_names.include?('project_id')
+ relation_hash['gl_project_id'] = project_id if relation_hash ['gl_project_id']
end
def relation_class(relation_sym)
@@ -103,7 +78,6 @@ module Gitlab
def imported_object(klass, relation_hash)
imported_object = klass.new(relation_hash)
- yield(imported_object) if block_given?
imported_object.importing = true if imported_object.respond_to?(:importing)
imported_object
end