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