-
Notifications
You must be signed in to change notification settings - Fork 5
/
org_repos.py
executable file
·85 lines (73 loc) · 2.56 KB
/
org_repos.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
"""
Script for outputting all repos in an org
Used primarily as input to repo related scripts - allowing action on all or a subset of an org.
(poor person's rate limiting)
"""
from github3 import login
from github_scripts import utils
def parse_args():
"""
Parse the command line. Only required command is the name of the org.
Detects if no PAT is given, asks for it.
:return: Returns the parsed CLI datastructures.
"""
parser = utils.GH_ArgParser(description="Gets a list of Repos for an Org.")
parser.add_argument("org", help="The GH org to query", action="store", type=str)
parser.add_argument(
"--without-org",
help="Include the org in the name, 'org/repo-name'",
action="store_false",
default=True,
dest="with_org",
)
parser.add_argument(
"--archived",
help="Include archived repos. Default is unarchived only.",
action="store_true",
default=False,
)
parser.add_argument(
"--type",
help="Type of repo: private, public, all.",
default="all",
choices=["public", "private", "all"],
)
parser.add_argument(
"--verbose", help="Add a '*' to the output if the repo is archived", action="store_true"
)
args = parser.parse_args()
return args
def main():
"""
Go through the org, and output all repos, either 'org/repo' or just 'repo'
Defaults to ignoring archived repos.
The PAT needs READ to repos if only public are desired, but read/write
if you want ALL the things.
"""
args = parse_args()
gh_sess = login(token=args.token)
org = gh_sess.organization(args.org)
if args.type == "all":
repolist = org.repositories()
elif args.type == "public":
repolist = org.repositories(type="public")
elif args.type == "private":
repolist = org.repositories(type="private")
else:
raise Exception(f"{args.type} not a known repository visibility type")
for repo in repolist:
if (repo.archived and args.archived) or not repo.archived:
# print(f"{repo.archived=}, {repo.full_name=}, {args.verbose=}")
if args.with_org:
if args.verbose and repo.archived:
print(f"{repo.full_name},*")
else:
print(repo.full_name)
else:
if args.verbose and repo.archived:
print(f"{repo.name},*")
else:
print(repo.name)
if __name__ == "__main__":
main()