Does not fetch repository when importing from GitHub on import service
This commit is contained in:
parent
29d380b03c
commit
517a9f97c7
|
@ -34,8 +34,10 @@ module Projects
|
|||
def import_repository
|
||||
raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url)
|
||||
|
||||
return if project.github_import?
|
||||
|
||||
begin
|
||||
if project.github_import? || project.gitea_import?
|
||||
if project.gitea_import?
|
||||
fetch_repository
|
||||
else
|
||||
clone_repository
|
||||
|
@ -55,7 +57,7 @@ module Projects
|
|||
end
|
||||
|
||||
def fetch_repository
|
||||
project.create_repository
|
||||
project.ensure_repository
|
||||
project.repository.add_remote(project.import_type, project.import_url)
|
||||
project.repository.set_remote_as_mirror(project.import_type)
|
||||
project.repository.fetch_remote(project.import_type, forced: true)
|
||||
|
|
|
@ -38,8 +38,7 @@ describe Projects::ImportService do
|
|||
|
||||
context 'with a Github repository' do
|
||||
it 'succeeds if repository import is successfully' do
|
||||
expect_any_instance_of(Repository).to receive(:fetch_remote).and_return(true)
|
||||
expect_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(true)
|
||||
expect_any_instance_of(Github::Import).to receive(:execute).and_return(true)
|
||||
|
||||
result = subject.execute
|
||||
|
||||
|
@ -52,16 +51,7 @@ describe Projects::ImportService do
|
|||
result = subject.execute
|
||||
|
||||
expect(result[:status]).to eq :error
|
||||
expect(result[:message]).to eq "Error importing repository #{project.import_url} into #{project.full_path} - Failed to import the repository"
|
||||
end
|
||||
|
||||
it 'does not remove the GitHub remote' do
|
||||
expect_any_instance_of(Repository).to receive(:fetch_remote).and_return(true)
|
||||
expect_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(true)
|
||||
|
||||
subject.execute
|
||||
|
||||
expect(project.repository.raw_repository.remote_names).to include('github')
|
||||
expect(result[:message]).to eq "Error importing repository #{project.import_url} into #{project.path_with_namespace} - The remote data could not be imported."
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -102,8 +92,7 @@ describe Projects::ImportService do
|
|||
end
|
||||
|
||||
it 'succeeds if importer succeeds' do
|
||||
allow_any_instance_of(Repository).to receive(:fetch_remote).and_return(true)
|
||||
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(true)
|
||||
allow_any_instance_of(Github::Import).to receive(:execute).and_return(true)
|
||||
|
||||
result = subject.execute
|
||||
|
||||
|
@ -111,10 +100,7 @@ describe Projects::ImportService do
|
|||
end
|
||||
|
||||
it 'flushes various caches' do
|
||||
allow_any_instance_of(Repository).to receive(:fetch_remote)
|
||||
.and_return(true)
|
||||
|
||||
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute)
|
||||
allow_any_instance_of(Github::Import).to receive(:execute)
|
||||
.and_return(true)
|
||||
|
||||
expect_any_instance_of(Repository).to receive(:expire_content_cache)
|
||||
|
@ -123,8 +109,7 @@ describe Projects::ImportService do
|
|||
end
|
||||
|
||||
it 'fails if importer fails' do
|
||||
allow_any_instance_of(Repository).to receive(:fetch_remote).and_return(true)
|
||||
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(false)
|
||||
allow_any_instance_of(Github::Import).to receive(:execute).and_return(false)
|
||||
|
||||
result = subject.execute
|
||||
|
||||
|
@ -133,8 +118,7 @@ describe Projects::ImportService do
|
|||
end
|
||||
|
||||
it 'fails if importer raise an error' do
|
||||
allow_any_instance_of(Gitlab::Shell).to receive(:fetch_remote).and_return(true)
|
||||
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_raise(Projects::ImportService::Error.new('Github: failed to connect API'))
|
||||
allow_any_instance_of(Github::Import).to receive(:execute).and_raise(Projects::ImportService::Error.new('Github: failed to connect API'))
|
||||
|
||||
result = subject.execute
|
||||
|
||||
|
@ -143,9 +127,9 @@ describe Projects::ImportService do
|
|||
end
|
||||
|
||||
it 'expires content cache after error' do
|
||||
allow_any_instance_of(Project).to receive(:repository_exists?).and_return(false, true)
|
||||
allow_any_instance_of(Project).to receive(:repository_exists?).and_return(false)
|
||||
|
||||
expect_any_instance_of(Gitlab::Shell).to receive(:fetch_remote).and_raise(Gitlab::Shell::Error.new('Failed to import the repository'))
|
||||
expect_any_instance_of(Repository).to receive(:fetch_remote).and_raise(Gitlab::Shell::Error.new)
|
||||
expect_any_instance_of(Repository).to receive(:expire_content_cache)
|
||||
|
||||
subject.execute
|
||||
|
|
Loading…
Reference in New Issue