Last active
March 22, 2025 10:41
-
-
Save matijaoe/58783776de00e3247a60f525f00ea886 to your computer and use it in GitHub Desktop.
github to gitea import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# GitHub → Gitea Mirror Import Script | |
# - Imports all GitHub repos (paginated) | |
# - Creates Gitea mirrors with sync enabled | |
# REQUIRED TOKEN PERMISSIONS: | |
# GitHub Token: | |
# - Contents (Read-only) | |
# - Metadata (Read-only) | |
# - Read org membership (if needed) | |
# - Issues, PRs, Wiki, Releases (optional) | |
# Gitea Token: | |
# - admin: Read & Write | |
# - repo: Read & Write | |
# - user: Read & Write (optional) | |
# CONFIGURATION (edit these) | |
GITEA_URL="http://your.gitea.host:port" | |
GITEA_TOKEN="your_gitea_token_here" | |
GITEA_USER="your_gitea_username" | |
GITHUB_TOKEN="your_github_token_here" | |
# Fetch all GitHub repos using pagination | |
repos="" | |
page=1 | |
while :; do | |
resp=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/user/repos?per_page=100&page=$page") | |
page_repos=$(echo "$resp" | jq -r '.[].clone_url') | |
[ -z "$page_repos" ] && break | |
repos="$repos $page_repos" | |
page=$((page + 1)) | |
done | |
# Embed GitHub token into HTTPS clone URLs | |
repos=$(echo "$repos" | sed "s#https://#https://$GITHUB_TOKEN@#") | |
# Import each repo into Gitea | |
for repo in $repos; do | |
name=$(basename -s .git "$repo") | |
echo "Importing $name..." | |
curl -s -X POST "$GITEA_URL/api/v1/repos/migrate" \ | |
-H "Authorization: token $GITEA_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"clone_addr": "'"$repo"'", | |
"uid": 0, | |
"repo_name": "'"$name"'", | |
"mirror": true, // enables auto-sync from GitHub | |
"mirror_interval": "8h", // sets sync frequency (e.g. "8h", "1h", "30m") | |
"private": true, // makes the Gitea repo private | |
"lfs": true, // enable Git LFS support if needed | |
"issues": true, | |
"pull_requests": true, | |
"wiki": true, | |
"releases": true | |
}' | |
echo "$name imported as mirror." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment