Josh

Building in the open

Releasing gh-pr-staleness: GitHub CLI Extension for Commits Behind Target

Working in a monorepo and with a merge-queue (as we are now doing inside Shopify - I’m grappling with it), it becomes imperative that pull-requests (proposed changes) are compared and tested against the most up-to-date version of the codebase. To ensure tests and reviews are accurate, they need to cross the smallest gap possible.

So, the operators of a merge-queue will often implement staleness checks/guarantees like:

  • PRs can only be merged if they are less than X commits behind the target branch
  • Code will only be tested in CI if it is less than X commits behind main/trunk

So, the engineers need to get into a habit of tracking staleness and proactively rebasing their changes on the active target/trunk. I”m having to do this quite a lot, so I built gh-pr-staleness.

gh-pr-staleness is a GitHub CLI extension that calculates the staleness (how many commits behind TARGET branch) of a pull request.

gh-pr-staleness repo
gh-pr-staleness repo

This is very useful for determining which PRs are actionably mergeable, especially in highly active monorepo or merge-queue environments. It’s simple and fast and easy to use in scripts.

What I also want is for GitHub to display the PR staleness in their actual pull request user interface, but I think they are resistant because it’s kind of an expensive calculation.

This is my second gh extension. Previously released: gh-view-md - A GitHub CLI Extension for LLM-Optimized Issue and PR Viewing

Installation

gh extension install joshbeckman/gh-pr-staleness

That’s it. If you have the GitHub CLI installed and authenticated, you’re ready to go.

gh pr-staleness <github_pr_url_or_number>
# or, if you are on a branch that has a PR already, it will be inferred:
gh pr-staleness

The source is on GitHub with examples and full documentation. Contributions are welcome!

Keyboard Shortcuts

Key Action
o Source
e Edit
i Insight
r Random
h Home
s or / Search
www.joshbeckman.org/blog/practicing/releasing-ghprstaleness-github-cli-extension-for-commits-behind-target