Does not fetch repository when importing from GitHub on import service

parent 29d380b0
...@@ -34,8 +34,10 @@ module Projects ...@@ -34,8 +34,10 @@ module Projects
def import_repository def import_repository
raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url) raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url)
return if project.github_import?
begin begin
if project.github_import? || project.gitea_import? if project.gitea_import?
fetch_repository fetch_repository
else else
clone_repository clone_repository
...@@ -55,7 +57,7 @@ module Projects ...@@ -55,7 +57,7 @@ module Projects
end end
def fetch_repository def fetch_repository
project.create_repository project.ensure_repository
project.repository.add_remote(project.import_type, project.import_url) project.repository.add_remote(project.import_type, project.import_url)
project.repository.set_remote_as_mirror(project.import_type) project.repository.set_remote_as_mirror(project.import_type)
project.repository.fetch_remote(project.import_type, forced: true) project.repository.fetch_remote(project.import_type, forced: true)
......
...@@ -38,8 +38,7 @@ describe Projects::ImportService do ...@@ -38,8 +38,7 @@ describe Projects::ImportService do
context 'with a Github repository' do context 'with a Github repository' do
it 'succeeds if repository import is successfully' 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(Github::Import).to receive(:execute).and_return(true)
expect_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(true)
result = subject.execute result = subject.execute
...@@ -52,16 +51,7 @@ describe Projects::ImportService do ...@@ -52,16 +51,7 @@ describe Projects::ImportService do
result = subject.execute result = subject.execute
expect(result[:status]).to eq :error 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" expect(result[:message]).to eq "Error importing repository #{project.import_url} into #{project.path_with_namespace} - The remote data could not be imported."
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')
end end
end end
...@@ -102,8 +92,7 @@ describe Projects::ImportService do ...@@ -102,8 +92,7 @@ describe Projects::ImportService do
end end
it 'succeeds if importer succeeds' do it 'succeeds if importer succeeds' do
allow_any_instance_of(Repository).to receive(:fetch_remote).and_return(true) allow_any_instance_of(Github::Import).to receive(:execute).and_return(true)
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(true)
result = subject.execute result = subject.execute
...@@ -111,10 +100,7 @@ describe Projects::ImportService do ...@@ -111,10 +100,7 @@ describe Projects::ImportService do
end end
it 'flushes various caches' do it 'flushes various caches' do
allow_any_instance_of(Repository).to receive(:fetch_remote) allow_any_instance_of(Github::Import).to receive(:execute)
.and_return(true)
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute)
.and_return(true) .and_return(true)
expect_any_instance_of(Repository).to receive(:expire_content_cache) expect_any_instance_of(Repository).to receive(:expire_content_cache)
...@@ -123,8 +109,7 @@ describe Projects::ImportService do ...@@ -123,8 +109,7 @@ describe Projects::ImportService do
end end
it 'fails if importer fails' do it 'fails if importer fails' do
allow_any_instance_of(Repository).to receive(:fetch_remote).and_return(true) allow_any_instance_of(Github::Import).to receive(:execute).and_return(false)
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(false)
result = subject.execute result = subject.execute
...@@ -133,8 +118,7 @@ describe Projects::ImportService do ...@@ -133,8 +118,7 @@ describe Projects::ImportService do
end end
it 'fails if importer raise an error' do 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(Github::Import).to receive(:execute).and_raise(Projects::ImportService::Error.new('Github: failed to connect API'))
allow_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_raise(Projects::ImportService::Error.new('Github: failed to connect API'))
result = subject.execute result = subject.execute
...@@ -143,9 +127,9 @@ describe Projects::ImportService do ...@@ -143,9 +127,9 @@ describe Projects::ImportService do
end end
it 'expires content cache after error' do 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) expect_any_instance_of(Repository).to receive(:expire_content_cache)
subject.execute subject.execute
......
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