Remove an organization from Git


When I was busy with a late spring-cleaning, I thought it to be a good idea to remove some old repositories from my Git server.

At home I am running Forgejo and when I want to remove a complete organization, I need to click and type a lot.

But Forgejo, just as Gitea has a wonderful API, so, why not use that??

I saw this at Justyns site and I stole ^W borrowed this script.

Remove all repos in an organization
#!/bin/bash

# Change these
GIT_URL=https://git.example.net
GIT_USER=jane
GIT_TOKEN=xxxx

ORG_NAME=Example

# List all repositories in the organization
repos=$(curl -s -u $GIT_USER:$GIT_TOKEN "$GIT_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.
    echo "^^^ Remove this line and the next if you
    echo "^^^ are really sure you want to delete
    echo "^^^ _ALL_ repos in $ORG_NAME"
    continue

    curl -s -u $GIT_USER:$GIT_TOKEN -X DELETE "$GIT_URL/api/v1/repos/$ORG_NAME/$repo"
done

echo "All repositories have been deleted."
sysadm 

See also