Skip to content

Commit a2d2f52

Browse files
committed
Split commit message checks into individual scripts
Split check-commit-messages.sh into three focused scripts: - check-title-length.sh: title must be <= 80 chars - check-no-fixup.sh: no fixup/squash/WIP commits - check-commit-body.sh: body required for 20+ line changes All scripts skip merge commits via --no-merges to avoid false positives on GitHub's auto-generated merge commit titles.
1 parent 133267b commit a2d2f52

5 files changed

Lines changed: 98 additions & 58 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# Check that commits with 20+ lines changed include a non-empty body.
3+
# Skips merge commits.
4+
#
5+
# Usage: check-commit-body.sh <base-sha>
6+
set -euo pipefail
7+
8+
base="${1:?Usage: check-commit-body.sh <base-sha>}"
9+
errors=0
10+
11+
for commit in $(git log --no-merges --format=%H "${base}..HEAD"); do
12+
short=$(git log -1 --format=%h "$commit")
13+
body=$(git log -1 --format=%b "$commit")
14+
15+
lines_changed=$(git diff-tree --no-commit-id --numstat -r "$commit" \
16+
| awk '{ s += $1 + $2 } END { print s+0 }')
17+
body_trimmed=$(echo "$body" | sed '/^$/d' | head -1)
18+
19+
if [ "$lines_changed" -ge 20 ] && [ -z "$body_trimmed" ]; then
20+
echo "::error::Commit $short: $lines_changed lines changed but no commit body."
21+
echo " Commits with 20+ lines changed should include a description."
22+
errors=$((errors + 1))
23+
fi
24+
done
25+
26+
if [ "$errors" -gt 0 ]; then
27+
echo "Found $errors commit(s) missing a body."
28+
exit 1
29+
fi
30+
31+
echo "All large commits have a body."

.github/scripts/pr-hygiene/check-commit-messages.sh

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
# Check that no fixup/squash/WIP commits remain in the PR.
3+
# Skips merge commits.
4+
#
5+
# Usage: check-no-fixup.sh <base-sha>
6+
set -euo pipefail
7+
8+
base="${1:?Usage: check-no-fixup.sh <base-sha>}"
9+
errors=0
10+
11+
for commit in $(git log --no-merges --format=%H "${base}..HEAD"); do
12+
subject=$(git log -1 --format=%s "$commit")
13+
short=$(git log -1 --format=%h "$commit")
14+
15+
case "$subject" in
16+
fixup!*|squash!*|WIP:*|WIP\ *|wip:*|wip\ *)
17+
echo "::error::Commit $short: fixup/squash/WIP commits must be cleaned up before merge."
18+
echo " Title: $subject"
19+
errors=$((errors + 1))
20+
;;
21+
esac
22+
done
23+
24+
if [ "$errors" -gt 0 ]; then
25+
echo "Found $errors fixup/WIP commit(s)."
26+
exit 1
27+
fi
28+
29+
echo "No fixup/squash/WIP commits found."
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
# Check that commit titles do not exceed 80 characters.
3+
# Skips merge commits.
4+
#
5+
# Usage: check-title-length.sh <base-sha>
6+
set -euo pipefail
7+
8+
base="${1:?Usage: check-title-length.sh <base-sha>}"
9+
errors=0
10+
11+
for commit in $(git log --no-merges --format=%H "${base}..HEAD"); do
12+
subject=$(git log -1 --format=%s "$commit")
13+
short=$(git log -1 --format=%h "$commit")
14+
15+
title_len=${#subject}
16+
if [ "$title_len" -gt 80 ]; then
17+
echo "::error::Commit $short: title is $title_len chars (max 80)."
18+
echo " Title: $subject"
19+
errors=$((errors + 1))
20+
fi
21+
done
22+
23+
if [ "$errors" -gt 0 ]; then
24+
echo "Found $errors title length error(s)."
25+
exit 1
26+
fi
27+
28+
echo "All commit titles are within 80 characters."

.github/workflows/pr-hygiene.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ jobs:
2727
- uses: actions/checkout@v6
2828
with:
2929
fetch-depth: 0
30-
- name: Verify commit message quality
30+
- name: Check title length
3131
run: >
32-
.github/scripts/pr-hygiene/check-commit-messages.sh
32+
.github/scripts/pr-hygiene/check-title-length.sh
33+
"${{ github.event.pull_request.base.sha }}"
34+
- name: Check no fixup/WIP commits
35+
run: >
36+
.github/scripts/pr-hygiene/check-no-fixup.sh
37+
"${{ github.event.pull_request.base.sha }}"
38+
- name: Check commit body on large changes
39+
run: >
40+
.github/scripts/pr-hygiene/check-commit-body.sh
3341
"${{ github.event.pull_request.base.sha }}"

0 commit comments

Comments
 (0)