Created
December 28, 2020 22:34
-
-
Save kathleenfrench/a2f3ac08eefcb91a19b7058c57624cc8 to your computer and use it in GitHub Desktop.
delete github deployments by environment name
This file contains hidden or 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 | |
| ## usage: | |
| ## | |
| ## handy script for deleting old deployments by environment name | |
| ## mostly an issue w/ heroku apps that were originally assigned a temporary name | |
| ## | |
| ## ./cleanup.sh username repo env_name token | |
| ## | |
| ## | |
| USERNAME=$1 | |
| REPO=$2 | |
| ENVIRONMENT=$3 | |
| TOKEN=$4 | |
| DEPLOYMENTS=$(curl -s --request GET \ | |
| --url "https://api.github.com/repos/$USERNAME/$REPO/deployments?environment=$ENVIRONMENT" \ | |
| --header "authorization: token $TOKEN" \ | |
| --header 'cache-control: no-cache' \ | |
| --header 'content-type: application/json' | jq .[].id) | |
| echo "" | |
| echo "deployment IDs for environment named: $ENVIRONMENT" | |
| echo "" | |
| ## delete a deployment | |
| ## /repos/{owner}/{repo}/deployments/{deployment_id} | |
| ## see: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#delete-a-deployment | |
| for id in ${DEPLOYMENTS} | |
| do | |
| echo "deleting deployment id $id..." | |
| curl --request DELETE \ | |
| --url "https://api.github.com/repos/$USERNAME/$REPO/deployments/$id" \ | |
| --header "authorization: token $TOKEN" \ | |
| --header 'cache-control: no-cache' | |
| echo "" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment