Commit 3fd5ea3d authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix/22225' into 'master'

Skip wiki creation when GitHub project has wiki enabled

## What does this MR do?

When importing a repository from if the repository has wiki, we should not create the default wiki. Otherwise the GitHub importer will fail because the wiki repository already exist. This bug was introduced here https://gitlab.com/gitlab-org/gitlab-ce/commit/892dea67717c0efbd6a28f7639f34535ec0a8747

## Are there points in the code the reviewer needs to double check?

No.

## Why was this MR needed?

GitLab fails to import GitHub Wiki.

## Screenshots (if relevant)

## Does this MR meet the acceptance criteria?

- [X] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- Tests
  - [X] Added for this feature/bug
  - [ ] All builds are passing
- [X] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [X] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [X] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

Fixes #22225

See merge request !6665
parents 7887a3da 0bb7bfd0
...@@ -51,6 +51,7 @@ v 8.13.0 (unreleased) ...@@ -51,6 +51,7 @@ v 8.13.0 (unreleased)
v 8.12.4 (unreleased) v 8.12.4 (unreleased)
- Fix type mismatch bug when closing Jira issue - Fix type mismatch bug when closing Jira issue
- Skip wiki creation when GitHub project has wiki enabled
- Fix issues importing services via Import/Export - Fix issues importing services via Import/Export
- Restrict failed login attempts for users with 2FA enabled - Restrict failed login attempts for users with 2FA enabled
- Fix "Copy to clipboard" tooltip to say "Copied!" when clipboard button is clicked. (lukehowell) - Fix "Copy to clipboard" tooltip to say "Copied!" when clipboard button is clicked. (lukehowell)
......
...@@ -7,6 +7,8 @@ module Projects ...@@ -7,6 +7,8 @@ module Projects
def execute def execute
forked_from_project_id = params.delete(:forked_from_project_id) forked_from_project_id = params.delete(:forked_from_project_id)
import_data = params.delete(:import_data) import_data = params.delete(:import_data)
@skip_wiki = params.delete(:skip_wiki)
@project = Project.new(params) @project = Project.new(params)
# Make sure that the user is allowed to use the specified visibility level # Make sure that the user is allowed to use the specified visibility level
...@@ -80,7 +82,7 @@ module Projects ...@@ -80,7 +82,7 @@ module Projects
log_info("#{@project.owner.name} created a new project \"#{@project.name_with_namespace}\"") log_info("#{@project.owner.name} created a new project \"#{@project.name_with_namespace}\"")
unless @project.gitlab_project_import? unless @project.gitlab_project_import?
@project.create_wiki if @project.feature_available?(:wiki, current_user) @project.create_wiki unless skip_wiki?
@project.build_missing_services @project.build_missing_services
@project.create_labels @project.create_labels
...@@ -94,6 +96,10 @@ module Projects ...@@ -94,6 +96,10 @@ module Projects
end end
end end
def skip_wiki?
!@project.feature_available?(:wiki, current_user) || @skip_wiki
end
def save_project_and_import_data(import_data) def save_project_and_import_data(import_data)
Project.transaction do Project.transaction do
@project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data @project.create_or_update_import_data(data: import_data[:data], credentials: import_data[:credentials]) if import_data
......
...@@ -170,10 +170,9 @@ module Gitlab ...@@ -170,10 +170,9 @@ module Gitlab
end end
def import_wiki def import_wiki
unless project.wiki_enabled? unless project.wiki.repository_exists?
wiki = WikiFormatter.new(project) wiki = WikiFormatter.new(project)
gitlab_shell.import_repository(project.repository_storage_path, wiki.path_with_namespace, wiki.import_url) gitlab_shell.import_repository(project.repository_storage_path, wiki.path_with_namespace, wiki.import_url)
project.project.update_attribute(:wiki_access_level, ProjectFeature::ENABLED)
end end
rescue Gitlab::Shell::Error => e rescue Gitlab::Shell::Error => e
# GitHub error message when the wiki repo has not been created, # GitHub error message when the wiki repo has not been created,
......
module Gitlab module Gitlab
module GithubImport module GithubImport
class ProjectCreator class ProjectCreator
attr_reader :repo, :namespace, :current_user, :session_data attr_reader :repo, :name, :namespace, :current_user, :session_data
def initialize(repo, name, namespace, current_user, session_data) def initialize(repo, name, namespace, current_user, session_data)
@repo = repo @repo = repo
...@@ -12,24 +12,37 @@ module Gitlab ...@@ -12,24 +12,37 @@ module Gitlab
end end
def execute def execute
project = ::Projects::CreateService.new( ::Projects::CreateService.new(
current_user, current_user,
name: @name, name: name,
path: @name, path: name,
description: repo.description, description: repo.description,
namespace_id: namespace.id, namespace_id: namespace.id,
visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : ApplicationSetting.current.default_project_visibility, visibility_level: visibility_level,
import_type: "github", import_type: "github",
import_source: repo.full_name, import_source: repo.full_name,
import_url: repo.clone_url.sub("https://", "https://#{@session_data[:github_access_token]}@") import_url: import_url,
skip_wiki: skip_wiki
).execute ).execute
end
private
def import_url
repo.clone_url.sub('https://', "https://#{session_data[:github_access_token]}@")
end
# If repo has wiki we'll import it later def visibility_level
if repo.has_wiki? && project repo.private ? Gitlab::VisibilityLevel::PRIVATE : ApplicationSetting.current.default_project_visibility
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
end end
project #
# If the GitHub project repository has wiki, we should not create the
# default wiki. Otherwise the GitHub importer will fail because the wiki
# repository already exist.
#
def skip_wiki
repo.has_wiki?
end end
end end
end end
......
...@@ -33,7 +33,7 @@ describe Gitlab::GithubImport::ProjectCreator, lib: true do ...@@ -33,7 +33,7 @@ describe Gitlab::GithubImport::ProjectCreator, lib: true do
expect(project.import_data.credentials).to eq(user: 'asdffg', password: nil) expect(project.import_data.credentials).to eq(user: 'asdffg', password: nil)
end end
context 'when Github project is private' do context 'when GitHub project is private' do
it 'sets project visibility to private' do it 'sets project visibility to private' do
repo.private = true repo.private = true
...@@ -43,7 +43,7 @@ describe Gitlab::GithubImport::ProjectCreator, lib: true do ...@@ -43,7 +43,7 @@ describe Gitlab::GithubImport::ProjectCreator, lib: true do
end end
end end
context 'when Github project is public' do context 'when GitHub project is public' do
before do before do
allow_any_instance_of(ApplicationSetting).to receive(:default_project_visibility).and_return(Gitlab::VisibilityLevel::INTERNAL) allow_any_instance_of(ApplicationSetting).to receive(:default_project_visibility).and_return(Gitlab::VisibilityLevel::INTERNAL)
end end
...@@ -56,5 +56,25 @@ describe Gitlab::GithubImport::ProjectCreator, lib: true do ...@@ -56,5 +56,25 @@ describe Gitlab::GithubImport::ProjectCreator, lib: true do
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL) expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
end end
end end
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
end end
end 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