Commit a9ab6dbc authored by Stan Hu's avatar Stan Hu

Refactor use of Shell.import_repository for Wikis

The previous behavior would pass in a list of parameters
to Shell, but we can improve this by using the WikiFormatter
and Project models to give us the same information.
parent 6bac612d
......@@ -73,7 +73,7 @@ module Projects
project.ensure_repository
project.repository.fetch_as_mirror(project.import_url, refmap: refmap)
else
gitlab_shell.import_repository(project.repository_storage, project.disk_path, project.import_url, project.full_path)
gitlab_shell.import_project_repository(project)
end
rescue Gitlab::Shell::Error => e
# Expire cache to prevent scenarios such as:
......
......@@ -65,9 +65,9 @@ module Gitlab
def import_wiki
return if project.wiki.repository_exists?
disk_path = project.wiki.disk_path
import_url = project.import_url.sub(/\.git\z/, ".git/wiki")
gitlab_shell.import_repository(project.repository_storage, disk_path, import_url, project.full_path)
wiki = WikiFormatter.new(project)
gitlab_shell.import_wiki_repository(project, wiki)
rescue StandardError => e
errors << { type: :wiki, errors: e.message }
end
......
# frozen_string_literal: true
module Gitlab
module BitbucketImport
class WikiFormatter
attr_reader :project
def initialize(project)
@project = project
end
def disk_path
project.wiki.disk_path
end
def full_path
project.wiki.full_path
end
def import_url
project.import_url.sub(/\.git\z/, ".git/wiki")
end
end
end
end
......@@ -6,11 +6,12 @@ module Gitlab
class RepositoryImporter
include Gitlab::ShellAdapter
attr_reader :project, :client
attr_reader :project, :client, :wiki_formatter
def initialize(project, client)
@project = project
@client = client
@wiki_formatter = ::Gitlab::LegacyGithubImport::WikiFormatter.new(project)
end
# Returns true if we should import the wiki for the project.
......@@ -57,9 +58,7 @@ module Gitlab
end
def import_wiki_repository
wiki_path = "#{project.disk_path}.wiki"
gitlab_shell.import_repository(project.repository_storage, wiki_path, wiki_url, project.full_path)
gitlab_shell.import_wiki_repository(project, wiki_formatter)
true
rescue Gitlab::Shell::Error => e
......@@ -72,7 +71,7 @@ module Gitlab
end
def wiki_url
project.import_url.sub(/\.git\z/, '.wiki.git')
wiki_formatter.import_url
end
def update_clone_time
......
......@@ -267,7 +267,7 @@ module Gitlab
def import_wiki
unless project.wiki.repository_exists?
wiki = WikiFormatter.new(project)
gitlab_shell.import_repository(project.repository_storage, wiki.disk_path, wiki.import_url, project.wiki.full_path)
gitlab_shell.import_wiki_repository(project, wiki)
end
rescue Gitlab::Shell::Error => e
# GitHub error message when the wiki repo has not been created,
......
......@@ -13,6 +13,10 @@ module Gitlab
project.wiki.disk_path
end
def full_path
project.wiki.full_path
end
def import_url
project.import_url.sub(/\.git\z/, ".wiki.git")
end
......
......@@ -86,6 +86,14 @@ module Gitlab
false
end
def import_wiki_repository(project, wiki_formatter)
import_repository(project.repository_storage, wiki_formatter.disk_path, wiki_formatter.import_url, project.wiki.full_path)
end
def import_project_repository(project)
import_repository(project.repository_storage, project.disk_path, project.import_url, project.full_path)
end
# Import repository
#
# storage - project's storage name
......
......@@ -218,7 +218,7 @@ describe Gitlab::BitbucketImport::Importer do
describe 'wiki import' do
it 'is skipped when the wiki exists' do
expect(project.wiki).to receive(:repository_exists?) { true }
expect(importer.gitlab_shell).not_to receive(:import_repository)
expect(importer.gitlab_shell).not_to receive(:import_wiki_repository)
importer.execute
......@@ -227,12 +227,7 @@ describe Gitlab::BitbucketImport::Importer do
it 'imports to the project disk_path' do
expect(project.wiki).to receive(:repository_exists?) { false }
expect(importer.gitlab_shell).to receive(:import_repository).with(
project.repository_storage,
project.wiki.disk_path,
project.import_url + '/wiki',
project.full_path
)
expect(importer.gitlab_shell).to receive(:import_wiki_repository)
importer.execute
......
......@@ -5,6 +5,14 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
let(:import_state) { double(:import_state) }
let(:client) { double(:client) }
let(:wiki) do
double(
:wiki,
disk_path: 'foo.wiki',
full_path: 'group/foo.wiki'
)
end
let(:project) do
double(
:project,
......@@ -16,7 +24,8 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
create_wiki: true,
import_state: import_state,
full_path: 'group/foo',
lfs_enabled?: true
lfs_enabled?: true,
wiki: wiki
)
end
......@@ -196,7 +205,7 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do
it 'imports the wiki repository' do
expect(importer.gitlab_shell)
.to receive(:import_repository)
.with('foo', 'foo.wiki', 'foo.wiki.git', 'group/foo')
.with('foo', 'foo.wiki', 'foo.wiki.git', 'group/foo.wiki')
expect(importer.import_wiki_repository).to eq(true)
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