2017-09-10 17:25:29 +05:30
|
|
|
# This service is an adapter used to for the GitLab Import feature, and
|
|
|
|
# creating a project from a template.
|
|
|
|
# The latter will under the hood just import an archive supplied by GitLab.
|
|
|
|
module Projects
|
|
|
|
class GitlabProjectsImportService
|
|
|
|
attr_reader :current_user, :params
|
|
|
|
|
|
|
|
def initialize(user, params)
|
|
|
|
@current_user, @params = user, params.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
FileUtils.mkdir_p(File.dirname(import_upload_path))
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
file = params.delete(:file)
|
2017-09-10 17:25:29 +05:30
|
|
|
FileUtils.copy_entry(file.path, import_upload_path)
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
params[:import_type] = 'gitlab_project'
|
|
|
|
params[:import_source] = import_upload_path
|
|
|
|
|
|
|
|
::Projects::CreateService.new(current_user, params).execute
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def import_upload_path
|
|
|
|
@import_upload_path ||= Gitlab::ImportExport.import_upload_path(filename: tmp_filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
def tmp_filename
|
2018-03-17 18:26:18 +05:30
|
|
|
SecureRandom.hex
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|