|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +List all GitHub repos of a user / organization. |
| 4 | +Optionally, open the settings or laerts page for each repo. |
| 5 | +
|
| 6 | +For organization private repos, you will need "repo" Oauth permission. |
| 7 | +Restricted "Third-party application access policy" |
| 8 | +from organization oauth_application_policy settings is OK. |
| 9 | +
|
| 10 | +Without Oauth, you will only see public repos |
| 11 | +""" |
| 12 | +from argparse import ArgumentParser |
| 13 | +import webbrowser |
| 14 | +import pygithubutils.base as gb |
| 15 | + |
| 16 | + |
| 17 | +def main(): |
| 18 | + p = ArgumentParser(description="List user/organization repos") |
| 19 | + p.add_argument("user", help="GitHub username / organization name") |
| 20 | + p.add_argument("oauth", help="Oauth filename", nargs="?") |
| 21 | + p.add_argument("-p", "--pattern", help="only repos with name starting with this string") |
| 22 | + p.add_argument("-settings", help="open settings page for each repo", action="store_true") |
| 23 | + p.add_argument("-alerts", help="open alerts page for each repo", action="store_true") |
| 24 | + P = p.parse_args() |
| 25 | + |
| 26 | + # %% authentication |
| 27 | + sess = gb.github_session(P.oauth) |
| 28 | + gb.check_api_limit(sess) |
| 29 | + # %% get user / organization handle |
| 30 | + userorg = gb.user_or_org(sess, P.user) |
| 31 | + # %% prepare to loop over repos |
| 32 | + repos = gb.get_repos(userorg) |
| 33 | + |
| 34 | + if P.pattern: |
| 35 | + repos = (repo for repo in repos if repo.name.startswith(P.pattern)) |
| 36 | + |
| 37 | + for repo in repos: |
| 38 | + print(repo.full_name) |
| 39 | + if P.settings: |
| 40 | + webbrowser.open_new_tab("https://github.com/" + repo.full_name + "/settings") |
| 41 | + if P.alerts: |
| 42 | + webbrowser.open_new_tab("https://github.com/" + repo.full_name + "/network/alerts") |
| 43 | + |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + main() |
0 commit comments