From 0e55734bdfc32cbaf21956d5a1c2abba6063633d Mon Sep 17 00:00:00 2001 From: tienbh Date: Thu, 26 Nov 2026 17:49:05 +0700 Subject: [PATCH] ci: Add length validation workflow to enforce PR and commit title/description character limits --- .../scoped_workflows/length-validation.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .gitea/scoped_workflows/length-validation.yaml diff --git a/.gitea/scoped_workflows/length-validation.yaml b/.gitea/scoped_workflows/length-validation.yaml new file mode 100644 index 0000000..370f64e --- /dev/null +++ b/.gitea/scoped_workflows/length-validation.yaml @@ -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!"