-
Notifications
You must be signed in to change notification settings - Fork 139
Add git minimum length body count validator #3437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
evallesp
merged 1 commit into
openstack-k8s-operators:main
from
danpawlik:add-commit-message-verify
Nov 6, 2025
+102
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: Check if commit message body is not too short | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, edited, reopened] | ||
|
|
||
| jobs: | ||
| verify-body-length: | ||
| runs-on: ubuntu-latest | ||
| # set as non-voting for now. | ||
| continue-on-error: true | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| repository-projects: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Dump commit message to file | ||
| run: | | ||
| git fetch origin ${{ github.event.pull_request.head.sha }} | ||
| git log -1 --pretty=format:"%B" ${{ github.event.pull_request.head.sha }} > commit-message-file | ||
|
|
||
| - name: Run commit message check | ||
| id: bodylength | ||
| run: | | ||
| set +e | ||
| ./scripts/git-check-commit-body-length.sh commit-message-file > result.log 2>&1 | ||
| EXIT_CODE=$? | ||
| echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT | ||
| cat result.log | ||
|
|
||
| - name: Comment on PR if body length check failed | ||
| if: steps.bodylength.outputs.exit_code != '0' | ||
| uses: peter-evans/create-or-update-comment@v5 | ||
| with: | ||
| issue-number: ${{ github.event.pull_request.number }} | ||
| body-path: ./result.log | ||
| reactions: confused |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/bin/bash | ||
|
|
||
| MSG_FILE="$1" | ||
| MIN_BODY_LEN=10 | ||
|
|
||
| # If no file provided, get latest commit message | ||
| if [ -z "$MSG_FILE" ]; then | ||
| TMP_FILE=$(mktemp) | ||
| git log -1 --pretty=format:"%B" >"$TMP_FILE" | ||
| MSG_FILE="$TMP_FILE" | ||
| fi | ||
|
|
||
| # print commit message | ||
| echo -e "Processing commit message:\n" | ||
| cat "$MSG_FILE" | ||
| echo -e "\nEnd of commit message" | ||
|
|
||
| # 0 = pass, 1 = fail | ||
| FAIL_LENGTH=0 | ||
| FAIL_SIGNED_OFF_BY=0 | ||
|
|
||
| BODY=$(tail -n +3 "$MSG_FILE" | sed '/^\s*#/d' | sed '/^\s*$/d') | ||
| BODY_LEN=$(echo -n "$BODY" | wc -m) | ||
|
|
||
| if [ "$BODY_LEN" -lt "$MIN_BODY_LEN" ]; then | ||
| echo -e "\n\n**WARNING: Commit message body is too short (has $BODY_LEN chars, minimum $MIN_BODY_LEN required).**\n" >&2 | ||
| echo "Please add a detailed explanation after the subject line." >&2 | ||
| FAIL_LENGTH=1 | ||
| fi | ||
|
|
||
| if ! grep -qi '^Signed-off-by:' "$MSG_FILE"; then | ||
| echo -e "\n\n**WARNING: Missing 'Signed-off-by:' line in commit message.**\n" >&2 | ||
| echo "Add: Signed-off-by: Your Name <[email protected]>" >&2 | ||
| FAIL_SIGNED_OFF_BY=1 | ||
| fi | ||
|
|
||
| [ -n "$TMP_FILE" ] && rm -f "$TMP_FILE" | ||
|
|
||
| if [ "$FAIL_LENGTH" -eq 0 ] && [ "$FAIL_SIGNED_OFF_BY" -eq 0 ]; then | ||
| echo "Commit message passes all checks." | ||
| exit 0 | ||
| else | ||
| echo -e "\nSome checks failed. See warnings above.\n" | ||
| exit 1 | ||
| fi | ||
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.
Uh oh!
There was an error while loading. Please reload this page.