diff options
author | James Lopez <james@jameslopez.es> | 2016-03-08 14:35:37 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-03-08 14:35:37 +0300 |
commit | 4e73f9827cc5b164e409a6beb9a305ef5604423d (patch) | |
tree | 8a3460ddcb7c1801220744d784a7a01eb1dc4261 /app/services/projects/import_export | |
parent | 68eae04538f296a15863235d7f1f59f3e9e8a1dd (diff) |
WIP - started working on bundle the repo, refactored some stuff and updated spec
Diffstat (limited to 'app/services/projects/import_export')
5 files changed, 72 insertions, 8 deletions
diff --git a/app/services/projects/import_export/command_line_util.rb b/app/services/projects/import_export/command_line_util.rb new file mode 100644 index 00000000000..7b0cc08763b --- /dev/null +++ b/app/services/projects/import_export/command_line_util.rb @@ -0,0 +1,11 @@ +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 diff --git a/app/services/projects/import_export/export_service.rb b/app/services/projects/import_export/export_service.rb index c89dd3d12ed..b3ad278733a 100644 --- a/app/services/projects/import_export/export_service.rb +++ b/app/services/projects/import_export/export_service.rb @@ -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 diff --git a/app/services/projects/import_export/project_tree_saver.rb b/app/services/projects/import_export/project_tree_saver.rb index 4801c791ffe..3ca90d1f79a 100644 --- a/app/services/projects/import_export/project_tree_saver.rb +++ b/app/services/projects/import_export/project_tree_saver.rb @@ -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" diff --git a/app/services/projects/import_export/repo_bundler.rb b/app/services/projects/import_export/repo_bundler.rb new file mode 100644 index 00000000000..27f1d5c87e5 --- /dev/null +++ b/app/services/projects/import_export/repo_bundler.rb @@ -0,0 +1,37 @@ +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 diff --git a/app/services/projects/import_export/shared.rb b/app/services/projects/import_export/shared.rb new file mode 100644 index 00000000000..cdff8b02dd3 --- /dev/null +++ b/app/services/projects/import_export/shared.rb @@ -0,0 +1,13 @@ +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 |