Skip to content

Instantly share code, notes, and snippets.

@a2nt
Last active April 15, 2022 18:00
Show Gist options
  • Save a2nt/9601c51584677b0e5f39c40aac9b202a to your computer and use it in GitHub Desktop.
Save a2nt/9601c51584677b0e5f39c40aac9b202a to your computer and use it in GitHub Desktop.
BASH: Move github repositories to gitea
#!/bin/bash
GITHUB_USERNAME=''
GITHUB_TOKEN=''
GITHUB_ORGANISATION=''
GITEA_USERNAME=''
GITEA_TOKEN=''
GITEA_DOMAIN='domain.com'
GITEA_REPO_OWNER=''
echo "Getting github repositories list ..."
# Uncomment to get organization repos:
GET_REPOS=$(curl -H 'Accept: application/vnd.github.v3+json' -u $GITHUB_USERNAME:$GITHUB_TOKEN -s "https://api.github.com/orgs/$GITHUB_ORGANISATION/repos?per_page=200&type=all" | jq -r '.[].html_url')
# Uncomment to get user repos:
#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 | sed "s|https://github.com/$GITHUB_ORGANISATION/||g")
echo "Found $REPO_NAME, importing..."
curl -X POST "https://$GITEA_DOMAIN/api/v1/repos/migrate" -H "Authorization: token $GITEA_TOKEN" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \
\"clone_addr\": \"$URL\", \
\"mirror\": true, \
\"private\": false, \
\"repo_name\": \"$REPO_NAME\" \
}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment