-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (26 loc) · 902 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// @ts-check
/** @type boolean */
let hasDeleteRepoScope;
/**
* An Octoherd script to delete repositories
*
* @param {import('@octoherd/cli').Octokit} octokit
* @param {import('@octoherd/cli').Repository} repository
*/
export async function script(octokit, repository) {
if (!hasDeleteRepoScope) {
const { headers } = await octokit.request("HEAD /");
const scopes = new Set(headers["x-oauth-scopes"].split(", "));
if (!scopes.has("delete_repo")) {
throw new Error(
`The "delete_repo" scope is required for this script. Create a token at https://github.com/settings/tokens/new?scopes=delete_repo then run the script with "-T <paste token here>"`
);
}
hasDeleteRepoScope = true;
}
await octokit.request("DELETE /repos/{owner}/{repo}", {
owner: repository.owner.login,
repo: repository.name,
});
octokit.log.info("Repository deleted");
}