TIL to close GitHub PRs with the gh CLI!
I have a post archival automation where I archive social posts (from x, bsky etc.) sent through my posting software, to my blog . This is done via automated prs, which I review and close manually. What happened was that I took a break from posting and in that period, the pull requests were created with malformed & non-significant boilerplate content (I fixed that too!).
Now, I had like 30+ pull requests with junk. I wanted to close them all quickly. But, the GitHub UI is slow and it’s annoying to open a pr, close it and move to the next pr.
So, I used the gh cli tool to bulk close all prs made by the automation author with a certain pattern that’s unique to my use-case.
The command is as follows:
gh pr list --state open --json number,files,author \
| jq -r '.[] | select(.files | length == 2) | select(.author.login == "app/github-actions") | .number' \
| xargs -n1 -I {} gh pr close {} --comment "Auto-closing PRs with minimal changes from this author."
🔧 Remember: default page size is 30, use --limit 1000 for better results!
I learned about this command tool through @ChatGPT!