Skip to content

Instantly share code, notes, and snippets.

@CodeShakingSheep
Created June 18, 2023 11:45
Show Gist options
  • Save CodeShakingSheep/65a7f46ab6067a72835e13b8459c0f7d to your computer and use it in GitHub Desktop.
Save CodeShakingSheep/65a7f46ab6067a72835e13b8459c0f7d to your computer and use it in GitHub Desktop.
Revert import of 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 delete $(wc -w <<< "$GET_REPOS") repositories? " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
for URL in $GET_REPOS; do
REPO_NAME=$(echo $URL | sed 's#.*/##')
echo "Deleting $REPO_NAME if it exists on Gitea ..."
curl -X DELETE "$GITEA_DOMAIN/api/v1/repos/$GITEA_REPO_OWNER/$name" -u $GITEA_USERNAME:$GITEA_TOKEN -H "accept: application/json"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment