Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Created May 1, 2020 13:29
Show Gist options
  • Save Luzifer/58b4629b7fcac42883fd751c171d8232 to your computer and use it in GitHub Desktop.
Save Luzifer/58b4629b7fcac42883fd751c171d8232 to your computer and use it in GitHub Desktop.
Delete all repos from certain workspace (username) in Bitbucket
#!/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