debian-mirror-gitlab/lib/gitlab/import_export/importer.rb

76 lines
2.4 KiB
Ruby
Raw Normal View History

2016-06-22 15:30:34 +05:30
module Gitlab
module ImportExport
class Importer
def initialize(project)
@archive_file = project.import_source
@current_user = project.creator
@project = project
@shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace)
end
def execute
2017-08-17 22:00:37 +05:30
if import_file && check_version! && [repo_restorer, wiki_restorer, project_tree, avatar_restorer, uploads_restorer].all?(&:restore)
2016-06-22 15:30:34 +05:30
project_tree.restored_project
else
raise Projects::ImportService::Error.new(@shared.errors.join(', '))
end
2016-08-24 12:49:21 +05:30
remove_import_file
2016-06-22 15:30:34 +05:30
end
private
2016-08-24 12:49:21 +05:30
def import_file
Gitlab::ImportExport::FileImporter.import(archive_file: @archive_file,
shared: @shared)
end
2016-06-22 15:30:34 +05:30
def check_version!
Gitlab::ImportExport::VersionChecker.check!(shared: @shared)
end
def project_tree
@project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(user: @current_user,
shared: @shared,
project: @project)
end
2016-08-24 12:49:21 +05:30
def avatar_restorer
Gitlab::ImportExport::AvatarRestorer.new(project: project_tree.restored_project, shared: @shared)
end
2016-06-22 15:30:34 +05:30
def repo_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: @shared,
project: project_tree.restored_project)
end
def wiki_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path,
shared: @shared,
2016-08-24 12:49:21 +05:30
project: ProjectWiki.new(project_tree.restored_project))
2016-06-22 15:30:34 +05:30
end
def uploads_restorer
Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.restored_project, shared: @shared)
end
def path_with_namespace
2017-08-17 22:00:37 +05:30
File.join(@project.namespace.full_path, @project.path)
2016-06-22 15:30:34 +05:30
end
def repo_path
File.join(@shared.export_path, 'project.bundle')
end
def wiki_repo_path
File.join(@shared.export_path, 'project.wiki.bundle')
end
2016-08-24 12:49:21 +05:30
def remove_import_file
FileUtils.rm_rf(@archive_file)
end
2016-06-22 15:30:34 +05:30
end
end
end