-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListRepos.py
More file actions
49 lines (37 loc) · 1.58 KB
/
Copy pathListRepos.py
File metadata and controls
49 lines (37 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
"""
List all Git repos of a user / organization.
Optionally, open the settings or laerts page for each repo.
For organization private repos, you will need "repo" Oauth permission.
Restricted "Third-party application access policy"
from organization oauth_application_policy settings is OK.
Without Oauth, you will only see public repos
"""
from argparse import ArgumentParser
import webbrowser
import gitbulk as gb
def main():
p = ArgumentParser(description="List user/organization repos")
p.add_argument("user", help="Git remote username / organization name")
p.add_argument("oauth", help="Oauth filename", nargs="?")
p.add_argument("-p", "--pattern", help="only repos with name starting with this string")
p.add_argument("-settings", help="open settings page for each repo", action="store_true")
p.add_argument("-alerts", help="open alerts page for each repo", action="store_true")
P = p.parse_args()
# %% authentication
sess = gb.session(P.oauth)
gb.check_api_limit(sess)
# %% get user / organization handle
userorg = gb.user_or_org(sess, P.user)
# %% prepare to loop over repos
repos = gb.get_repos(userorg)
if P.pattern:
repos = (repo for repo in repos if repo.name.startswith(P.pattern))
for repo in repos:
print(repo.full_name)
if P.settings:
webbrowser.open_new_tab("https://github.com/" + repo.full_name + "/settings")
if P.alerts:
webbrowser.open_new_tab("https://github.com/" + repo.full_name + "/network/alerts")
if __name__ == "__main__":
main()