2019-11-24 12:06:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-12-31 13:07:48 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::LegacyGithubImport::ProjectCreator do
|
2015-08-07 07:06:20 +00:00
|
|
|
let(:user) { create(:user) }
|
2018-04-23 15:48:26 +00:00
|
|
|
let(:namespace) { create(:group) }
|
2016-08-25 14:16:28 +00:00
|
|
|
|
2015-06-22 20:00:54 +00:00
|
|
|
let(:repo) do
|
|
|
|
OpenStruct.new(
|
|
|
|
login: 'vim',
|
|
|
|
name: 'vim',
|
|
|
|
full_name: 'asd/vim',
|
2016-08-25 14:16:28 +00:00
|
|
|
clone_url: 'https://gitlab.com/asd/vim.git'
|
2015-06-22 20:00:54 +00:00
|
|
|
)
|
|
|
|
end
|
2016-08-25 14:16:28 +00:00
|
|
|
|
2016-08-08 13:05:58 +00:00
|
|
|
subject(:service) { described_class.new(repo, repo.name, namespace, user, github_access_token: 'asdffg') }
|
2015-04-15 14:58:43 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
namespace.add_owner(user)
|
2018-06-14 13:04:44 +00:00
|
|
|
|
|
|
|
expect_next_instance_of(Project) do |project|
|
|
|
|
expect(project).to receive(:add_import_job)
|
|
|
|
end
|
2015-04-15 14:58:43 +00:00
|
|
|
end
|
2014-12-31 13:07:48 +00:00
|
|
|
|
2016-08-25 14:16:28 +00:00
|
|
|
describe '#execute' do
|
|
|
|
it 'creates a project' do
|
|
|
|
expect { service.execute }.to change(Project, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handle GitHub credentials' do
|
|
|
|
project = service.execute
|
|
|
|
|
|
|
|
expect(project.import_url).to eq('https://asdffg@gitlab.com/asd/vim.git')
|
|
|
|
expect(project.safe_import_url).to eq('https://*****@gitlab.com/asd/vim.git')
|
|
|
|
expect(project.import_data.credentials).to eq(user: 'asdffg', password: nil)
|
|
|
|
end
|
|
|
|
|
2016-10-04 05:40:03 +00:00
|
|
|
context 'when GitHub project is private' do
|
2016-08-25 14:16:28 +00:00
|
|
|
it 'sets project visibility to private' do
|
|
|
|
repo.private = true
|
|
|
|
|
|
|
|
project = service.execute
|
|
|
|
|
|
|
|
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-04 05:40:03 +00:00
|
|
|
context 'when GitHub project is public' do
|
2019-04-08 14:12:39 +00:00
|
|
|
it 'sets project visibility to namespace visibility level' do
|
2016-08-25 14:16:28 +00:00
|
|
|
repo.private = false
|
|
|
|
project = service.execute
|
2015-06-22 20:00:54 +00:00
|
|
|
|
2019-04-08 14:12:39 +00:00
|
|
|
expect(project.visibility_level).to eq(namespace.visibility_level)
|
2018-06-05 20:20:37 +00:00
|
|
|
end
|
2019-04-09 09:10:15 +00:00
|
|
|
|
|
|
|
context 'when importing into a user namespace' do
|
|
|
|
subject(:service) { described_class.new(repo, repo.name, user.namespace, user, github_access_token: 'asdffg') }
|
|
|
|
|
|
|
|
it 'sets project visibility to user namespace visibility level' do
|
|
|
|
repo.private = false
|
|
|
|
project = service.execute
|
|
|
|
|
|
|
|
expect(project.visibility_level).to eq(user.namespace.visibility_level)
|
|
|
|
end
|
|
|
|
end
|
2018-06-05 20:20:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when visibility level is restricted' do
|
|
|
|
context 'when GitHub project is private' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PRIVATE])
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive(:default_project_visibility).and_return(Gitlab::VisibilityLevel::INTERNAL)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets project visibility to the default project visibility' do
|
|
|
|
repo.private = true
|
|
|
|
|
|
|
|
project = service.execute
|
|
|
|
|
|
|
|
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when GitHub project is public' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive(:default_project_visibility).and_return(Gitlab::VisibilityLevel::INTERNAL)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets project visibility to the default project visibility' do
|
|
|
|
repo.private = false
|
|
|
|
|
|
|
|
project = service.execute
|
|
|
|
|
|
|
|
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
|
|
|
|
end
|
2016-08-25 14:16:28 +00:00
|
|
|
end
|
|
|
|
end
|
2016-10-04 05:40:03 +00:00
|
|
|
|
|
|
|
context 'when GitHub project has wiki' do
|
|
|
|
it 'does not create the wiki repository' do
|
|
|
|
allow(repo).to receive(:has_wiki?).and_return(true)
|
|
|
|
|
|
|
|
project = service.execute
|
|
|
|
|
|
|
|
expect(project.wiki.repository_exists?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when GitHub project does not have wiki' do
|
|
|
|
it 'creates the wiki repository' do
|
|
|
|
allow(repo).to receive(:has_wiki?).and_return(false)
|
|
|
|
|
|
|
|
project = service.execute
|
|
|
|
|
|
|
|
expect(project.wiki.repository_exists?).to eq true
|
|
|
|
end
|
|
|
|
end
|
2014-12-31 13:07:48 +00:00
|
|
|
end
|
|
|
|
end
|