gitlab-org--gitlab-foss/app/services/projects/create_from_template_service.rb

29 lines
630 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module Projects
class CreateFromTemplateService < BaseService
2018-07-20 19:25:10 -04:00
include Gitlab::Utils::StrongMemoize
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
override_params = params.dup
params[:file] = file
GitlabProjectsImportService.new(current_user, params, override_params).execute
ensure
file&.close
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
end
end