Skip to content

Instantly share code, notes, and snippets.

@UrsaDK
Last active May 14, 2020 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UrsaDK/e8192b3ed71328afd374fb65043ec5fc to your computer and use it in GitHub Desktop.
Save UrsaDK/e8192b3ed71328afd374fb65043ec5fc to your computer and use it in GitHub Desktop.
How to remove the "environment" tab from a Github repo
#!/usr/bin/env bash
#
# Remove Project Environment artefacts from a Github project: This script
# can be used to remove all "environment" artefacts from a project that,
# for example, no longer uses github-pages. Doing so would also remove the
# "environment" tab from the Github repository.
#
# The script requires for `curl` and `jq` to be in your PATH. You will also
# need to define a personal access token with `repo_deployment` scope on
# Github, and update the values of API_URL_BASE and ACCESS_TOKEN bellow.
#
# Personal access token can be defined at:
# Settings > Developer settings > Personal access tokens
# ie -- https://github.com/settings/tokens/new
API_URL_BASE="https://api.github.com/repos/USER/REPO"
ACCESS_TOKEN=""
for id in $(curl -sL ${API_URL_BASE}/deployments | jq '.[].id'); do
echo
echo "ID: ${id}"
echo -n " - update state: "
curl -sL \
-H "accept: application/vnd.github.ant-man-preview+json" \
-H "authorization: token ${ACCESS_TOKEN}" \
-X POST -d '{"state":"inactive"}' \
${API_URL_BASE}/deployments/${id}/statuses \
| jq '.state'
echo -n " - delete artefact: "
curl -sL \
-H "authorization: token ${ACCESS_TOKEN}" \
-X DELETE \
${API_URL_BASE}/deployments/${id} \
&& echo "ok"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment