Last active
March 14, 2021 08:12
-
-
Save hos/626050f266b4752fd3052bc4bcbd0f12 to your computer and use it in GitHub Desktop.
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
// RECOMMENDED: Disconnect HEROKU from Github before doing this (though not strictly necessary, I think). | |
//See https://stackoverflow.com/a/61272173/6569950 for more info. | |
// PARAMETERS | |
const TOKEN = ""; // MUST BE `repo_deployments` authorized | |
const REPO = ""; // e.g. "repository" | |
const USER_OR_ORG = ""; // e.g. "your-name" | |
// GLOBAL VARS | |
const URL = `https://api.github.com/repos/${USER_OR_ORG}/${REPO}/deployments`; | |
const AUTH_HEADER = `token ${TOKEN}`; | |
// UTILITY FUNCTIONS | |
const getAllDeployments = () => | |
fetch(`${URL}`, { headers: { authorization: AUTH_HEADER } }).then( | |
async val => { | |
if (val.status !== 200) { | |
throw await val.json(); | |
} | |
val.json(); | |
} | |
); | |
const makeDeploymentInactive = id => | |
fetch(`${URL}/${id}/statuses`, { | |
method: "POST", | |
body: JSON.stringify({ state: "inactive" }), | |
headers: { | |
"Content-Type": "application/json", | |
Accept: "application/vnd.github.ant-man-preview+json", | |
authorization: AUTH_HEADER | |
} | |
}).then(() => id); | |
const deleteDeployment = id => | |
fetch(`${URL}/${id}`, { | |
method: "DELETE", | |
headers: { authorization: AUTH_HEADER } | |
}) | |
.then(res => res.json()) | |
.then(console.log); | |
const main = async () => { | |
const all = await getAllDeployments(); | |
console.log(`${all.length} deployments found`); | |
for (const deployment of all) { | |
const inactive = await makeDeploymentInactive(deployment.id); | |
console.log("inactive", inactive); | |
const deleted = await deleteDeployment(id); | |
console.log("deleted", deleted); | |
} | |
}; | |
main().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment