Skip to content

Commit 4ff3be8

Browse files
Add CI check for issue references in commit messages
#337
1 parent 5ed3231 commit 4ff3be8

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,38 @@ env:
1717
FORCE_COLOR: 3
1818

1919
jobs:
20+
check-commit-messages:
21+
name: Check commit messages
22+
runs-on: ubuntu-latest
23+
if: github.event_name == 'pull_request'
24+
steps:
25+
- uses: actions/checkout@v6
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Check all PR commits reference a GitHub issue
30+
env:
31+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
32+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
33+
run: |
34+
pattern='(#[0-9]+|github\.com/[^/]+/[^/]+/issues/[0-9]+|^Bump |^Merge |^Revert |^fixup! |^squash! |^amend! )'
35+
failed=0
36+
for sha in $(git log --format="%H" "$BASE_SHA".."$HEAD_SHA"); do
37+
msg=$(git log -1 --format="%B" "$sha")
38+
first_line=$(git log -1 --format="%s" "$sha")
39+
if ! printf '%s\n' "$msg" | grep -qP "$pattern"; then
40+
echo "::error::Commit ${sha::7} missing issue reference: $first_line"
41+
failed=1
42+
fi
43+
done
44+
45+
if [ "$failed" -eq 1 ]; then
46+
echo ""
47+
echo "Every commit must reference a GitHub issue (e.g., #123 or full issue URL)."
48+
echo "Exceptions: Bump, Merge, Revert, fixup!, squash!, amend! commits."
49+
exit 1
50+
fi
51+
2052
pre-commit:
2153
name: Format
2254
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)