BigW Consortium Gitlab

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
......@@ -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?
......
......@@ -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
......
......@@ -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
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment