BigW Consortium Gitlab

Commit 4e73f982 by James Lopez

WIP - started working on bundle the repo, refactored some stuff and updated spec

parent 68eae045
module Projects
module ImportExport
module CommandLineUtil
def tar_cf(archive:, dir:)
cmd = %W(tar -cf #{archive} -C #{dir} .)
_output, status = Gitlab::Popen.popen(cmd)
status.zero?
end
end
end
end
......@@ -2,13 +2,19 @@ module Projects
module ImportExport
class ExportService < BaseService
def execute(options = {})
@shared = Projects::ImportExport::Shared.new(project_name: @project_name)
save_project_tree
bundle_repo
end
private
def save_project_tree
Projects::ImportExport::ProjectTreeSaver.save(project: project)
Projects::ImportExport::ProjectTreeSaver.new(project: project, shared: @shared).save
end
def bundle_repo
Projects::ImportExport::RepoBundler.new(project: project, shared: @shared).bundle
end
end
end
......
......@@ -3,19 +3,20 @@ module Projects
class ProjectTreeSaver
attr_reader :full_path
def initialize(project: )
def initialize(project: , shared: )
@project = project
@export_path = shared.export_path
end
def save
@full_path = File.join(export_path, project_filename)
@full_path = File.join(@export_path, project_filename)
save_to_disk
end
private
def save_to_disk
FileUtils.mkdir_p(export_path)
FileUtils.mkdir_p(@export_path)
File.write(full_path, project_json_tree)
true
rescue
......@@ -23,10 +24,6 @@ module Projects
false
end
def export_path
@export_path ||= ImportExport.export_path(@project.name)
end
def project_filename
# TODO sanitize name
"#{@project.name}.json"
......
module Projects
module ImportExport
class RepoBundler
include Projects::ImportExport::CommandLineUtil
attr_reader :full_path
def initialize(project: , shared: )
@project = project
@export_path = shared.export_path
end
def bundle
return false if project.empty_repo?
@full_path = File.join(export_path, project_filename)
bundle_to_disk
end
private
def bundle_to_disk
tar_cf(archive: full_path, dir: path_to_repo)
rescue
#TODO: handle error
false
end
def project_filename
@project.path_with_namespace + ".bundle"
end
def path_to_repo
@project.repository.path_to_repo
end
end
end
end
module Projects
module ImportExport
class Shared
def initialize(opts)
@opts = opts
end
def export_path
@export_path ||= ImportExport.export_path(project_name: @opts[:project_name])
end
end
end
end
\ No newline at end of file
......@@ -23,7 +23,8 @@ 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(:project_tree_saver) { Projects::ImportExport::ProjectTreeSaver.new(project: project) }
let(:shared) { Projects::ImportExport::Shared.new(project_name: @project_name) }
let(:project_tree_saver) { Projects::ImportExport::ProjectTreeSaver.new(project: project, shared: shared) }
before(:each) do
project.team << [user, :master]
......
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