Skip to content
Snippets Groups Projects
Unverified Commit 3baf3dc9 authored by Z.J. van de Weg's avatar Z.J. van de Weg
Browse files

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
parent a853d3e9
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -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?
Loading
Loading
Loading
Loading
@@ -71,7 +71,7 @@ class Project < ActiveRecord::Base
 
attr_accessor :new_default_branch
attr_accessor :old_path_with_namespace
attr_accessor :template_title
attr_accessor :template_name
attr_writer :pipeline_status
 
alias_attribute :title, :name
Loading
Loading
Loading
Loading
@@ -5,10 +5,11 @@ module Projects
end
 
def execute
params[:file] = Gitlab::ProjectTemplate.find(params[:template_title]).file
params[:file] = Gitlab::ProjectTemplate.find(params[:template_name]).file
 
@params[:from_template] = true
GitlabProjectsImporterService.new(@current_user, @params).execute
GitlabProjectsImportService.new(@current_user, @params).execute
ensure
params[:file]&.close
end
end
end
Loading
Loading
@@ -2,7 +2,7 @@
# creating a project from a template.
# The latter will under the hood just import an archive supplied by GitLab.
module Projects
class GitlabProjectsImporterService
class GitlabProjectsImportService
attr_reader :current_user, :params
 
def initialize(user, params)
Loading
Loading
Loading
Loading
@@ -17,7 +17,7 @@ module Gitlab
def import_upload_path(filename:)
milliseconds = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
 
File.join(storage_path, 'uploads', "#{millisecond}-#{filename}")
File.join(storage_path, 'uploads', "#{milliseconds}-#{filename}")
end
 
def project_filename
Loading
Loading
Loading
Loading
@@ -24,13 +24,13 @@ module Gitlab
name == other.name && title == other.title
end
 
TemplatesTable = [
TEMPLATES_TABLE = [
ProjectTemplate.new('rails', 'Ruby on Rails')
].freeze
 
class << self
def all
TemplatesTable
TEMPLATES_TABLE
end
 
def find(name)
Loading
Loading
Loading
Loading
@@ -10,15 +10,15 @@ feature 'Project', feature: true do
visit new_project_path
end
 
it "allows creation from the #{template.name} template" do
fill_in("project_template_title", with: template.title)
it "allows creation from templates" do
fill_in("project_template_name", with: template.title)
fill_in("project_path", with: template.name)
 
page.within '#content-body' do
click_button "Create project"
end
 
expect(page).to have_content 'Import'
expect(page).to have_content 'Import in progress'
end
end
 
Loading
Loading
Loading
Loading
@@ -35,13 +35,28 @@ describe Gitlab::ProjectTemplate do
end
 
describe 'validate all templates' do
set(:admin) { create(:admin) }
described_class.all.each do |template|
it "#{template.name} has a valid archive" do
archive = template.archive_path
logo = Rails.root.join("app/assets/images/#{template.logo_path}")
 
expect(File.exist?(archive)).to be(true)
expect(File.exist?(logo)).to be(true)
end
context 'with valid parameters' do
it 'can be imported' do
params = {
template_name: template.name,
namespace_id: admin.namespace.id,
path: template.name
}
project = Projects::CreateFromTemplateService.new(admin, params).execute
expect(project).to be_valid
expect(project).to be_persisted
end
end
end
end
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ describe Projects::CreateFromTemplateService do
subject { described_class.new(user, project_params) }
 
it 'calls the importer service' do
expect_any_instance_of(Projects::GitlabProjectsImporterService).to receive(:execute)
expect_any_instance_of(Projects::GitlabProjectsImportService).to receive(:execute)
 
subject.execute
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment