Conventional commits & PR title checks
Make every line of history mean something, to people and to tools
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_BODYSo 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:
- Locally,
commitlintruns in acommit-msggit hook (viahusky) and rejects a bad message before the commit exists. - 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.
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:
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 1usethis::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 |
✗ |
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 --onelinereads 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
mainhas 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 pullwould fail a strict hook. The template letsMerge …andRevert …through, andpull.rebase = trueavoids them anyway.
Sources
Standards and tools
- Conventional Commits: conventionalcommits.org
- commitlint: commitlint.js.org
- husky: typicode.github.io/husky
- amannn/action-semantic-pull-request: github.com/amannn/action-semantic-pull-request
- Squash merging: PR title becomes the commit message: GitHub Docs: Configuring commit squashing for pull requests
R package documentation
- usethis (
use_git_hook()): usethis.r-lib.org
- 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.