Migrating from GitHub to a Gitea

To migrate all your GitHub projects (both private and public) to a Gitea instance (may work with gogs aswell - not tested) you can use the attached script below. It uses the Gitea API to start a migration for every projcet as returned by the GitHub API. You will need to generate a token at Github and Gitea for this to work.

By default it imports every repository as private because of a bug in Gitea which exposes private repositories in users' public activity feeds if the repository has been made private after the initial import.

set -x


for url in `curl -u "$GITHUB_USERNAME:$GITHUB_TOKEN"
  --url https://api.github.com/user/repos?per_page=500 | jq -r '.[] | "\(.clone_url)"'`; do

  name=`echo $url | rev | cut -d'/' -f1 | rev | rev | cut -c 5- | rev`
  curl --header "Authorization: token $GITEA_TOKEN" --request POST \
    --url https://$GITEA_DOMAIN/api/v1/repos/migrate --header 'content-type: application/json' \
    --data "{\"clone_addr\": \"$url\",
             \"uid\": 1,
             \"repo_name\": \"$name\",
             \"auth_username\": \"$GITEA_USERNAME\",
             \"auth_password\": \"$GITEA_TOKEN\",
             \"private\": true}"

Further reading