Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-07-21 02:25:10 +0300
committerFrancisco Javier López <fjlopez@gitlab.com>2018-07-21 02:25:10 +0300
commit38eab74483e728018a129c36d4064313f5d152f6 (patch)
treef946438bc3085b175fe20e08ebf0773cfbfdb782 /app/services/projects/gitlab_projects_import_service.rb
parent334ee10727540c8e16d47075781564fd21e8a9cb (diff)
EE Port
Diffstat (limited to 'app/services/projects/gitlab_projects_import_service.rb')
-rw-r--r--app/services/projects/gitlab_projects_import_service.rb64
1 files changed, 38 insertions, 26 deletions
diff --git a/app/services/projects/gitlab_projects_import_service.rb b/app/services/projects/gitlab_projects_import_service.rb
index bc6e9caebb8..615dccc4685 100644
--- a/app/services/projects/gitlab_projects_import_service.rb
+++ b/app/services/projects/gitlab_projects_import_service.rb
@@ -5,6 +5,9 @@
# The latter will under the hood just import an archive supplied by GitLab.
module Projects
class GitlabProjectsImportService
+ include Gitlab::Utils::StrongMemoize
+ include Gitlab::TemplateHelper
+
attr_reader :current_user, :params
def initialize(user, import_params, override_params = nil)
@@ -12,39 +15,17 @@ module Projects
end
def execute
- FileUtils.mkdir_p(File.dirname(import_upload_path))
-
- file = params.delete(:file)
- FileUtils.copy_entry(file.path, import_upload_path)
-
- @overwrite = params.delete(:overwrite)
- data = {}
- data[:override_params] = @override_params if @override_params
-
- if overwrite_project?
- data[:original_path] = params[:path]
- params[:path] += "-#{tmp_filename}"
- end
+ prepare_template_environment(template_file&.path)
- params[:import_type] = 'gitlab_project'
- params[:import_source] = import_upload_path
- params[:import_data] = { data: data } if data.present?
+ prepare_import_params
::Projects::CreateService.new(current_user, params).execute
end
private
- def import_upload_path
- @import_upload_path ||= Gitlab::ImportExport.import_upload_path(filename: tmp_filename)
- end
-
- def tmp_filename
- SecureRandom.hex
- end
-
def overwrite_project?
- @overwrite && project_with_same_full_path?
+ overwrite? && project_with_same_full_path?
end
def project_with_same_full_path?
@@ -52,7 +33,38 @@ module Projects
end
def current_namespace
- @current_namespace ||= Namespace.find_by(id: params[:namespace_id])
+ strong_memoize(:current_namespace) do
+ Namespace.find_by(id: params[:namespace_id])
+ end
+ end
+
+ def overwrite?
+ strong_memoize(:overwrite) do
+ params.delete(:overwrite)
+ end
+ end
+
+ def template_file
+ strong_memoize(:template_file) do
+ params.delete(:file)
+ end
+ end
+
+ def prepare_import_params
+ data = {}
+ data[:override_params] = @override_params if @override_params
+
+ if overwrite_project?
+ data[:original_path] = params[:path]
+ params[:path] += "-#{tmp_filename}"
+ end
+
+ if template_file
+ params[:import_type] = 'gitlab_project'
+ params[:import_source] = import_upload_path
+ end
+
+ params[:import_data] = { data: data } if data.present?
end
end
end