I didn't follow my own advice on https://justyn.io/til/mirror-starred-repositories-from-github-to-gitea-forgejo/ and quickly used up all of the disk space on my small forgejo vm.

I decided this was a problem for another day and wanted to delete everything in my mirrors organization, which is where I mirrored all of the starred repos to. Unfortunately trying to delete an organization from the UI just returns an error due to it still owning repositories.

Instead, I wrote another script to loop through all repos belonging to an organization and delete them.

WARNING: There is no confirmation, this will delete all repos it finds.


# See https://justyn.io/til/delete-all-repos-from-an-organization-in-forgejo-gitea/ for more informataion

# Change these

# List all repositories in the organization
repos=$(curl -s -u $FORGEJO_USER:$FORGEJO_TOKEN "$FORGEJO_URL/api/v1/orgs/$ORG_NAME/repos?limit=100" | jq -r '.[].name')

# Loop through each repository and delete it
for repo in $repos; do
    echo "Deleting repository: $repo"
    echo "^^^ I didn't really delete anything yet.  Remove this line and the next if you are really sure you want to delete _ALL_ repos in $ORG_NAME"
    exit 1
    curl -s -u $FORGEJO_USER:$FORGEJO_TOKEN -X DELETE "$FORGEJO_URL/api/v1/repos/$ORG_NAME/$repo"

echo "All repositories have been deleted."