From a4b6707e63ca10eb64a92d45797eaad49e9c9f46 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 6 Jul 2018 16:21:22 +0300 Subject: Refactor manifest import code Signed-off-by: Dmitriy Zaporozhets --- lib/gitlab/manifest_import/importer.rb | 46 --------------------------- lib/gitlab/manifest_import/project_creator.rb | 42 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 46 deletions(-) delete mode 100644 lib/gitlab/manifest_import/importer.rb create mode 100644 lib/gitlab/manifest_import/project_creator.rb (limited to 'lib') diff --git a/lib/gitlab/manifest_import/importer.rb b/lib/gitlab/manifest_import/importer.rb deleted file mode 100644 index 8ffeb0a4143..00000000000 --- a/lib/gitlab/manifest_import/importer.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Gitlab - module ManifestImport - class Importer - attr_reader :repository, :destination, :user - - def initialize(repository, destination, user) - @repository = repository - @destination = destination - @user = user - end - - def execute - import_project - end - - private - - def import_project - group_full_path, _, project_path = repository[:path].rpartition('/') - group_full_path = File.join(destination.full_path, group_full_path) if destination - group = Group.find_by_full_path(group_full_path) || - create_group_with_parents(group_full_path) - - params = { - import_url: repository[:url], - import_type: 'manifest', - namespace_id: group.id, - path: project_path, - name: project_path, - visibility_level: destination.visibility_level - } - - Projects::CreateService.new(user, params).execute - end - - def create_group_with_parents(full_path) - params = { - group_path: full_path, - visibility_level: destination.visibility_level - } - - Groups::NestedCreateService.new(user, params).execute - end - end - end -end diff --git a/lib/gitlab/manifest_import/project_creator.rb b/lib/gitlab/manifest_import/project_creator.rb new file mode 100644 index 00000000000..9ccd32c3a3b --- /dev/null +++ b/lib/gitlab/manifest_import/project_creator.rb @@ -0,0 +1,42 @@ +module Gitlab + module ManifestImport + class ProjectCreator + attr_reader :repository, :destination, :current_user + + def initialize(repository, destination, current_user) + @repository = repository + @destination = destination + @current_user = current_user + end + + def execute + group_full_path, _, project_path = repository[:path].rpartition('/') + group_full_path = File.join(destination.full_path, group_full_path) if destination + group = Group.find_by_full_path(group_full_path) || + create_group_with_parents(group_full_path) + + params = { + import_url: repository[:url], + import_type: 'manifest', + namespace_id: group.id, + path: project_path, + name: project_path, + visibility_level: destination.visibility_level + } + + Projects::CreateService.new(current_user, params).execute + end + + private + + def create_group_with_parents(full_path) + params = { + group_path: full_path, + visibility_level: destination.visibility_level + } + + Groups::NestedCreateService.new(current_user, params).execute + end + end + end +end -- cgit v1.2.1