Last active
September 20, 2020 18:09
-
-
Save D3strukt0r/568bc979e29fef9aa0e9d12215d50d34 to your computer and use it in GitHub Desktop.
Inactives and deletes all deployments on a repository
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 | |
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