summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-08-22 12:13:25 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-08-23 13:36:38 +0200
commit22ef4ba3a4be66296e5ee9231b4eb39e172c0f1f (patch)
treed59cb5328fffd5f0161444893b3429ae94e543cd /lib
parentd8d2b73b9f17e5af9aeccb1e9ba40045486651b5 (diff)
downloadgitlab-ce-22ef4ba3a4be66296e5ee9231b4eb39e172c0f1f.tar.gz
Migrate creation of nested groups into a service
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/bare_repository_importer.rb35
-rw-r--r--lib/tasks/import.rake18
2 files changed, 3 insertions, 50 deletions
diff --git a/lib/gitlab/bare_repository_importer.rb b/lib/gitlab/bare_repository_importer.rb
index 4bc3ccc3a1a..9323bfc7fb2 100644
--- a/lib/gitlab/bare_repository_importer.rb
+++ b/lib/gitlab/bare_repository_importer.rb
@@ -80,39 +80,8 @@ module Gitlab
return namespace
end
- create_group_path
- end
-
- def create_group_path
- group_path_segments = group_path.split('/')
-
- new_group, parent_group = nil
- partial_path_segments = []
- while subgroup_name = group_path_segments.shift
- partial_path_segments << subgroup_name
- partial_path = partial_path_segments.join('/')
-
- unless new_group = Group.find_by_full_path(partial_path)
- log " * Creating group #{partial_path}.".color(:green)
- params = {
- path: subgroup_name,
- name: subgroup_name,
- parent: parent_group,
- visibility_level: Gitlab::CurrentSettings.current_application_settings.default_group_visibility
- }
- new_group = Groups::CreateService.new(user, params).execute
- end
-
- if new_group.persisted?
- log " * Group #{partial_path} (#{new_group.id}) available".color(:green)
- else
- log " * Failed trying to create group #{partial_path}.".color(:red)
- log " * Errors: #{new_group.errors.messages}".color(:red)
- end
- parent_group = new_group
- end
-
- new_group
+ log " * Creating Group: #{group_path}"
+ Groups::NestedCreateService.new(user, group_path: group_path).execute
end
# This is called from within a rake task only used by Admins, so allow writing
diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake
index 96b8f59242c..1206302cb76 100644
--- a/lib/tasks/import.rake
+++ b/lib/tasks/import.rake
@@ -72,23 +72,7 @@ class GithubImport
return @current_user.namespace if names == @current_user.namespace_path
return @current_user.namespace unless @current_user.can_create_group?
- full_path_namespace = Namespace.find_by_full_path(names)
-
- return full_path_namespace if full_path_namespace
-
- names.split('/').inject(nil) do |parent, name|
- begin
- namespace = Group.create!(name: name,
- path: name,
- owner: @current_user,
- parent: parent)
- namespace.add_owner(@current_user)
-
- namespace
- rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid
- Namespace.where(parent: parent).find_by_path_or_name(name)
- end
- end
+ Groups::NestedCreateService.new(@current_user, group_path: names).execute
end
def full_path_namespace(names)