Skip to content

Instantly share code, notes, and snippets.

@CodeShakingSheep
Created June 18, 2023 11:42
Show Gist options
  • Save CodeShakingSheep/5dc2cf6ac3b6d265218a7214f8f1210b to your computer and use it in GitHub Desktop.
Save CodeShakingSheep/5dc2cf6ac3b6d265218a7214f8f1210b to your computer and use it in GitHub Desktop.
Import organisation or user repositories from GitHub to Gitea based on https://dev.to/nicolasboyer/migrate-all-of-your-repos-from-github-to-gitea-3fk
#!/bin/bash
GITHUB_USERNAME=
GITHUB_TOKEN=
GITHUB_ORGANISATION=
GITHUB_API_CALL=
GITEA_USERNAME=
GITEA_TOKEN=
GITEA_DOMAIN=
GITEA_REPO_OWNER=
if [ -z "$GITHUB_ORGANISATION" ]
then
echo "\$GITHUB_ORGANISATION is empty"
GITHUB_API_CALL=https://api.github.com/user/repos?per_page=100
else
echo "\$GITHUB_ORGANISATION is NOT empty"
GITHUB_API_CALL=https://api.github.com/orgs/$GITHUB_ORGANISATION/repos?per_page=200&type=all
fi
GET_REPOS=$(curl -H 'Accept: application/vnd.github.v3+json' -H "Authorization: token $GITHUB_TOKEN" $GITHUB_API_CALL | jq -r '.[].html_url')
read -p "Do you want to import $(wc -w <<< "$GET_REPOS") repositories? " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
for URL in $GET_REPOS; do
REPO_NAME=$(echo $URL | sed 's#.*/##')
echo "Found $REPO_NAME, importing..."
curl -X POST "$GITEA_DOMAIN/api/v1/repos/migrate" -H "accept: application/json" -H "Authorization: token $GITEA_TOKEN" -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_REPO_OWNER\", \
\"service\": \"git\", \
\"uid\": 0, \
\"wiki\": true}"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment