about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-11-07 18:33:25 -0800
committerFranck Cuny <franck@fcuny.net>2022-11-07 18:33:25 -0800
commitd36daaa4dbbaa3823d5c8587d7cbe093c6b6dcbd (patch)
tree9f0e0198cbbc6389257cab620d47bab0e9cf847b
parentci: replace GitHub actions with drone (diff)
downloadworld-d36daaa4dbbaa3823d5c8587d7cbe093c6b6dcbd.tar.gz
feat(tools/import-gh-to-gitea): a script to archive repositories
Diffstat (limited to '')
-rwxr-xr-xtools/import-gh-to-gitea/archive-projects.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/import-gh-to-gitea/archive-projects.py b/tools/import-gh-to-gitea/archive-projects.py
new file mode 100755
index 0000000..a940bd2
--- /dev/null
+++ b/tools/import-gh-to-gitea/archive-projects.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+import argparse
+import sys
+
+import requests
+
+
+def main(api_token):
+    s = requests.Session()
+    s.headers.update({"Authorization": f"token {api_token}"})
+    s.headers.update({"Accept": "application/json"})
+    s.headers.update({"Content-Type": "application/json"})
+
+    not_done = True
+    page = 1
+    while not_done:
+        url = f"https://git.fcuny.net/api/v1/user/repos?page={page}&limit=10"
+        res = s.get(
+            url,
+            timeout=5,
+        )
+        res.raise_for_status()
+
+        repos = res.json()
+        if len(repos) == 0:
+            not_done = False
+        else:
+            page = page + 1
+
+        for repo in repos:
+            if repo.get("owner").get("login") == "attic":
+                if repo.get("archived") is False:
+                    name = repo.get("name")
+                    data = {"archived": True}
+                    res = s.patch(
+                        f"https://git.fcuny.net/api/v1/repos/attic/{name}", json=data
+                    )
+                    res.raise_for_status()
+                    print(f"set {name} to archived: {res.status_code}")
+
+
+if __name__ == "__main__":
+    argp = argparse.ArgumentParser()
+    argp.add_argument("-t", "--token-file", nargs=1, type=argparse.FileType("r"))
+
+    args = argp.parse_args()
+    api_token = args.token_file[0].readline().strip()
+
+    main(api_token)