Commit 4e73f982 authored by James Lopez's avatar 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 ...@@ -2,13 +2,19 @@ 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)
save_project_tree save_project_tree
bundle_repo
end end
private private
def save_project_tree 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 end
end end
......
...@@ -3,19 +3,20 @@ module Projects ...@@ -3,19 +3,20 @@ module Projects
class ProjectTreeSaver class ProjectTreeSaver
attr_reader :full_path attr_reader :full_path
def initialize(project: ) def initialize(project: , shared: )
@project = project @project = project
@export_path = shared.export_path
end end
def save def save
@full_path = File.join(export_path, project_filename) @full_path = File.join(@export_path, project_filename)
save_to_disk save_to_disk
end end
private private
def save_to_disk def save_to_disk
FileUtils.mkdir_p(export_path) FileUtils.mkdir_p(@export_path)
File.write(full_path, project_json_tree) File.write(full_path, project_json_tree)
true true
rescue rescue
...@@ -23,10 +24,6 @@ module Projects ...@@ -23,10 +24,6 @@ module Projects
false false
end end
def export_path
@export_path ||= ImportExport.export_path(@project.name)
end
def project_filename def project_filename
# TODO sanitize name # TODO sanitize name
"#{@project.name}.json" "#{@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 ...@@ -23,7 +23,8 @@ 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(: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 before(:each) do
project.team << [user, :master] 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