From d36daaa4dbbaa3823d5c8587d7cbe093c6b6dcbd Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Mon, 7 Nov 2022 18:33:25 -0800 Subject: feat(tools/import-gh-to-gitea): a script to archive repositories --- tools/import-gh-to-gitea/archive-projects.py | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 tools/import-gh-to-gitea/archive-projects.py 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) -- cgit 1.4.1