Created
May 6, 2020 10:18
-
-
Save RunsFor/ca5bd4f91c28298c6ca1237493759737 to your computer and use it in GitHub Desktop.
Simple python script which recursively iterates over a nested tree of subgroups and count a number of projects with shared runners option enabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import gitlab | |
gl = gitlab.Gitlab('http://gitlab.com', private_token="<put your private token here>") | |
GROUP_ID = '1234567890' | |
total_projects_count = 0 | |
def get_projects_with_shared_runners_enabled(group_id): | |
global total_projects_count | |
group = gl.groups.get(group_id) | |
enabled = [] | |
print(f"Fetching groups for group {group.attributes['full_name']}") | |
for subgroup in group.subgroups.list(all=True): | |
enabled += get_projects_with_shared_runners_enabled(subgroup.get_id()) | |
group_projects = group.projects.list() | |
total_projects_count += len(group_projects) | |
enabled += [ | |
{'Name': p.attributes['name_with_namespace'], 'ID': p.attributes['id']} | |
for p in group_projects | |
if p.attributes['shared_runners_enabled'] | |
] | |
return enabled | |
projects = get_projects_with_shared_runners_enabled(GROUP_ID) | |
print(f"Total projects with enabled shared runners: {len(projects)}/{total_projects_count}") | |
print(json.dumps(projects, indent=' ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment