Batch closing PRs

If you find yourself in the situation where a golem has opened many many PRs, and you need to close them; you can use the web UI, but only 25 at a time.

A better option is to use the GH CLI. Once you’ve done the auth dance, you can list the PRs for a repo, and just return the number (not the id, which is a different thing):

$ gh pr list --json number -L 1
[
  {
    "number": 123
  }
]

You can then add a jq filter, to extract the number from the json blob:

$ gh pr list --json number -q '.[] | .number' -L 1
123

And finally, send each line to a close cmd, using xargs:

$ gh pr list --json number -q '.[] | .number' -L 500 | xargs -I % sh -c 'gh pr close %'
✓ Closed pull request foo/bar#123 (...)
...

Leave a comment