diff --git a/github/add_to_private.py b/github/add_to_private.py new file mode 100755 index 0000000..9588bf7 --- /dev/null +++ b/github/add_to_private.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +import os +from github import Github +from optparse import OptionParser + +HELP_DESCRIPTION='This a utility for adding accounts to private GitHub repos.' +HELP_EXAMPLE='Example: ./add_to_private.py -o "waku-org" -u "status-im-auto"' + +def parse_opts(): + parser = OptionParser(description=HELP_DESCRIPTION, epilog=HELP_EXAMPLE) + parser.add_option('-o', '--org', default='status-im', + help='GitHub organization to search for private repos.') + parser.add_option('-u', '--user', default='status-im-bot', + help='GitHub user to grant access to private repos found.') + parser.add_option('-p', '--perm', default='pull', + help='Permission to give to GitHub user to private repo.') + parser.add_option('-t', '--token', default=os.environ['GH_TOKEN'], + help='GitHub API token to query for repos.') + + return parser.parse_args() + +def main(): + (opts, args) = parse_opts() + + gh = Github(opts.token) + + org = gh.get_organization(opts.org) + + for repo in org.get_repos(): + skip = any([ + repo.fork, + repo.archived, + not repo.private, + repo.name.endswith('-pass'), + repo.name.contains('-ghsa-'), + ]) + if skip: + continue + + print(' - %s' % repo.name) + repo.add_to_collaborators(opts.user, permission=opts.perm) + +if __name__ == '__main__': + main() diff --git a/github/add_user_to_private.py b/github/add_user_to_private.py deleted file mode 100755 index 07aff4c..0000000 --- a/github/add_user_to_private.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python3 -import os -from github import Github - -gh = Github(os.environ['GH_TOKEN']) - -org = gh.get_organization('status-im') - -#print("Scopes:", gh.oauth_scopes) - -for repo in org.get_repos(): - skip = any([ - repo.fork, - repo.archived, - not repo.private, - repo.name.endswith('-pass'), - ]) - if skip: - continue - - print(repo) - repo.add_to_collaborators('status-im-auto', permission='pull')