BigW Consortium Gitlab

Commit 556cafa4 by James Lopez

added repo bundler spec and refactored some of the export code

parent 4e73f982
...@@ -2,8 +2,8 @@ module Projects ...@@ -2,8 +2,8 @@ module Projects
module ImportExport module ImportExport
extend self extend self
def export_path(project_name:) def export_path(relative_path:)
File.join(storage_path, "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_gitlab_export_#{project_name}") File.join(storage_path, "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_gitlab_export/#{relative_path}")
end end
def project_atts def project_atts
......
...@@ -2,7 +2,7 @@ module Projects ...@@ -2,7 +2,7 @@ module Projects
module ImportExport module ImportExport
class ExportService < BaseService class ExportService < BaseService
def execute(options = {}) 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 save_project_tree
bundle_repo bundle_repo
end end
......
...@@ -11,14 +11,15 @@ module Projects ...@@ -11,14 +11,15 @@ module Projects
end end
def bundle def bundle
return false if project.empty_repo? return false if @project.empty_repo?
@full_path = File.join(export_path, project_filename) @full_path = File.join(@export_path, project_filename)
bundle_to_disk bundle_to_disk
end end
private private
def bundle_to_disk def bundle_to_disk
FileUtils.mkdir_p(@export_path)
tar_cf(archive: full_path, dir: path_to_repo) tar_cf(archive: full_path, dir: path_to_repo)
rescue rescue
#TODO: handle error #TODO: handle error
...@@ -26,7 +27,7 @@ module Projects ...@@ -26,7 +27,7 @@ module Projects
end end
def project_filename def project_filename
@project.path_with_namespace + ".bundle" "#{@project.namespace}#{@project.name}.bundle"
end end
def path_to_repo def path_to_repo
......
...@@ -6,7 +6,7 @@ module Projects ...@@ -6,7 +6,7 @@ module Projects
end end
def export_path 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 end
end end
......
...@@ -23,12 +23,12 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do ...@@ -23,12 +23,12 @@ describe Projects::ImportExport::ProjectTreeSaver, services: true do
end end
let!(:milestone) { create(:milestone, title: "Milestone v1.2", project: project) } let!(:milestone) { create(:milestone, title: "Milestone v1.2", project: project) }
let(:export_path) { "#{Dir::tmpdir}/project_tree_saver_spec" } 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) } let(:project_tree_saver) { Projects::ImportExport::ProjectTreeSaver.new(project: project, shared: shared) }
before(:each) do before(:each) do
project.team << [user, :master] 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 end
after(:each) do after(:each) do
......
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
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