73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
import requests
|
|
import time
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables from .env file
|
|
load_dotenv()
|
|
|
|
# --- CONFIGURACIÓN ---
|
|
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
|
|
GITEA_TOKEN = os.getenv("GITEA_TOKEN")
|
|
GITEA_API_URL = os.getenv("GITEA_API_URL", "https://git.mguz.dev/api/v1")
|
|
GITEA_UID = int(os.getenv("GITEA_UID", "1"))
|
|
|
|
if not GITHUB_TOKEN or not GITEA_TOKEN:
|
|
print("❌ Error: GITHUB_TOKEN and GITEA_TOKEN must be set in .env file")
|
|
exit(1)
|
|
|
|
headers_gh = {"Authorization": f"token {GITHUB_TOKEN}"}
|
|
headers_gt = {
|
|
"Authorization": f"token {GITEA_TOKEN}",
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
|
|
def migrate_repos():
|
|
# 1. Obtener todos tus repositorios de GitHub (incluye privados)
|
|
# Usamos paginación por si tenés muchos
|
|
print("Obteniendo lista de repositorios desde GitHub...")
|
|
gh_repos_url = "https://api.github.com/user/repos?per_page=100"
|
|
response = requests.get(gh_repos_url, headers=headers_gh)
|
|
|
|
if response.status_code != 200:
|
|
print(f"Error al conectar con GitHub: {response.text}")
|
|
return
|
|
|
|
repos = response.json()
|
|
print(f"Se encontraron {len(repos)} repositorios.")
|
|
|
|
# 2. Iterar y enviar a Gitea
|
|
for repo in repos:
|
|
repo_name = repo["name"]
|
|
clone_url = repo["clone_url"]
|
|
is_private = repo["private"]
|
|
|
|
print(f"Migrando: {repo_name}...", end=" ")
|
|
|
|
data = {
|
|
"clone_addr": clone_url,
|
|
"mirror": True, # Mantiene sincronizado con GitHub
|
|
"repo_name": repo_name,
|
|
"service": "github",
|
|
"auth_token": GITHUB_TOKEN,
|
|
"uid": GITEA_UID,
|
|
"private": is_private,
|
|
}
|
|
|
|
res = requests.post(
|
|
f"{GITEA_API_URL}/repos/migrate", headers=headers_gt, json=data
|
|
)
|
|
|
|
if res.status_code == 201:
|
|
print("✅ OK")
|
|
elif res.status_code == 409:
|
|
print("⚠️ Ya existe en Gitea")
|
|
else:
|
|
print(f"❌ Error {res.status_code}: {res.text}")
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
migrate_repos() |