From fdd24848cf4a9e66deb180b5ddc63c267fefde74 Mon Sep 17 00:00:00 2001 From: Izan Gil <66965250+SrIzan10@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:54:19 +0100 Subject: [PATCH] init --- .gitignore | 1 + main.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cffcb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.json \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..51fcb3d --- /dev/null +++ b/main.py @@ -0,0 +1,44 @@ +import requests +import json + +with open("config.json") as config_file: + config = json.load(config_file) + +print(config) + +gh_user = config["github"]["user"] +gh_token = config["github"]["token"] +gitea_url = config["gitea"]["url"] +gitea_user = config["gitea"]["user"] +gitea_token = config["gitea"]["token"] + +gh_repo_list = requests.get( + f"https://api.github.com/users/{gh_user}/repos", + headers={"Authorization": f"Bearer {gh_token}"}, +).json() +gh_repo_list = [repo["name"] for repo in gh_repo_list] +gitea_repo_list = requests.get( + f"{gitea_url}/api/v1/users/{gitea_user}/repos", + headers={"Authorization": f"token {gitea_token}"}, +).json() +gitea_repo_list = [repo["name"] for repo in gitea_repo_list] +repos_to_migrate = [repo for repo in gh_repo_list if repo not in gitea_repo_list] + +for repo in repos_to_migrate: + print(f"Migrating {repo}...") + migrate_request = requests.post( + f"{gitea_url}/api/v1/repos/migrate", + headers={"Authorization": f"token {gitea_token}"}, + json={ + "auth_password": gh_token, + "auth_username": gh_user, + "clone_addr": f"https://github.com/{gh_user}/{repo}", + "repo_name": repo, + "mirror": True, + "repo_owner": gitea_user, + }, + ) + print( + "Migrated", + "successfully!" if migrate_request.status_code == 201 else "unsuccessfully!", + )