2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-26 08:21:53 -04:00
|
|
|
module Projects
|
|
|
|
class CreateFromTemplateService < BaseService
|
2018-07-20 19:25:10 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2017-07-26 08:21:53 -04:00
|
|
|
def initialize(user, params)
|
|
|
|
@current_user, @params = user, params.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2018-07-20 19:25:10 -04:00
|
|
|
file = Gitlab::ProjectTemplate.find(template_name)&.file
|
2018-02-12 08:57:25 -05:00
|
|
|
|
2018-04-19 11:24:32 -04:00
|
|
|
override_params = params.dup
|
2018-02-12 08:57:25 -05:00
|
|
|
params[:file] = file
|
|
|
|
|
2018-04-19 11:24:32 -04:00
|
|
|
GitlabProjectsImportService.new(current_user, params, override_params).execute
|
2017-08-01 08:34:11 -04:00
|
|
|
ensure
|
2018-02-12 08:57:25 -05:00
|
|
|
file&.close
|
2017-07-26 08:21:53 -04:00
|
|
|
end
|
2018-07-20 19:25:10 -04:00
|
|
|
|
|
|
|
def template_name
|
|
|
|
strong_memoize(:template_name) do
|
2018-07-25 09:07:47 -04:00
|
|
|
params.delete(:template_name).presence
|
2018-07-20 19:25:10 -04:00
|
|
|
end
|
|
|
|
end
|
2017-07-26 08:21:53 -04:00
|
|
|
end
|
|
|
|
end
|