Skip to content

Instantly share code, notes, and snippets.

@D3strukt0r
Last active September 20, 2020 18:09
Show Gist options
  • Save D3strukt0r/568bc979e29fef9aa0e9d12215d50d34 to your computer and use it in GitHub Desktop.
Save D3strukt0r/568bc979e29fef9aa0e9d12215d50d34 to your computer and use it in GitHub Desktop.
Inactives and deletes all deployments on a repository
#!/bin/bash
REPO=
TOKEN=
# https://starkandwayne.com/blog/bash-for-loop-over-json-array-using-jq/
for deployment in $(curl https://api.github.com/repos/$REPO/deployments | jq -r '.[] | @base64'); do
DEPLOYMENT_ID=$(echo "$deployment" | base64 --decode | jq -r '.id')
echo "$DEPLOYMENT_ID"
curl "https://api.github.com/repos/$REPO/deployments/$DEPLOYMENT_ID/statuses" \
-X POST \
-d '{"state":"inactive"}' \
-H 'accept: application/vnd.github.ant-man-preview+json' \
-H "authorization: token $TOKEN"
done
for deployment in $(curl https://api.github.com/repos/$REPO/deployments | jq -r '.[] | @base64'); do
DEPLOYMENT_ID=$(echo "$deployment" | base64 --decode | jq -r '.id')
curl "https://api.github.com/repos/$REPO/deployments/$DEPLOYMENT_ID" \
-X DELETE \
-H "authorization: token $TOKEN"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment