Compare commits
@@ -0,0 +1,52 @@
|
||||
name: Check PR & Commit Length
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, edited, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
validate-length:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check PR Title, Description & Commits
|
||||
env:
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
PR_BODY: ${{ github.event.pull_request.body }}
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
MAX_TITLE: 72
|
||||
MAX_DESC: 500
|
||||
run: |
|
||||
# 1. Check PR Title & Description (important when using Squash Merge)
|
||||
if [ ${#PR_TITLE} -gt $MAX_TITLE ]; then
|
||||
echo "❌ PR Title too long (${#PR_TITLE}/$MAX_TITLE characters)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ${#PR_BODY} -gt $MAX_DESC ]; then
|
||||
echo "❌ PR Description too long (${#PR_BODY}/$MAX_DESC characters)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Check each commit inside PR (important when using Merge Commit / Rebase)
|
||||
for commit in $(git rev-list "$BASE_SHA..$HEAD_SHA"); do
|
||||
c_title=$(git log -n 1 --format=%s "$commit")
|
||||
c_body=$(git log -n 1 --format=%b "$commit")
|
||||
|
||||
if [ ${#c_title} -gt $MAX_TITLE ]; then
|
||||
echo "❌ Commit $commit has Title too long ${#c_title}/$MAX_TITLE characters."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ${#c_body} -gt $MAX_DESC ]; then
|
||||
echo "❌ Commit $commit has Description too long ${#c_body}/$MAX_DESC characters."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "✅ Passed the length requirements!"
|
||||
Reference in new issue
Block a user