Add CI check for issue references in commit messages#419
Merged
Conversation
52727b8 to
e97a14d
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new CI job to enforce that pull request commit messages reference a GitHub issue (with a few allowed exceptions), helping keep commit history consistently traceable to issues.
Changes:
- Add a
check-commit-messagesjob that scans all commits in a PR and fails CI if any commit message lacks an issue reference. - Define allowed reference patterns (
#123or full issue URL) and exception prefixes (e.g.,Bump,Merge,Revert,fixup!).
Comments suppressed due to low confidence (3)
.github/workflows/ci.yml:40
- Using
echo "$msg"can misbehave for certain commit messages (e.g., ones starting with-n), sinceechomay treat that as an option and change output. Useprintf '%s\n' "$msg"(or similar) to reliably pass the message togrep.
msg=$(git log -1 --format="%B" "$sha")
first_line=$(git log -1 --format="%s" "$sha")
if ! echo "$msg" | grep -qP "$pattern"; then
echo "::error::Commit message missing issue reference: $first_line"
.github/workflows/ci.yml:37
- The commit range
"$BASE_SHA".."$HEAD_SHA"assumes the base SHA is an ancestor of the head SHA. If the PR branch is behind base (or history diverged), this range can miss commits or include an unexpected set. Consider computing the merge-base first (e.g.,git merge-base "$BASE_SHA" "$HEAD_SHA") and using that as the start of the range to reliably get all PR commits.
for sha in $(git log --format="%H" "$BASE_SHA".."$HEAD_SHA"); do
msg=$(git log -1 --format="%B" "$sha")
.github/workflows/ci.yml:40
- The regex is applied to the full multi-line commit message (
%B). Because^matches the start of any line, a commit could pass by having an exception token (e.g.,Merge) in the body even if the subject doesn't qualify. If the intent is to allow exceptions only based on the subject, check the exception patterns againstfirst_line(or usegrep -qPzwith\Aanchors).
pattern='(#[0-9]+|github\.com/[^/]+/[^/]+/issues/[0-9]+|^Bump |^Merge |^Revert |^fixup! |^squash! |^amend! )'
failed=0
for sha in $(git log --format="%H" "$BASE_SHA".."$HEAD_SHA"); do
msg=$(git log -1 --format="%B" "$sha")
first_line=$(git log -1 --format="%s" "$sha")
if ! echo "$msg" | grep -qP "$pattern"; then
echo "::error::Commit message missing issue reference: $first_line"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e97a14d to
d8c02d8
Compare
sadhana-r
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes it a CI requirement to reference in issue number in each commit message (in the title or body of the message).