Created
May 1, 2020 13:29
-
-
Save Luzifer/58b4629b7fcac42883fd751c171d8232 to your computer and use it in GitHub Desktop.
Delete all repos from certain workspace (username) in Bitbucket
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/bash | |
set -euo pipefail | |
username="" | |
apppass="" | |
workspace="${username}" | |
function authcurl() { | |
curl -sSfL -u "${username}:${apppass}" "$@" | |
} | |
apibase="https://api.bitbucket.org/2.0" | |
while [ 1 ]; do | |
repos=($(authcurl "${apibase}/repositories/${workspace}?pagelen=100" | jq -r '.values[] | .full_name')) | |
# Stop on no more repos | |
[ ${#repos[@]} -eq 0 ] && break | |
# Remove repos without further questions | |
for repo in "${repos[@]}"; do | |
authcurl -X DELETE "${apibase}/repositories/${repo}" && echo "Deleted repo ${repo}" || echo "Failed to delete ${repo}" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment