Created
October 29, 2021 16:42
-
-
Save kristof-mattei/8150bca62a032b1e85741e15f1e9fc13 to your computer and use it in GitHub Desktop.
Clean up all workflow runs.
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
const { Octokit } = require("@octokit/rest"); | |
const { serializeError } = require("serialize-error"); | |
const octokit = new Octokit({ | |
auth: "PUT TOKEN HERE" | |
}); | |
const baseRef = { | |
owner: "Kristof-Mattei", | |
repo: "rust-integrity-playground" | |
}; | |
async function delete_workflow_run_or_err(run_id) { | |
try { | |
await octokit.rest.actions.deleteWorkflowRun({ | |
...baseRef, | |
run_id: run_id | |
}); | |
console.log(`Deleted ${run_id}.`); | |
} | |
catch (e) { | |
console.log(`Couldn't delete ${run_id}, error returned.`); | |
return e; | |
} | |
} | |
class AggregateError extends Error { | |
constructor(message, errors = []) { | |
super(message); | |
this.name = "ValidationError"; | |
this.innerErrors = errors; | |
} | |
} | |
(async () => { | |
try { | |
let runs = []; | |
do { | |
runs = await octokit.rest.actions.listWorkflowRunsForRepo({ | |
...baseRef, | |
per_page: 20, | |
}) | |
let run_ids = runs.data.workflow_runs.map(e => e.id); | |
let errors = (await Promise.all(run_ids.map(delete_workflow_run_or_err))).filter(e => e != null); | |
if (null !== errors && errors.length !== 0) { | |
throw new AggregateError("Aggregation of errors of this delete run, check innerErrors", errors); | |
} | |
} while (runs.data.workflow_runs.length !== 0); | |
console.log("Done!"); | |
} catch (e) { | |
console.log("Check the fan, something hit it."); | |
console.error(serializeError(e)); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment