From ac13a95a2a104011be68f10330135de72fb254dc Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 15 Sep 2023 00:28:41 +0200 Subject: [PATCH] Create mirror.py --- mirror.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 mirror.py diff --git a/mirror.py b/mirror.py new file mode 100644 index 0000000..178a442 --- /dev/null +++ b/mirror.py @@ -0,0 +1,43 @@ +import requests +from dotenv import load_dotenv +import os + +# Lade die .env Datei +load_dotenv() + +GITHUB_USER = os.getenv("GITHUB_USER") +GITEA_USER = os.getenv("GITEA_USER") +GITEA_TOKEN = os.getenv("GITEA_TOKEN") + +GITHUB_URL = f"https://api.github.com/users/{GITHUB_USER}/repos" +GITEA_URL = f"https://git.veen.world/api/v1/users/{GITEA_USER}/repos" +HEADERS = { + "Authorization": f"token {GITEA_TOKEN}" +} + +# Hole die Repos von GitHub +response = requests.get(GITHUB_URL) +response.raise_for_status() +github_repos = {repo['name']: repo['clone_url'] for repo in response.json()} + +# Hole die Repos von Gitea +response = requests.get(GITEA_URL, headers=HEADERS) +response.raise_for_status() +gitea_repos = set(repo['name'] for repo in response.json()) + +# Finde die Repos, die noch nicht auf Gitea gemirrored werden +to_mirror = {name: url for name, url in github_repos.items() if name not in gitea_repos} + +for name, url in to_mirror.items(): + data = { + "clone_url": url, + "mirror": True, + "private": True, + "repo_name": name, + "uid": GITEA_USER + } + response = requests.post(f"https://git.veen.world/api/v1/repos/migrate", headers=HEADERS, json=data) + if response.status_code == 201: + print(f"{name} wurde erfolgreich gemirrored.") + else: + print(f"Fehler beim Mirroring von {name}. Status-Code: {response.status_code}, Antwort: {response.text}")