Created
June 8, 2024 14:20
-
-
Save hassy/71bf33eb00035ed459eaa98d621bee60 to your computer and use it in GitHub Desktop.
Bulk delete GitHub issues through the GraphQL API
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
// 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