summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects_controller.rb12
-rw-r--r--app/services/projects/create_service.rb4
-rw-r--r--app/views/projects/new.html.haml2
-rw-r--r--changelogs/unreleased/zj-project-templates.yml4
-rw-r--r--doc/development/rake_tasks.md17
-rw-r--r--lib/tasks/gitlab/update_templates.rake7
-rw-r--r--spec/features/projects_spec.rb6
-rw-r--r--spec/lib/gitlab/project_template_spec.rb2
-rw-r--r--spec/services/projects/create_from_template_service_spec.rb4
9 files changed, 36 insertions, 22 deletions
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'
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb
index e874a2d8789..48578b6d9e5 100644
--- a/app/services/projects/create_service.rb
+++ b/app/services/projects/create_service.rb
@@ -5,6 +5,10 @@ module Projects
end
def execute
+ if @params[:template_name]&.present?
+ return ::Projects::CreateFromTemplateService.new(current_user, params).execute
+ end
+
forked_from_project_id = params.delete(:forked_from_project_id)
import_data = params.delete(:import_data)
@skip_wiki = params.delete(:skip_wiki)
diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml
index 05521ac75b9..e3bbebbcf4c 100644
--- a/app/views/projects/new.html.haml
+++ b/app/views/projects/new.html.haml
@@ -25,7 +25,7 @@
.form-group
= f.label :template_project, class: 'label-light' do
Create from template
- = link_to icon('question-circle'), help_page_path("public_access/public_access"), aria: { label: "What's included in a template?" }, title: "What's included in a template?", class: 'has-tooltip', data: { placement: 'top'}
+ = link_to icon('question-circle'), help_page_path("public_access/public_access"), aria: { label: "What’s included in a template?" }, title: "What’s included in a template?", class: 'has-tooltip', data: { placement: 'top'}
%div
= render 'project_templates', f: f
.second-column
diff --git a/changelogs/unreleased/zj-project-templates.yml b/changelogs/unreleased/zj-project-templates.yml
new file mode 100644
index 00000000000..ab6e0f2d5f2
--- /dev/null
+++ b/changelogs/unreleased/zj-project-templates.yml
@@ -0,0 +1,4 @@
+---
+title: Projects can be created from templates
+merge_request: 13108
+author:
diff --git a/doc/development/rake_tasks.md b/doc/development/rake_tasks.md
index 42bb5e8619c..bfd80aab6a4 100644
--- a/doc/development/rake_tasks.md
+++ b/doc/development/rake_tasks.md
@@ -146,3 +146,20 @@ If new emoji are added, the spritesheet may change size. To compensate for
such changes, first generate the `emoji.png` spritesheet with the above Rake
task, then check the dimensions of the new spritesheet and update the
`SPRITESHEET_WIDTH` and `SPRITESHEET_HEIGHT` constants accordingly.
+
+## Updating project templates
+
+Starting a project from a template needs this project to be exported. On a
+up to date master branch with run:
+
+```
+gdk run db
+# In a new terminal window
+bundle exec rake gitlab:update_project_templates
+git checkout -b update-project-templates
+git add vendor/project_templates
+git commit
+git push -u origin update-project-templates
+```
+
+Now create a merge request and merge that to master.
diff --git a/lib/tasks/gitlab/update_templates.rake b/lib/tasks/gitlab/update_templates.rake
index 26f6276e84b..17199c1871d 100644
--- a/lib/tasks/gitlab/update_templates.rake
+++ b/lib/tasks/gitlab/update_templates.rake
@@ -24,16 +24,17 @@ namespace :gitlab do
path: template.title,
skip_wiki: true
}
+
puts "Creating project for #{template.name}"
- project = Projects::CreateService.new(admin, project).execute
+ project = Projects::CreateService.new(admin, params).execute
loop do
- if project.import_status == "finished"
+ if project.finished?
puts "Import finished for #{template.name}"
break
end
- if project.import_status == "failed"
+ if project.failed?
puts "Failed to import from #{project_params[:import_url]}".red
exit(1)
end
diff --git a/spec/features/projects_spec.rb b/spec/features/projects_spec.rb
index 48805de2f3b..c2ad3a25365 100644
--- a/spec/features/projects_spec.rb
+++ b/spec/features/projects_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
-<<<<<<< HEAD
-feature 'Project', feature: true do
+feature 'Project' do
describe 'creating from template' do
let(:user) { create(:user) }
let(:template) { Gitlab::ProjectTemplate.find(:rails) }
@@ -23,9 +22,6 @@ feature 'Project', feature: true do
end
end
-=======
-feature 'Project' do
->>>>>>> master
describe 'description' do
let(:project) { create(:project, :repository) }
let(:path) { project_path(project) }
diff --git a/spec/lib/gitlab/project_template_spec.rb b/spec/lib/gitlab/project_template_spec.rb
index 0f68e87a41a..12e75cdd5d0 100644
--- a/spec/lib/gitlab/project_template_spec.rb
+++ b/spec/lib/gitlab/project_template_spec.rb
@@ -31,7 +31,7 @@ describe Gitlab::ProjectTemplate do
describe 'instance methods' do
subject { described_class.new('phoenix', 'Phoenix Framework') }
- it { is_expected.to respond_to(:logo_path, :file, :archive_path) }
+ it { is_expected.to respond_to(:logo, :file, :archive_path) }
end
describe 'validate all templates' do
diff --git a/spec/services/projects/create_from_template_service_spec.rb b/spec/services/projects/create_from_template_service_spec.rb
index 9125b5bf161..9919ec254c6 100644
--- a/spec/services/projects/create_from_template_service_spec.rb
+++ b/spec/services/projects/create_from_template_service_spec.rb
@@ -5,7 +5,7 @@ describe Projects::CreateFromTemplateService do
let(:project_params) do
{
path: user.to_param,
- template_title: 'rails'
+ template_name: 'rails'
}
end
@@ -21,6 +21,6 @@ describe Projects::CreateFromTemplateService do
project = subject.execute
expect(project).to be_saved
- expect(project.import_status).to eq('scheduled')
+ expect(project.scheduled?).to be(true)
end
end