Rename key param from project to importable in repo restorers

In this commit we rename the param used by repo restorers to indicate
the resource their using to import to. Since we're going to reuse it
with different elements, like projects and groups, it makes more sense
to rename them to `importable`.
parent 1d7c653b
...@@ -170,7 +170,7 @@ The last option is to import a project using a Rails console: ...@@ -170,7 +170,7 @@ The last option is to import a project using a Rails console:
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path, Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: shared, shared: shared,
project: project).restore importable: project).restore
``` ```
We are storing all import failures in the `import_failures` data table. We are storing all import failures in the `import_failures` data table.
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
module Gitlab module Gitlab
module ImportExport module ImportExport
class DesignRepoRestorer < RepoRestorer class DesignRepoRestorer < RepoRestorer
def initialize(project:, shared:, path_to_bundle:) extend ::Gitlab::Utils::Override
super(project: project, shared: shared, path_to_bundle: path_to_bundle)
@repository = project.design_repository override :repository
def repository
@repository ||= importable.design_repository
end end
# `restore` method is handled in super class # `restore` method is handled in super class
......
...@@ -75,19 +75,19 @@ module Gitlab ...@@ -75,19 +75,19 @@ module Gitlab
def repo_restorer def repo_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path, Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: shared, shared: shared,
project: project) importable: project)
end end
def wiki_restorer def wiki_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path, Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path,
shared: shared, shared: shared,
project: ProjectWiki.new(project)) importable: ProjectWiki.new(project))
end end
def design_repo_restorer def design_repo_restorer
Gitlab::ImportExport::DesignRepoRestorer.new(path_to_bundle: design_repo_path, Gitlab::ImportExport::DesignRepoRestorer.new(path_to_bundle: design_repo_path,
shared: shared, shared: shared,
project: project) importable: project)
end end
def uploads_restorer def uploads_restorer
......
...@@ -5,10 +5,12 @@ module Gitlab ...@@ -5,10 +5,12 @@ module Gitlab
class RepoRestorer class RepoRestorer
include Gitlab::ImportExport::CommandLineUtil include Gitlab::ImportExport::CommandLineUtil
def initialize(project:, shared:, path_to_bundle:) attr_reader :importable
@repository = project.repository
def initialize(importable:, shared:, path_to_bundle:)
@path_to_bundle = path_to_bundle @path_to_bundle = path_to_bundle
@shared = shared @shared = shared
@importable = importable
end end
def restore def restore
...@@ -22,9 +24,13 @@ module Gitlab ...@@ -22,9 +24,13 @@ module Gitlab
false false
end end
def repository
@repository ||= importable.repository
end
private private
attr_accessor :repository, :path_to_bundle, :shared attr_accessor :path_to_bundle, :shared
def ensure_repository_does_not_exist! def ensure_repository_does_not_exist!
if repository.exists? if repository.exists?
......
...@@ -16,7 +16,7 @@ RSpec.describe Gitlab::ImportExport::DesignRepoRestorer do ...@@ -16,7 +16,7 @@ RSpec.describe Gitlab::ImportExport::DesignRepoRestorer do
let(:restorer) do let(:restorer) do
described_class.new(path_to_bundle: bundle_path, described_class.new(path_to_bundle: bundle_path,
shared: shared, shared: shared,
project: project) importable: project)
end end
before do before do
......
...@@ -16,7 +16,7 @@ RSpec.describe 'forked project import' do ...@@ -16,7 +16,7 @@ RSpec.describe 'forked project import' do
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
let(:repo_restorer) do let(:repo_restorer) do
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: bundle_path, shared: shared, project: project) Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: bundle_path, shared: shared, importable: project)
end end
let!(:merge_request) do let!(:merge_request) do
......
...@@ -69,8 +69,8 @@ RSpec.describe Gitlab::ImportExport::Importer do ...@@ -69,8 +69,8 @@ RSpec.describe Gitlab::ImportExport::Importer do
repo_path = File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) repo_path = File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename)
restorer = double(Gitlab::ImportExport::RepoRestorer) restorer = double(Gitlab::ImportExport::RepoRestorer)
expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: repo_path, shared: shared, project: project).and_return(restorer) expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: repo_path, shared: shared, importable: project).and_return(restorer)
expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: wiki_repo_path, shared: shared, project: ProjectWiki.new(project)).and_return(restorer) expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: wiki_repo_path, shared: shared, importable: ProjectWiki.new(project)).and_return(restorer)
expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).and_call_original expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).and_call_original
expect(restorer).to receive(:restore).and_return(true).twice expect(restorer).to receive(:restore).and_return(true).twice
......
...@@ -30,7 +30,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do ...@@ -30,7 +30,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do
let(:bundler) { Gitlab::ImportExport::RepoSaver.new(exportable: project_with_repo, shared: shared) } let(:bundler) { Gitlab::ImportExport::RepoSaver.new(exportable: project_with_repo, shared: shared) }
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: project) } subject { described_class.new(path_to_bundle: bundle_path, shared: shared, importable: project) }
after do after do
Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path) Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path)
...@@ -65,7 +65,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do ...@@ -65,7 +65,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do
let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(exportable: project_with_repo, shared: shared) } let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(exportable: project_with_repo, shared: shared) }
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.wiki_repo_bundle_filename) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.wiki_repo_bundle_filename) }
subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: ProjectWiki.new(project)) } subject { described_class.new(path_to_bundle: bundle_path, shared: shared, importable: ProjectWiki.new(project)) }
after do after do
Gitlab::Shell.new.remove_repository(project.wiki.repository_storage, project.wiki.disk_path) Gitlab::Shell.new.remove_repository(project.wiki.repository_storage, project.wiki.disk_path)
......
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