From 0c0d8487df4ef4c1f368d8ce61fe39a4b98135c6 Mon Sep 17 00:00:00 2001 From: Jon Carroll Date: Wed, 22 Apr 2020 13:01:00 -0600 Subject: [PATCH 1/2] Support for >2 nested subgroups in destination path Pulling an object out of a gitlab.v4.objects.Group's subgroup property returns a gitlab.v4.objects.GroupSubgroup object, which is not a subclass of Group, and thus doesn't have a subgroup property. This will cause the code to break if the destination is more than 2 groups deep. To solve this the id property of the Subgroup can be used to pull out an actual group object object out with groups.get, then querying the subgroups of that object. --- gitlab_migrate/connection.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gitlab_migrate/connection.py b/gitlab_migrate/connection.py index 3a8cc88..bc7d50c 100644 --- a/gitlab_migrate/connection.py +++ b/gitlab_migrate/connection.py @@ -90,15 +90,18 @@ def find_group(connection, group, statistics=False): if '/' in group: tokens = group.split('/') current_group = None + base_group = None for search_for in tokens: if current_group is None: current_group = connection.groups.list( search=search_for, statistics=statistics, include_subgroups=True )[0] + base_group = current_group else: - current_group = current_group.subgroups.list( + current_group = base_group.subgroups.list( search=search_for, statistics=statistics, include_subgroups=True )[0] + base_group = connection.groups.get(current_group.id) # full API access only through groups.get current_group = connection.groups.get(current_group.id) return current_group From bd4940233db36cde7b3b3693dc75cb1d4d88dbf6 Mon Sep 17 00:00:00 2001 From: Jon Carroll Date: Wed, 22 Apr 2020 14:27:07 -0600 Subject: [PATCH 2/2] Support project names with spaces in them project.path should be used instead of project.name when importing a project so projects with spaces in the name are imported without error. By default spaces in project names are replaced with '-' characters in the path. --- gitlab_migrate/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab_migrate/connection.py b/gitlab_migrate/connection.py index bc7d50c..7f24b6c 100644 --- a/gitlab_migrate/connection.py +++ b/gitlab_migrate/connection.py @@ -121,10 +121,10 @@ def import_project(connection, project, destination): with open(export_file, 'rb') as f: output = None if type(destination).__name__ == 'User': - output = connection.projects.import_project(f, path=project.name, override=True) + output = connection.projects.import_project(f, path=project.path, override=True) else: output = connection.projects.import_project( - f, path=project.name, namespace=destination.id, overwrite=True, + f, path=project.path, namespace=destination.id, overwrite=True, ) print(' >>>> Import in progress') project_import = connection.projects.get(output['id'], lazy=True).imports.get()