debian-mirror-gitlab/app/services/projects/create_from_template_service.rb

29 lines
630 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Projects
class CreateFromTemplateService < BaseService
2018-11-18 11:00:15 +05:30
include Gitlab::Utils::StrongMemoize
2017-09-10 17:25:29 +05:30
def initialize(user, params)
@current_user, @params = user, params.dup
end
def execute
2018-11-18 11:00:15 +05:30
file = Gitlab::ProjectTemplate.find(template_name)&.file
2018-03-27 19:54:05 +05:30
2018-05-09 12:01:36 +05:30
override_params = params.dup
2018-03-27 19:54:05 +05:30
params[:file] = file
2018-05-09 12:01:36 +05:30
GitlabProjectsImportService.new(current_user, params, override_params).execute
2017-09-10 17:25:29 +05:30
ensure
2018-03-27 19:54:05 +05:30
file&.close
2017-09-10 17:25:29 +05:30
end
2018-11-18 11:00:15 +05:30
def template_name
strong_memoize(:template_name) do
params.delete(:template_name).presence
end
end
2017-09-10 17:25:29 +05:30
end
end