Git
R packages
Best practices
Foundations series · part 3

Conventional commits & PR title checks

Make every line of history mean something, to people and to tools

Structure commit messages and PR titles to automate changelogs and trace changes back to requirements.
Published

2026-09-26

Modified

2026-09-27

The problem

Look at the history of most R repos and you’ll see update, fix, wip, final version, final version 2. The code may be excellent, but the history can’t answer basic questions:

  • What changed for users since the last release?
  • Which change broke something?
  • Does this release need a major, minor or patch version bump?

In a GxP setting the same history is also part of your change-control evidence. “fix” is not an adequate change description.

The standard: Conventional Commits

Conventional Commits is a tiny grammar for the first line of a commit message:

<type>(<optional scope>)<optional !>: <description>
Type Use it for Version effect
feat A new user-facing capability minor
fix A bug fix patch
docs Documentation only none
test Tests only none
refactor Code change with no behaviour change none
perf Faster, same behaviour patch
build, ci, chore, style, revert Tooling, CI, housekeeping none
! after the type, or a BREAKING CHANGE: footer Breaks existing code major

R examples:

feat(km_plot): add risk table below the curve
fix(read_adsl): keep labels when reading xpt files
docs: add vignette on ARD-based tables
feat!: require R >= 4.3

Scopes are free text. In an R package, use the function or module name, so that git log --grep "(km_plot)" finds every change to that function.

The key idea: with squash-merge, the PR title is the commit

If a repo allows only squash merges (git workflow), each PR lands on main as one commit, and GitHub uses the PR title as that commit’s message:

# Repo setting, once (needs admin rights on the repo)
gh api -X PATCH repos/OWNER/REPO \
  -F allow_squash_merge=true -F allow_merge_commit=false -F allow_rebase_merge=false \
  -f squash_merge_commit_title=PR_TITLE -f squash_merge_commit_message=PR_BODY

So the commits on your branch can stay informal (“try another approach”). What matters is the PR title, and that’s what you should check automatically.

The web-repo way

Two layers:

  1. Locally, commitlint runs in a commit-msg git hook (via husky) and rejects a bad message before the commit exists.
  2. In CI, a workflow checks the PR title on every edit:
# .github/workflows/pr-title.yml
on:
  pull_request:
    types: [opened, edited, reopened, synchronize]
permissions:
  pull-requests: read
jobs:
  conventional-title:
    runs-on: ubuntu-latest
    steps:
      - uses: amannn/action-semantic-pull-request@v6
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

We tested this with a throwaway PR titled updated the readme. The check failed with “No release type found in pull request title”, while a PR titled docs: clean PR probe passed. Because the workflow also runs on edited, renaming a PR re-runs the check without a new commit.

The R way

The CI layer needs no Node at all. pr-title.yml is a hosted action, so you can drop the same file into any R package or Shiny repo: templates/github/workflows/pr-title.yml.

# Drop into .github/workflows/ of an R package or Shiny app repo.
# With squash-merge, the PR title becomes the commit on main, so check it here.
# No Node or npm needed in the R repo: this is a hosted action.
name: pr-title

on:
  pull_request:
    types: [opened, edited, reopened, synchronize]

permissions:
  pull-requests: read

jobs:
  conventional-title:
    runs-on: ubuntu-latest
    steps:
      - uses: amannn/action-semantic-pull-request@v6
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

For the local layer, skip commitlint. Pulling Node into an R package just for this isn’t worth it. A 15-line shell hook does the same job, and usethis installs it. Save templates/git-hooks/commit-msg in your project root as commit-msg:

#!/bin/sh
# Conventional Commits check for repos without Node (R packages, Shiny apps).
# Install from R:  usethis::use_git_hook("commit-msg", readLines("commit-msg"))
first_line=$(head -n 1 "$1")
case "$first_line" in
  Merge\ *|Revert\ *|fixup!\ *|squash!\ *) exit 0 ;;
esac
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9_./-]+\))?!?: .+'
if printf '%s' "$first_line" | grep -Eq "$pattern"; then
  exit 0
fi
echo "✖ Commit message is not a Conventional Commit:" >&2
echo "    $first_line" >&2
echo "  Expected: <type>(<optional scope>): <description>" >&2
echo "  e.g.  feat(read_adsl): support SAS transport files" >&2
echo "        fix: handle empty data in km_plot()" >&2
exit 1
usethis::use_git_hook(
  "commit-msg",
  readLines("commit-msg")
)

We tested the hook against these messages:

Message Result
feat(read_adsl): support xpt files ✓
feat!: drop R 4.1 support ✓
Merge branch 'main' ✓ (merges and reverts are let through)
updated stuff ✗
Feat: capitalised type ✗
feat:missing space ✗
NoteHooks are local and optional; CI is the gate

Git hooks live in .git/hooks/, which is never committed, so every clone has to install them. Treat the local hook as a convenience that catches mistakes early. The PR title check in CI is the actual rule, because nobody can skip it.

What you get in return

  • A readable history: git log --oneline reads like a changelog.
  • Automatic version bumps and NEWS/CHANGELOG entries. Tools read feat/fix/! to decide the next version (releases & changelogs).
  • Faster review: the title tells the reviewer what kind of change to expect.
  • Better change-control evidence: each change on main has a type, a scope, a description and a linked PR with its review and CI results.

Pitfalls

  • The title check only runs when the PR changes. It’s triggered by edited, so after renaming a PR the check re-runs by itself, and you don’t need to push again.
  • Squash settings are per repo. New repos default to allowing all three merge methods. Set squash-only when you create the repo.
  • Don’t over-engineer scopes. Free-text function names beat a mandated list nobody remembers.
  • Merge commits from git pull would fail a strict hook. The template lets Merge … and Revert … through, and pull.rebase = true avoids them anyway.

Sources

Standards and tools

R package documentation

NoteUpdates
  • 2026-09-26: Removed the end-of-post checklist.
  • 2026-09-27: Added a Sources section.
  • 2026-09-27: Linked every template file and showed it on the page.