This instance will be upgraded to Heptapod 0.26.0rc1 on 2021-10-26 at 14:30 UTC+2 (a few minutes of down time)

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 1764b198ced2
......@@ -329,7 +329,7 @@ def project_params_ce
:runners_token,
:tag_list,
:visibility_level,
:template_title,
:template_name,
project_feature_attributes: %i[
builds_access_level
......@@ -352,7 +352,7 @@ def repo_exists?
end
def project_from_template?
project_params[:template_title]&.present?
project_params[:template_name]&.present?
end
def project_view_files?
......
......@@ -71,7 +71,7 @@ def set_last_repository_updated_at
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 @@ def initialize(user, params)
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 @@ def storage_path
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 @@ def ==(other)
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 @@
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 @@
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 @@
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