started refactoring a bunch of stuff based on feedback

This commit is contained in:
James Lopez 2016-06-03 12:56:29 +02:00
parent 398f0071a6
commit 9d0038f2d7
8 changed files with 37 additions and 40 deletions

View file

@ -2,36 +2,39 @@ module Projects
module ImportExport
class ExportService < BaseService
def execute(options = {})
def execute(_options = {})
@shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(project.path_with_namespace, 'work'))
save_all if [save_version, save_project_tree, save_uploads, bundle_repo, bundle_wiki_repo].all?
cleanup_and_notify_worker if @shared.errors.any?
save_all
end
private
def save_version
Gitlab::ImportExport::VersionSaver.save(shared: @shared)
end
def save_project_tree
Gitlab::ImportExport::ProjectTreeSaver.new(project: project, shared: @shared).save
end
def save_uploads
Gitlab::ImportExport::UploadsSaver.save(project: project, shared: @shared)
end
def bundle_repo
Gitlab::ImportExport::RepoBundler.new(project: project, shared: @shared).bundle
end
def bundle_wiki_repo
Gitlab::ImportExport::WikiRepoBundler.new(project: project, shared: @shared).bundle
end
def save_all
Gitlab::ImportExport::Saver.save(shared: @shared)
if [version_saver, project_tree_saver, uploads_saver, repo_saver, wiki_repo_saver].all?(&:save)
Gitlab::ImportExport::Saver.save(shared: @shared)
else
cleanup_and_notify_worker
end
end
def version_saver
Gitlab::ImportExport::VersionSaver.new(shared: @shared)
end
def project_tree_saver
Gitlab::ImportExport::ProjectTreeSaver.new(project: project, shared: @shared)
end
def uploads_saver
Gitlab::ImportExport::UploadsSaver.new(project: project, shared: @shared)
end
def repo_saver
Gitlab::ImportExport::RepoSaver.new(project: project, shared: @shared)
end
def wiki_repo_saver
Gitlab::ImportExport::WikiRepoSaver.new(project: project, shared: @shared)
end
def cleanup_and_notify_worker

View file

@ -16,6 +16,8 @@ project_tree:
- :merge_request_diff
- ci_commits:
- :statuses
- notes:
:author
- :variables
- :triggers
- :deploy_keys

View file

@ -1,6 +1,6 @@
module Gitlab
module ImportExport
class RepoBundler
class RepoSaver
include Gitlab::ImportExport::CommandLineUtil
attr_reader :full_path
@ -10,7 +10,7 @@ module Gitlab
@shared = shared
end
def bundle
def save
return false if @project.empty_repo?
@full_path = File.join(@shared.export_path, ImportExport.project_bundle_filename)
bundle_to_disk

View file

@ -2,10 +2,6 @@ module Gitlab
module ImportExport
class UploadsSaver
def self.save(*args)
new(*args).save
end
def initialize(project:, shared:)
@project = project
@shared = shared

View file

@ -2,10 +2,6 @@ module Gitlab
module ImportExport
class VersionSaver
def self.save(*args)
new(*args).save
end
def initialize(shared:)
@shared = shared
end

View file

@ -1,7 +1,7 @@
module Gitlab
module ImportExport
class WikiRepoBundler < RepoBundler
def bundle
class WikiRepoSaver < RepoSaver
def save
@wiki = ProjectWiki.new(@project)
return true unless wiki_repository_exists? # it's okay to have no Wiki
bundle_to_disk(File.join(@shared.export_path, project_filename))

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe Gitlab::ImportExport::RepoBundler, services: true do
describe Gitlab::ImportExport::RepoSaver, services: true do
describe 'bundle a project Git repo' do
let(:user) { create(:user) }
@ -19,7 +19,7 @@ describe Gitlab::ImportExport::RepoBundler, services: true do
end
it 'bundles the repo successfully' do
expect(bundler.bundle).to be true
expect(bundler.save).to be true
end
end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe Gitlab::ImportExport::WikiRepoBundler, services: true do
describe Gitlab::ImportExport::WikiRepoSaver, services: true do
describe 'bundle a wiki Git repo' do
let(:user) { create(:user) }
@ -22,7 +22,7 @@ describe Gitlab::ImportExport::WikiRepoBundler, services: true do
end
it 'bundles the repo successfully' do
expect(wiki_bundler.bundle).to be true
expect(wiki_bundler.save).to be true
end
end
end