GitHub View Source

Git Shortlog reviewed-by

17 Nov 2020 in Tech

Whilst reading the git 2.29 release notes there was one section in particular that caught my eye. git shortlog added the ability to group commits by a trailer, such as Co-authored-by, Committed-by or Reviewed-by.

That is, until Git 2.29! In this release, git shortlog learned a new --group argument, to specify how commits are grouped and assigned credit. It takes --group=author (the default behavior from before) and --group=committer (equivalent to git shortlog -c), but it also accepts a --group=trailer:argument.

Passing the latter allows us to group commits by their co-authors, and it also allows for more creative uses. If your project is using the Reviewed-by trailer, you can use git shortlog to see who is reviewing the most patches:

$ git shortlog -ns --group=trailer:reviewed-by v2.28.0.. | head -n5 40 Eric Sunshine 10 Taylor Blau 4 brian m. carlson 2 Elijah Newren 1 Jeff King

This made me think that it would be great to see who is reviewing most of our pull requests as it’s a very important job, but it’s not as visible to the rest of the team.

Like a lot of teams, we use GitHub for code reviews, and we’re heavily invested in GitHub Actions. I took a look at the available events and saw pull_request_review, which I could use to automatically update the pull request description to contain a Reviewed-by trailer whenever a review was added. Combined with Squash and merge this provides a way to add the Reviewed-by trailer with zero effort from the team.

Usage

If you want to use this yourself, you can find it on the Actions Marketplace. Here’s an example workflow that enables the action:

yaml
name: PR Review
on: pull_request_review
jobs:
review:
name: Reviewed-by Trailer
runs-on: ubuntu-latest
steps:
- name: Debug
uses: mheap/reviewed-by-trailer-action@v1
env:
GITHUB_TOKEN: $
with:
states: approved,changed_requested

And here’s how it looks once it’s run:

Example Trailer

The action is just 40 lines of code, and 260 lines of tests. Another example where a little automation can go a long way with GitHub Actions!