Commit 88f7e434 authored by Imre Farkas's avatar Imre Farkas

Merge branch '207886-fj-refactor-export-repo-savers-to-user-exportable' into 'master'

Refactor repo exporters to use exportable instead of project

See merge request gitlab-org/gitlab!52173
parents 6a7f4289 224112a6
......@@ -86,11 +86,11 @@ module Projects
end
def repo_saver
Gitlab::ImportExport::RepoSaver.new(project: project, shared: shared)
Gitlab::ImportExport::RepoSaver.new(exportable: project, shared: shared)
end
def wiki_repo_saver
Gitlab::ImportExport::WikiRepoSaver.new(project: project, shared: shared)
Gitlab::ImportExport::WikiRepoSaver.new(exportable: project, shared: shared)
end
def lfs_saver
......@@ -102,7 +102,7 @@ module Projects
end
def design_repo_saver
Gitlab::ImportExport::DesignRepoSaver.new(project: project, shared: shared)
Gitlab::ImportExport::DesignRepoSaver.new(exportable: project, shared: shared)
end
def cleanup
......
......@@ -3,16 +3,18 @@
module Gitlab
module ImportExport
class DesignRepoSaver < RepoSaver
def save
@repository = project.design_repository
extend ::Gitlab::Utils::Override
super
override :repository
def repository
@repository ||= exportable.design_repository
end
private
def bundle_full_path
File.join(shared.export_path, ::Gitlab::ImportExport.design_repo_bundle_filename)
override :bundle_filename
def bundle_filename
::Gitlab::ImportExport.design_repo_bundle_filename
end
end
end
......
......@@ -5,12 +5,11 @@ module Gitlab
class RepoSaver
include Gitlab::ImportExport::CommandLineUtil
attr_reader :project, :repository, :shared
attr_reader :exportable, :shared
def initialize(project:, shared:)
@project = project
def initialize(exportable:, shared:)
@exportable = exportable
@shared = shared
@repository = @project.repository
end
def save
......@@ -19,6 +18,10 @@ module Gitlab
bundle_to_disk
end
def repository
@repository ||= @exportable.repository
end
private
def repository_exists?
......@@ -26,7 +29,11 @@ module Gitlab
end
def bundle_full_path
File.join(shared.export_path, ImportExport.project_bundle_filename)
File.join(shared.export_path, bundle_filename)
end
def bundle_filename
::Gitlab::ImportExport.project_bundle_filename
end
def bundle_to_disk
......
......@@ -3,17 +3,18 @@
module Gitlab
module ImportExport
class WikiRepoSaver < RepoSaver
def save
wiki = ProjectWiki.new(project)
@repository = wiki.repository
extend ::Gitlab::Utils::Override
super
override :repository
def repository
@repository ||= exportable.wiki.repository
end
private
def bundle_full_path
File.join(shared.export_path, ImportExport.wiki_repo_bundle_filename)
override :bundle_filename
def bundle_filename
::Gitlab::ImportExport.wiki_repo_bundle_filename
end
end
end
......
......@@ -11,7 +11,7 @@ RSpec.describe Gitlab::ImportExport::DesignRepoRestorer do
let!(:project) { create(:project) }
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
let(:shared) { project.import_export_shared }
let(:bundler) { Gitlab::ImportExport::DesignRepoSaver.new(project: project_with_design_repo, shared: shared) }
let(:bundler) { Gitlab::ImportExport::DesignRepoSaver.new(exportable: project_with_design_repo, shared: shared) }
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.design_repo_bundle_filename) }
let(:restorer) do
described_class.new(path_to_bundle: bundle_path,
......
......@@ -9,7 +9,7 @@ RSpec.describe Gitlab::ImportExport::DesignRepoSaver do
let!(:project) { create(:project, :design_repo) }
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
let(:shared) { project.import_export_shared }
let(:design_bundler) { described_class.new(project: project, shared: shared) }
let(:design_bundler) { described_class.new(exportable: project, shared: shared) }
before do
project.add_maintainer(user)
......
......@@ -12,7 +12,7 @@ RSpec.describe 'forked project import' do
let(:shared) { project.import_export_shared }
let(:forked_from_project) { create(:project, :repository) }
let(:forked_project) { fork_project(project_with_repo, nil, repository: true) }
let(:repo_saver) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) }
let(:repo_saver) { Gitlab::ImportExport::RepoSaver.new(exportable: project_with_repo, shared: shared) }
let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) }
let(:repo_restorer) do
......
......@@ -27,7 +27,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do
end
describe 'bundle a project Git repo' do
let(:bundler) { Gitlab::ImportExport::RepoSaver.new(project: 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) }
subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: project) }
......@@ -62,7 +62,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do
end
describe 'restore a wiki Git repo' do
let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: 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) }
subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: ProjectWiki.new(project)) }
......@@ -83,7 +83,7 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do
describe 'no wiki in the bundle' do
let!(:project_without_wiki) { create(:project) }
let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_without_wiki, shared: shared) }
let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(exportable: project_without_wiki, shared: shared) }
it 'does not creates an empty wiki' do
expect(subject.restore).to be true
......
......@@ -8,7 +8,7 @@ RSpec.describe Gitlab::ImportExport::RepoSaver do
let!(:project) { create(:project, :repository) }
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
let(:shared) { project.import_export_shared }
let(:bundler) { described_class.new(project: project, shared: shared) }
let(:bundler) { described_class.new(exportable: project, shared: shared) }
before do
project.add_maintainer(user)
......
......@@ -8,7 +8,7 @@ RSpec.describe Gitlab::ImportExport::WikiRepoSaver do
let_it_be(:project) { create(:project, :wiki_repo) }
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
let(:shared) { project.import_export_shared }
let(:wiki_bundler) { described_class.new(project: project, shared: shared) }
let(:wiki_bundler) { described_class.new(exportable: project, shared: shared) }
let!(:project_wiki) { ProjectWiki.new(project, user) }
before do
......
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