Skip to content

Instantly share code, notes, and snippets.

@ruimaranhao
Created February 1, 2018 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruimaranhao/aa32e8719f15dd9a084fe9b6601aec52 to your computer and use it in GitHub Desktop.
Save ruimaranhao/aa32e8719f15dd9a084fe9b6601aec52 to your computer and use it in GitHub Desktop.
Bulk delete of GitHub repositories
#!/bin/sh
set -x
# For it to work, you need to install
# -- jq, https://stedolan.github.io/jq/
# -- http, https://httpie.org/
if [ "$#" -ne 1 ]; then
echo "Usage: $0 AUTORIZATION_TOKEN" >&2
exit 1
fi
#Token needs to have repo deletion permissions.
TOKEN=$1
URL=https://api.github.com/orgs
ORG=tecnico-softeng
REG_EXPR="es17.*-project"
echo "Fetching repos (${REG_EXPR})"
repos=`http $URL/$ORG/repos "Authorization:token ${TOKEN}" | jq '.[].full_name' | egrep ${REG_EXPR}`
echo "Deleteing repos..."
for r in $repos
do
name=`echo $r | tr -d '"'`
`http DELETE https://api.github.com/repos/$name "Authorization:token $TOKEN"`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment