diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-07-26 14:21:53 +0200 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-07-28 11:32:46 +0200 |
commit | 1d3815f89b9b9f5ecfd6dd15158a2988603b9ed8 (patch) | |
tree | a694e1e05f58fc3fe5ae00135d4a439eef7c8150 /app/services | |
parent | d964816b9fe56679ffc0b331e701f7b24db5c6a9 (diff) | |
download | gitlab-ce-1d3815f89b9b9f5ecfd6dd15158a2988603b9ed8.tar.gz |
Allow projects to be started from a template
Started implementation for the first iteration of
gitlab-org/gitlab-ce#32420. This will allow users to select a template
to start with, instead of an empty repository in the project just
created.
Internally this is basically a small extension of the ImportExport
GitLab projects we already support. We just import a certain import
tar archive. This commits includes the first one: Ruby on Rails. In the
future more will be added.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/create_from_template_service.rb | 14 | ||||
-rw-r--r-- | app/services/projects/gitlab_projects_importer_service.rb | 33 |
2 files changed, 47 insertions, 0 deletions
diff --git a/app/services/projects/create_from_template_service.rb b/app/services/projects/create_from_template_service.rb new file mode 100644 index 00000000000..3fc5c4ad157 --- /dev/null +++ b/app/services/projects/create_from_template_service.rb @@ -0,0 +1,14 @@ +module Projects + class CreateFromTemplateService < BaseService + def initialize(user, params) + @current_user, @params = user, params.dup + end + + def execute + params[:file] = Gitlab::ProjectTemplate.find(params[:template_title]).file + + @params[:from_template] = true + GitlabProjectsImporterService.new(@current_user, @params).execute + end + end +end diff --git a/app/services/projects/gitlab_projects_importer_service.rb b/app/services/projects/gitlab_projects_importer_service.rb new file mode 100644 index 00000000000..4cb98c54de5 --- /dev/null +++ b/app/services/projects/gitlab_projects_importer_service.rb @@ -0,0 +1,33 @@ +# 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 GitlabProjectsImporterService + 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)) + FileUtils.copy_entry(file.path, import_upload_path) + + Gitlab::ImportExport::ProjectCreator.new(params[:namespace_id], + current_user, + import_upload_path, + params[:path]).execute + end + + private + + def import_upload_path + @import_upload_path ||= Gitlab::ImportExport + .import_upload_path(filename: "#{params[:namespace_id]}-#{params[:path]}") + end + + def file + params[:file] + end + end +end |