diff options
author | James Lopez <james@jameslopez.es> | 2016-06-14 20:32:19 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-06-14 20:32:19 +0200 |
commit | b53ed84843b97c45bb19095cd2c7e0e8c86eb41a (patch) | |
tree | 3dbfeace867e212b6e3838421fcce02682abaa80 /lib | |
parent | 1d4243f5dd219d6e139864456353bee5f325bd72 (diff) | |
download | gitlab-ce-b53ed84843b97c45bb19095cd2c7e0e8c86eb41a.tar.gz |
adapted current services stuff to use new project import, plus fixes a few issues, updated routes, etc...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/import_export/importer.rb | 36 | ||||
-rw-r--r-- | lib/gitlab/import_export/project_creator.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/import_export/project_tree_restorer.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/import_export/version_checker.rb | 4 |
4 files changed, 21 insertions, 33 deletions
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb index d096e17bdf0..4db9410bba1 100644 --- a/lib/gitlab/import_export/importer.rb +++ b/lib/gitlab/import_export/importer.rb @@ -2,24 +2,22 @@ module Gitlab module ImportExport class Importer - def self.execute(*args) - new(*args).execute - end - def initialize(project) @archive_file = project.import_source @current_user = project.creator - @shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace(@project.path)) + @project = project + @shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace) end def execute Gitlab::ImportExport::FileImporter.import(archive_file: @archive_file, shared: @shared) if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore) - project_tree.project + project_tree.restored_project else - project_tree.project.destroy if project_tree.project - nil + project_tree.restored_project.destroy if project_tree.restored_project + + raise Projects::ImportService::Error.new, @shared.errors.join(', ') end end @@ -38,22 +36,22 @@ module Gitlab def repo_restorer Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path, shared: @shared, - project: project_tree.project) + project: project_tree.restored_project) end def wiki_restorer Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path, shared: @shared, - project: ProjectWiki.new(project_tree.project), + project: ProjectWiki.new(project_tree.restored_project), wiki: true) end def uploads_restorer - Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.project, shared: @shared) + Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.restored_project, shared: @shared) end - def path_with_namespace(project_path) - File.join(@namespace.path, project_path) + def path_with_namespace + File.join(@project.namespace.path, @project.path) end def repo_path @@ -63,18 +61,6 @@ module Gitlab def wiki_repo_path File.join(@shared.export_path, 'project.wiki.bundle') end - - def attributes_for_todo - { user_id: @current_user.id, - project_id: project_tree.project.id, - target_type: 'Project', - target: project_tree.project, - action: Todo::IMPORTED, - author_id: @current_user.id, - state: :pending, - target_id: project_tree.project.id - } - end end end end diff --git a/lib/gitlab/import_export/project_creator.rb b/lib/gitlab/import_export/project_creator.rb index 6f1e3867efb..89388d1984b 100644 --- a/lib/gitlab/import_export/project_creator.rb +++ b/lib/gitlab/import_export/project_creator.rb @@ -11,10 +11,10 @@ module Gitlab def execute ::Projects::CreateService.new( - current_user, + @current_user, name: @project_path, path: @project_path, - namespace_id: namespace_id, + namespace_id: @namespace_id, import_type: "gitlab_project", import_source: @file ).execute diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb index 92727528d01..dd71b92c522 100644 --- a/lib/gitlab/import_export/project_tree_restorer.rb +++ b/lib/gitlab/import_export/project_tree_restorer.rb @@ -19,7 +19,7 @@ module Gitlab false end - def project + def restored_project @restored_project ||= restore_project end @@ -28,7 +28,7 @@ module Gitlab def members_mapper @members_mapper ||= Gitlab::ImportExport::MembersMapper.new(exported_members: @project_members, user: @user, - project: project) + project: restored_project) end # Loops through the tree of models defined in import_export.yml and @@ -45,7 +45,7 @@ module Gitlab relation_key = relation.is_a?(Hash) ? relation.keys.first : relation relation_hash = create_relation(relation_key, @tree_hash[relation_key.to_s]) - saved << project.update_attribute(relation_key, relation_hash) + saved << restored_project.update_attribute(relation_key, relation_hash) end saved.all? end @@ -57,6 +57,8 @@ module Gitlab end def restore_project + return @project unless @tree_hash + project_params = @tree_hash.reject { |_key, value| value.is_a?(Array) } @project.update(project_params) @project @@ -91,7 +93,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: relation_hash.merge('project_id' => project.id), + relation_hash: relation_hash.merge('project_id' => restored_project.id), members_mapper: members_mapper, user: @user) end diff --git a/lib/gitlab/import_export/version_checker.rb b/lib/gitlab/import_export/version_checker.rb index 4f467760862..cf5c62c5e3c 100644 --- a/lib/gitlab/import_export/version_checker.rb +++ b/lib/gitlab/import_export/version_checker.rb @@ -2,8 +2,8 @@ module Gitlab module ImportExport class VersionChecker - def self.restore(*args) - new(*args).check + def self.check!(*args) + new(*args).check! end def initialize(shared:) |