-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetArchive.py
More file actions
48 lines (35 loc) · 1.51 KB
/
Copy pathSetArchive.py
File metadata and controls
48 lines (35 loc) · 1.51 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
#!/usr/bin/env python3
"""
Archive GitHub repos for a user/organization with repo names matching pattern.
It is NOT possible to unarchive via API, you would have to UNarchive by hand:
https://developer.github.com/v3/repos/#input
Requires GitHub Oauth login with
permissions "repo:public_repo" or "repo" for private repos.
"""
from argparse import ArgumentParser
import gitbulk as gb
def main():
p = ArgumentParser(description="Set GitHub repos to Archive matching pattern")
p.add_argument("user", help="GitHub username / organizations")
p.add_argument("oauth", help="Oauth filename")
p.add_argument("pattern", help="archive repos with name starting with this string")
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)
to_act = [repo for repo in repos if repo.name.startswith(P.pattern) and not repo.archived]
if not to_act:
raise SystemExit(f"There were no repos left to archive with {P.pattern} in {P.user}")
print("NOTE: presently, you can only UNarchive through the website manually.")
print("\ntype yes to ARCHIVE (make read-only)", "\n".join([repo.full_name for repo in to_act]))
if input() != "yes":
raise SystemExit("Aborted")
for repo in to_act:
repo.edit(archived=True)
print("archived", repo.full_name)
if __name__ == "__main__":
main()