From f5d99ea6534c4e2a1d82b48fabc38eb7b220785f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 9 Aug 2022 13:10:04 +0200 Subject: [PATCH] github/add_to_private: add flags to be more reusable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- github/add_to_private.py | 45 +++++++++++++++++++++++++++++++++++ github/add_user_to_private.py | 22 ----------------- 2 files changed, 45 insertions(+), 22 deletions(-) create mode 100755 github/add_to_private.py delete mode 100755 github/add_user_to_private.py 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')