Created
May 14, 2022 01:46
-
-
Save samuelko123/a67e7e56fd4e80e18b3597f77bd5be39 to your computer and use it in GitHub Desktop.
delete github deployments
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
const axios = require('axios') | |
const user = '<your username>' | |
const repo = '<your repo>' | |
const personal_access_token = '<your token>' // with repo_deployment access | |
const url = `https://api.github.com/repos/${user}/${repo}/deployments` | |
const auth = { | |
username: user, | |
password: personal_access_token, | |
} | |
axios.get(url, { auth: auth }) | |
.then(res => { | |
const arr = res.data | |
arr.forEach(deployment => { | |
make_inactive(deployment.id) | |
}) | |
}) | |
.catch(err => console.error(err)) | |
async function make_inactive(deployment_id) { | |
const url = `https://api.github.com/repos/${user}/${repo}/deployments/${deployment_id}/statuses` | |
const body = { | |
state: 'inactive' | |
} | |
const auth = { | |
username: user, | |
password: personal_access_token, | |
} | |
axios.post(url, body, { auth: auth }) | |
.then(res => delete_deployment(deployment_id)) | |
.catch(err => console.error(err)) | |
} | |
async function delete_deployment(deployment_id) { | |
const url = `https://api.github.com/repos/${user}/${repo}/deployments/${deployment_id}` | |
const auth = { | |
username: user, | |
password: personal_access_token, | |
} | |
axios.delete(url, { auth: auth }) | |
.then(res => console.log(`deleted: ${deployment_id}`)) | |
.catch(err => console.error(err.response.data)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment