Commit 5485c2bf authored by Thomas de Grenier de Latour's avatar Thomas de Grenier de Latour
Browse files

fix: only visit each subgroup once (+ order by path)

parent 78746577
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -433,7 +433,7 @@ class Butler:
        print(f"🏢 Group {AnsiColors.BLUE}{group.full_path}{AnsiColors.RESET}...")

        # 2: clean subprojects
        subprojects = group.projects.list(all=True)
        subprojects = group.projects.list(all=True, order_by="path", sort="asc")
        if len(subprojects) > 0:
            print(f"- clean {len(subprojects)} sub projects...")
            for project in subprojects:
@@ -457,7 +457,7 @@ class Butler:

        # 3: clean subgroups
        if not self.skip_subgroups:
            subgroups = group.descendant_groups.list(all=True)
            subgroups = group.subgroups.list(all=True, order_by="path", sort="asc")
            if len(subgroups) > 0:
                print(f"- clean {len(subgroups)} sub groups...")
                for subgroup in subgroups:
+20 −20
Original line number Diff line number Diff line
@@ -68,8 +68,8 @@ class TestGroups:
            'full_path': 'path/to/group'
        })

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/descendant_groups?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100&order_by=path&sort=asc', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[])

        # get initial group
        group = butler.client.groups.get(butler.group_path)
@@ -90,13 +90,13 @@ class TestGroups:
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43', status=200,
                      json={'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'})

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/descendant_groups?per_page=100', status=200, json=[
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100&order_by=path&sort=asc', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[
            {'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'}
        ])

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/projects?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/descendant_groups?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/projects?per_page=100&order_by=path&sort=asc', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[])

        # get initial group
        group = butler.client.groups.get(butler.group_path)
@@ -117,13 +117,13 @@ class TestGroups:
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43', status=200,
                      json={'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'})

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/descendant_groups?per_page=100', status=200, json=[
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100&order_by=path&sort=asc', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[
            {'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'}
        ])

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/projects?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/descendant_groups?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/projects?per_page=100&order_by=path&sort=asc', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[])

        # get initial group
        group = butler.client.groups.get(butler.group_path)
@@ -147,13 +147,13 @@ class TestGroups:
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43', status=200,
                      json={'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'})

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/descendant_groups?per_page=100', status=200, json=[
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100&order_by=path&sort=asc', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[
            {'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'}
        ])

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/projects?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/descendant_groups?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/projects?per_page=100&order_by=path&sort=asc', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[])

        # get initial group
        group = butler.client.groups.get(butler.group_path)
@@ -177,12 +177,12 @@ class TestGroups:
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43', status=200,
                      json={'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'})

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100', status=200, json=[
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100&order_by=path&sort=asc', status=200, json=[
            {'id': 1000, 'path': 'path/to/group/project1'},
            {'id': 1001, 'path': 'path/to/group/project2'},
            {'id': 1002, 'path': 'path/to/group/project3'},
        ])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/descendant_groups?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[])

        # Setup empty project
        mock_empty_project('1000')
@@ -208,13 +208,13 @@ class TestGroups:
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43', status=200,
                      json={'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'})

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100', status=200, json=[
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100&order_by=path&sort=asc', status=200, json=[
            {'id': 1000, 'path': 'path/to/group/project1'},
            {'id': 1001, 'path': 'path/to/group/project2'},
            {'id': 1002, 'path': 'path/to/group/project3'},
            {'id': 1003, 'path': 'path/to/group/project4'},
        ])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/descendant_groups?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[])

        # Setup empty project
        mock_empty_project('1000')
@@ -244,7 +244,7 @@ class TestGroups:
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/43', status=200,
                      json={'id': 43, 'name': 'Sub Group 1', 'full_path': 'path/to/group/sub1'})

        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100', status=200, json=[
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/projects?per_page=100&order_by=path&sort=asc', status=200, json=[
            {'id': 1000, 'path': 'path/to/group/project0'},
            {'id': 1001, 'path': 'path/to/group/project1'},
            {'id': 1002, 'path': 'path/to/group/project2'},
@@ -252,7 +252,7 @@ class TestGroups:
            {'id': 1004, 'path': 'path/to/group/project4'},
            {'id': 1005, 'path': 'path/to/group/project5'},
        ])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/descendant_groups?per_page=100', status=200, json=[])
        responses.add(responses.GET, 'http://gitlab.test/api/v4/groups/42/subgroups?per_page=100&order_by=path&sort=asc', status=200, json=[])

        # Setup empty project
        mock_empty_project('1000', project_access=None, group_access=None) # no access