Created
July 8, 2024 23:46
-
-
Save garentyler/53165c3bcbd2376d4ac3a4a5a851c45e to your computer and use it in GitHub Desktop.
Helper script to migrate from GitHub to self-hosted Gitea
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
#!/bin/bash | |
# Modified from https://dev.to/nicolasboyer/migrate-all-of-your-repos-from-github-to-gitea-3fk | |
# https://github.com/settings/tokens | |
GITHUB_USERNAME= | |
GITHUB_TOKEN= | |
# https://$GITEA_DOMAIN/user/settings/applications | |
GITEA_USERNAME= | |
GITEA_TOKEN= | |
GITEA_DOMAIN= | |
GET_REPOS=$(curl -H 'Accept: application/vnd.github.v3+json' -u $GITHUB_USERNAME:$GITHUB_TOKEN -s "https://api.github.com/users/$GITHUB_USERNAME/repos?per_page=200&type=all" | jq -r '.[].html_url') | |
for URL in $GET_REPOS; do | |
REPO_NAME=$(echo $URL | awk -F '/' '{print $NF}') | |
echo "Importing $REPO_NAME from $URL" | |
curl -X POST "https://$GITEA_DOMAIN/api/v1/repos/migrate" -u $GITEA_USERNAME:$GITEA_TOKEN -H "accept: application/json" -H "Content-Type: application/json" -d "{ \ | |
\"auth_username\": \"$GITHUB_USERNAME\", \ | |
\"auth_password\": \"$GITHUB_TOKEN\", \ | |
\"clone_addr\": \"$URL\", \ | |
\"mirror\": false, \ | |
\"private\": true, \ | |
\"repo_name\": \"$REPO_NAME\", \ | |
\"repo_owner\": \"$GITEA_USERNAME\", \ | |
\"service\": \"git\", \ | |
\"uid\": 0, \ | |
\"wiki\": true}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment