Skip to content

Instantly share code, notes, and snippets.

@hassy
Created June 8, 2024 14:20
Show Gist options
  • Save hassy/71bf33eb00035ed459eaa98d621bee60 to your computer and use it in GitHub Desktop.
Save hassy/71bf33eb00035ed459eaa98d621bee60 to your computer and use it in GitHub Desktop.
Bulk delete GitHub issues through the GraphQL API
// Usage: create a personal GitHub token, export it as GH_PAT environment variable, and run this script
// It will print a list of ids + titles of the most recent 25 issues and ask for confirmation before deleting
import {
graphql
} from "@octokit/graphql";
import * as readline from "node:readline";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const {
repository
} = await graphql(
`
{
repository(owner: "artilleryio", name: "artillery") {
issues(last: 25) {
edges {
node {
id
title
number
}
}
}
}
}
`, {
headers: {
authorization: `token ${process.env.GH_PAT}`,
},
},
);
for (const e of repository.issues.edges) {
const id = e.node.id;
const title = e.node.title;
console.log(id, title);
}
rl.question('Delete all issues above? Type "yes" to confirm, "no" or Ctrl+C to cancel: ', async (input) => {
if (input === 'yes') {
for (const e of repository.issues.edges) {
const id = e.node.id;
await graphql(`
mutation($issueId: ID!) {
deleteIssue(input: {issueId: $issueId}) {
clientMutationId
}
}
`, {
headers: {
authorization: `token ${process.env.GH_PAT}`
},
issueId: id
});
console.log('deleted', id);
}
} else {
console.log('exiting without doing anything');
}
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment