Created
March 4, 2019 23:51
-
-
Save donkirkby/b95538e6cfacb16cb7b6633fd2dac80e to your computer and use it in GitHub Desktop.
Summarize access to an organization's repositories on GitHub.
This file contains 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
""" | |
Summarize access to an organization's repositories on GitHub. | |
Run a query like this on the GitHub explorer: | |
https://developer.github.com/v4/explorer/ | |
{ | |
organization(login: "your-org") { | |
name | |
repositories(first: 100) { | |
edges { | |
node { | |
name | |
collaborators(first: 100) { | |
edges { | |
permission | |
node { | |
login | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
Then save the results in organization.json. | |
""" | |
from __future__ import print_function | |
import json | |
from collections import defaultdict | |
with open('organization.json') as f: | |
response = json.load(f) | |
admin_access = defaultdict(list) # {login: [repo_name]} | |
organization = response['data']['organization'] | |
print('Organization:', organization['name']) | |
repositories = {repository['node']['name']: repository | |
for repository in organization['repositories']['edges']} | |
for repository_name, repository in sorted(repositories.items()): | |
user_levels = defaultdict(list) # {level: [login]} | |
collaborators = repository['node']['collaborators']['edges'] | |
for collaborator in collaborators: | |
user_levels[collaborator['permission']].append(collaborator['node']['login']) | |
print(repository_name) | |
for user_level, users in sorted(user_levels.items()): | |
print(' ', user_level + ':', ', '.join(sorted(users))) | |
for user_name in user_levels['ADMIN']: | |
admin_access[user_name].append(repository_name) | |
print() | |
print('Administrator access:') | |
for user_name, repository_names in sorted(admin_access.items()): | |
print(user_name) | |
print(' ', ', '.join(repository_names)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment