Merge every green Dependabot PR in one command (and the trap that merges untested code)
DEV Community

Merge every green Dependabot PR in one command (and the trap that merges untested code)

Stop merging 20 green PRs by hand. You only need 1 command.

Monday morning, a stack of dependency pull requests, most of them green. Opening each one to click merge is twenty minutes of nothing. We've all done it.

The command

gh pr list --author "app/dependabot" --state open \
  --json number,statusCheckRollup \
  --jq '.[] | select((.statusCheckRollup | length) > 0 and all(.statusCheckRollup[]; (.conclusion // .state) == "SUCCESS")) | .number' \
  | xargs -n1 gh pr merge --squash

What it does:

  • lists open PRs opened by Dependabot (swap the author for Renovate or your own bot),
  • keeps those where every check run (conclusion) and every commit status (state) is SUCCESS,
  • merges each one.

The trap: length > 0

Without that line, a PR with no checks at all passes all(...), because "all of nothing" is true. It's how a batch script merges a PR whose CI never ran: a workflow that didn't trigger, a path filter that skipped it, a new repo with no CI yet.

Two more rules

  • Re-check right before merging. A check can fail between the list and the merge, or a new commit can land. gh pr merge respects branch protection, so turn on required status checks and the merge refuses anything that isn't green.
  • Only version bumps. Never batch-merge a PR that changes code. A migration deserves a person reading it, even when it's green.

If a check reports NEUTRAL or SKIPPED, this command leaves the PR alone. That's on purpose: we'd decide those by hand, and so should you.

The button version

In Versyka it's one button on Overview, "Merge all that passed CI". You tick which pull requests to merge, and each is checked again on GitHub right before it merges, up to 20 per click.

How many dependency PRs are open in your main repo right now?

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.