added repo bundler spec and refactored some of the export code
This commit is contained in:
parent
4e73f9827c
commit
556cafa44e
|
@ -2,8 +2,8 @@ module Projects
|
|||
module ImportExport
|
||||
extend self
|
||||
|
||||
def export_path(project_name:)
|
||||
File.join(storage_path, "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_gitlab_export_#{project_name}")
|
||||
def export_path(relative_path:)
|
||||
File.join(storage_path, "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_gitlab_export/#{relative_path}")
|
||||
end
|
||||
|
||||
def project_atts
|
||||
|
|
|
@ -2,7 +2,7 @@ module Projects
|
|||
module ImportExport
|
||||
class ExportService < BaseService
|
||||
def execute(options = {})
|
||||
@shared = Projects::ImportExport::Shared.new(project_name: @project_name)
|
||||
@shared = Projects::ImportExport::Shared.new(relative_path: project.path_with_namespace)
|
||||
save_project_tree
|
||||
bundle_repo
|
||||
end
|
||||
|
|
|
@ -11,14 +11,15 @@ module Projects
|
|||
end
|
||||
|
||||
def bundle
|
||||
return false if project.empty_repo?
|
||||
@full_path = File.join(export_path, project_filename)
|
||||
return false if @project.empty_repo?
|
||||
@full_path = File.join(@export_path, project_filename)
|
||||
bundle_to_disk
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def bundle_to_disk
|
||||
FileUtils.mkdir_p(@export_path)
|
||||
tar_cf(archive: full_path, dir: path_to_repo)
|
||||
rescue
|
||||
#TODO: handle error
|
||||
|
@ -26,7 +27,7 @@ module Projects
|
|||
end
|
||||
|
||||
def project_filename
|
||||
@project.path_with_namespace + ".bundle"
|
||||
"#{@project.namespace}#{@project.name}.bundle"
|
||||
end
|
||||
|
||||
def path_to_repo
|
||||
|
|
|
@ -6,7 +6,7 @@ module Projects
|
|||
end
|
||||
|
||||
def export_path
|
||||
@export_path ||= ImportExport.export_path(project_name: @opts[:project_name])
|
||||
@export_path ||= Projects::ImportExport.export_path(relative_path: @opts[:relative_path])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,12 +23,12 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do
|
|||
end
|
||||
let!(:milestone) { create(:milestone, title: "Milestone v1.2", project: project) }
|
||||
let(:export_path) { "#{Dir::tmpdir}/project_tree_saver_spec" }
|
||||
let(:shared) { Projects::ImportExport::Shared.new(project_name: @project_name) }
|
||||
let(:shared) { Projects::ImportExport::Shared.new(relative_path: project.path_with_namespace) }
|
||||
let(:project_tree_saver) { Projects::ImportExport::ProjectTreeSaver.new(project: project, shared: shared) }
|
||||
|
||||
before(:each) do
|
||||
project.team << [user, :master]
|
||||
allow_any_instance_of(Projects::ImportExport::ProjectTreeSaver).to receive(:export_path).and_return(export_path)
|
||||
allow_any_instance_of(Projects::ImportExport).to receive(:storage_path).and_return(export_path)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Projects::ImportExport::RepoBundler, services: true do
|
||||
describe :bundle do
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let!(:project) { create(:project, :public, name: 'searchable_project') }
|
||||
let(:export_path) { "#{Dir::tmpdir}/project_tree_saver_spec" }
|
||||
let(:shared) { Projects::ImportExport::Shared.new(relative_path: project.path_with_namespace) }
|
||||
let(:bundler) { Projects::ImportExport::RepoBundler.new(project: project, shared: shared) }
|
||||
|
||||
before(:each) do
|
||||
project.team << [user, :master]
|
||||
allow_any_instance_of(Projects::ImportExport).to receive(:storage_path).and_return(export_path)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
FileUtils.rm_rf(export_path)
|
||||
end
|
||||
|
||||
it 'bundles the repo successfully' do
|
||||
expect(bundler.bundle).to be true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue