aboutsummaryrefslogtreecommitdiff
path: root/packages/import-gh-to-gitea/archive-projects.py
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-03-06 06:29:24 -0800
committerFranck Cuny <franck@fcuny.net>2024-03-06 06:29:24 -0800
commit1e4a5aa09c1c8f43722c9c260f011398799a8e8f (patch)
treecd73e0fb8ba53bd21cee6ccf2dcc85639bbbb93f /packages/import-gh-to-gitea/archive-projects.py
parentset correct git email in the profiles (diff)
downloadinfra-1e4a5aa09c1c8f43722c9c260f011398799a8e8f.tar.gz
rename `tools` to `packages` to follow convention
The convention is to use `pkgs` or `packages` for overlays and definition of custom packages. Since I'm already using `pkg` for go, I prefer to use `packages` for my scripts.
Diffstat (limited to 'packages/import-gh-to-gitea/archive-projects.py')
-rwxr-xr-xpackages/import-gh-to-gitea/archive-projects.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/import-gh-to-gitea/archive-projects.py b/packages/import-gh-to-gitea/archive-projects.py
new file mode 100755
index 0000000..41bd898
--- /dev/null
+++ b/packages/import-gh-to-gitea/archive-projects.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import argparse
+
+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)