Created
February 1, 2018 22:21
-
-
Save ruimaranhao/aa32e8719f15dd9a084fe9b6601aec52 to your computer and use it in GitHub Desktop.
Bulk delete of GitHub repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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