Merge branch '41424-gitlab-rake-gitlab-import-repos-schedules-an-import' into 'master'
Resolve "gitlab-rake gitlab:import:repos schedules an import" Closes #41424 See merge request gitlab-org/gitlab-ce!16115
This commit is contained in:
commit
9a2186d31b
6 changed files with 34 additions and 7 deletions
|
@ -639,7 +639,7 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def import?
|
||||
external_import? || forked? || gitlab_project_import?
|
||||
external_import? || forked? || gitlab_project_import? || bare_repository_import?
|
||||
end
|
||||
|
||||
def no_import?
|
||||
|
@ -679,6 +679,10 @@ class Project < ActiveRecord::Base
|
|||
Gitlab::UrlSanitizer.new(import_url).masked_url
|
||||
end
|
||||
|
||||
def bare_repository_import?
|
||||
import_type == 'bare_repository'
|
||||
end
|
||||
|
||||
def gitlab_project_import?
|
||||
import_type == 'gitlab_project'
|
||||
end
|
||||
|
|
|
@ -56,11 +56,7 @@ module Projects
|
|||
|
||||
after_create_actions if @project.persisted?
|
||||
|
||||
if @project.errors.empty?
|
||||
@project.import_schedule if @project.import?
|
||||
else
|
||||
fail(error: @project.errors.full_messages.join(', '))
|
||||
end
|
||||
import_schedule
|
||||
|
||||
@project
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
|
@ -164,5 +160,15 @@ module Projects
|
|||
@project.path = @project.name.dup.parameterize
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def import_schedule
|
||||
if @project.errors.empty?
|
||||
@project.import_schedule if @project.import? && !@project.bare_repository_import?
|
||||
else
|
||||
fail(error: @project.errors.full_messages.join(', '))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix gitlab-rake gitlab:import:repos import schedule
|
||||
merge_request: 16115
|
||||
author:
|
||||
type: fixed
|
|
@ -55,7 +55,8 @@ module Gitlab
|
|||
name: project_name,
|
||||
path: project_name,
|
||||
skip_disk_validation: true,
|
||||
import_type: 'gitlab_project',
|
||||
skip_wiki: bare_repo.wiki_exists?,
|
||||
import_type: 'bare_repository',
|
||||
namespace_id: group&.id).execute
|
||||
|
||||
if project.persisted? && mv_repo(project)
|
||||
|
|
|
@ -7,6 +7,7 @@ module Gitlab
|
|||
module ImportSources
|
||||
ImportSource = Struct.new(:name, :title, :importer)
|
||||
|
||||
# We exclude `bare_repository` here as it has no import class associated
|
||||
ImportTable = [
|
||||
ImportSource.new('github', 'GitHub', Gitlab::GithubImport::ParallelImporter),
|
||||
ImportSource.new('bitbucket', 'Bitbucket', Gitlab::BitbucketImport::Importer),
|
||||
|
|
|
@ -68,6 +68,12 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do
|
|||
expect(Project.find_by_full_path(project_path)).not_to be_nil
|
||||
end
|
||||
|
||||
it 'does not schedule an import' do
|
||||
expect_any_instance_of(Project).not_to receive(:import_schedule)
|
||||
|
||||
importer.create_project_if_needed
|
||||
end
|
||||
|
||||
it 'creates the Git repo in disk' do
|
||||
FileUtils.mkdir_p(File.join(base_dir, "#{project_path}.git"))
|
||||
|
||||
|
@ -131,6 +137,7 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do
|
|||
project = Project.find_by_full_path("#{admin.full_path}/#{project_path}")
|
||||
|
||||
expect(File).to exist(File.join(project.repository_storage_path, project.disk_path + '.git'))
|
||||
expect(File).to exist(File.join(project.repository_storage_path, project.disk_path + '.wiki.git'))
|
||||
end
|
||||
|
||||
it 'moves an existing project to the correct path' do
|
||||
|
@ -161,6 +168,9 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do
|
|||
FileUtils.mkdir_p(File.join(base_dir, "#{project_path}.git"))
|
||||
FileUtils.mkdir_p(File.join(base_dir, "#{project_path}.wiki.git"))
|
||||
|
||||
expect(Projects::CreateService).to receive(:new).with(admin, hash_including(skip_wiki: true,
|
||||
import_type: 'bare_repository')).and_call_original
|
||||
|
||||
importer.create_project_if_needed
|
||||
|
||||
project = Project.find_by_full_path(project_path)
|
||||
|
|
Loading…
Reference in a new issue