diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-07-06 16:21:22 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-07-11 12:22:57 +0300 |
commit | a4b6707e63ca10eb64a92d45797eaad49e9c9f46 (patch) | |
tree | d2faaa1ca8504ba7148feebba00a3f8d8218fed4 /lib/gitlab/manifest_import/project_creator.rb | |
parent | 85b0240c4b58a49b22c9dbff9451127ae817652a (diff) |
Refactor manifest import code
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib/gitlab/manifest_import/project_creator.rb')
-rw-r--r-- | lib/gitlab/manifest_import/project_creator.rb | 42 |
1 files changed, 42 insertions, 0 deletions
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 |