Last active
June 20, 2026 18:00
-
-
Save phixion/742e2f1f6e4458563a84f6943dcc68c3 to your computer and use it in GitHub Desktop.
migrate to codeberg
This file contains hidden or 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
| #variables | |
| #gh token, scope repo: https://github.com/settings/tokens | |
| #cb token: https://codeberg.org/user/settings/applications | |
| export GH_TOKEN="token" | |
| export CB_TOKEN="token" | |
| export GH_USER="user" | |
| #get gh repos | |
| curl -s -H "Authorization: token $GH_TOKEN" \ | |
| "https://api.github.com/user/repos?per_page=100&affiliation=owner" \ | |
| | jq -r '.[].name' > repos.txt | |
| #read repos.txt and clode to codeberg | |
| while IFS= read -r REPO; do | |
| if [ -z "$REPO" ]; then continue; fi # Skip empty lines | |
| echo "migrating: $REPO..." | |
| RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X 'POST' \ | |
| 'https://codeberg.org/api/v1/repos/migrate' \ | |
| -H 'accept: application/json' \ | |
| -H "Authorization: token $CB_TOKEN" \ | |
| -H 'Content-Type: application/json' \ | |
| -d "{ | |
| \"clone_addr\": \"https://github.com/$GH_USER/$REPO.git\", | |
| \"auth_token\": \"$GH_TOKEN\", | |
| \"repo_name\": \"$REPO\", | |
| \"service\": \"github\", | |
| \"mirror\": false, | |
| \"issues\": true, | |
| \"pull_requests\": true, | |
| \"releases\": true, | |
| \"wiki\": true | |
| }") | |
| if [ "$RESPONSE" -eq 201 ]; then | |
| echo "queued migration: $REPO" | |
| else | |
| echo "failed migration: $REPO (HTTP Status: $RESPONSE)" | |
| fi | |
| echo "----------------------------------------" | |
| sleep 2 # Small pause to avoid aggressive rate limiting | |
| done < repos.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment