From 1d3815f89b9b9f5ecfd6dd15158a2988603b9ed8 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Wed, 26 Jul 2017 14:21:53 +0200 Subject: 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. --- app/controllers/import/gitlab_projects_controller.rb | 10 +--------- app/controllers/projects_controller.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb index 36d246d185b..6463d2dfd5b 100644 --- a/app/controllers/import/gitlab_projects_controller.rb +++ b/app/controllers/import/gitlab_projects_controller.rb @@ -12,15 +12,7 @@ class Import::GitlabProjectsController < Import::BaseController return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." }) end - import_upload_path = Gitlab::ImportExport.import_upload_path(filename: project_params[:file].original_filename) - - FileUtils.mkdir_p(File.dirname(import_upload_path)) - FileUtils.copy_entry(project_params[:file].path, import_upload_path) - - @project = Gitlab::ImportExport::ProjectCreator.new(project_params[:namespace_id], - current_user, - import_upload_path, - project_params[:path]).execute + @project = ::Projects::GitlabProjectsImporterService.new(current_user, project_params).execute if @project.saved? redirect_to( diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c769693255c..275474d02f6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -27,7 +27,12 @@ class ProjectsController < Projects::ApplicationController end def create - @project = ::Projects::CreateService.new(current_user, project_params).execute + @project = + if project_from_template? + ::Projects::CreateFromTemplateService.new(current_user, project_params).execute + else + ::Projects::CreateService.new(current_user, project_params).execute + end if @project.saved? cookies[:issue_board_welcome_hidden] = { path: project_path(@project), value: nil, expires: Time.at(0) } @@ -324,6 +329,7 @@ class ProjectsController < Projects::ApplicationController :runners_token, :tag_list, :visibility_level, + :template_title, project_feature_attributes: %i[ builds_access_level @@ -345,6 +351,10 @@ class ProjectsController < Projects::ApplicationController false end + def project_from_template? + project_params[:template_title]&.present? + end + def project_view_files? if current_user current_user.project_view == 'files' -- cgit v1.2.1 From 3baf3dc955dfaad2961bba548dab940b55dfa68e Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Tue, 1 Aug 2017 14:34:11 +0200 Subject: Rename GitLabProjectImporterService and misc fixes First round of review, main changes: - templates.title is human readable, #name will be passed around - GitLabProjectImporterService has been renamed --- app/controllers/projects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 275474d02f6..db4ea9c7d27 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -329,7 +329,7 @@ class ProjectsController < Projects::ApplicationController :runners_token, :tag_list, :visibility_level, - :template_title, + :template_name, project_feature_attributes: %i[ builds_access_level @@ -352,7 +352,7 @@ class ProjectsController < Projects::ApplicationController end def project_from_template? - project_params[:template_title]&.present? + project_params[:template_name]&.present? end def project_view_files? -- cgit v1.2.1 From 2e6aa4f25e14fa7e57ea9f271e302e291ecc9e05 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Mon, 7 Aug 2017 14:21:28 +0200 Subject: After merge cleanup --- app/controllers/projects_controller.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5c7c99fe7ef..08219a5112e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -26,13 +26,9 @@ class ProjectsController < Projects::ApplicationController render 'edit' end + def create - @project = - if project_from_template? - ::Projects::CreateFromTemplateService.new(current_user, project_params).execute - else - ::Projects::CreateService.new(current_user, project_params).execute - end + @project = ::Projects::CreateService.new(current_user, project_params).execute if @project.saved? cookies[:issue_board_welcome_hidden] = { path: project_path(@project), value: nil, expires: Time.at(0) } @@ -351,10 +347,6 @@ class ProjectsController < Projects::ApplicationController false end - def project_from_template? - project_params[:template_name]&.present? - end - def project_view_files? if current_user current_user.project_view == 'files' -- cgit v1.2.1 From db65499e26d6bc0c882f4855fe0e376bb1df3e6d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Mon, 7 Aug 2017 15:32:43 +0200 Subject: Fix last feature test for project templates --- app/controllers/projects_controller.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 08219a5112e..0bffae6decd 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -26,7 +26,6 @@ class ProjectsController < Projects::ApplicationController render 'edit' end - def create @project = ::Projects::CreateService.new(current_user, project_params).execute -- cgit v1.2.1 From 036ee515d418b99181d5e610e40a7ab527a8a9ce Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Mon, 7 Aug 2017 19:24:40 +0200 Subject: Port form back to use form_tag --- app/controllers/import/gitlab_projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb index 6463d2dfd5b..510813846a4 100644 --- a/app/controllers/import/gitlab_projects_controller.rb +++ b/app/controllers/import/gitlab_projects_controller.rb @@ -12,7 +12,7 @@ class Import::GitlabProjectsController < Import::BaseController return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." }) end - @project = ::Projects::GitlabProjectsImporterService.new(current_user, project_params).execute + @project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute if @project.saved? redirect_to( -- cgit v1.2.1