Files
check-naming/check.sh
T
devandClaude Sonnet 4.6 5d0c72201e
test / test (pull_request) Successful in 6s
fix(check-naming): print corrected title on missing-prefix failure
When a role-bug branch has no [bug-id] prefix in the PR title, the check
now prints what the title should be:

  FAIL[check-naming]: title must lead with [bug-r095xkfgt2vz]
    have: fix(agenthub/bugs): budget unpark quote in bytes not runes
    want: [bug-r095xkfgt2vz] fix(agenthub/bugs): budget unpark quote in bytes not runes

The bug id is already parsed from the branch, so the corrected title is
mechanically derivable — no guesswork needed from the author.

Part of bug-hvhthrwf9ry8

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-25 02:04:17 +00:00

62 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Branch and PR title naming-standard checker.
# v2: exits 1 on violation. Consumers that want warn-only set
# continue-on-error: true on the job (or stay on @v1).
set -euo pipefail
BRANCH="${HEAD_BRANCH:-}"
TITLE="${PR_TITLE:-}"
AUTHOR="${PR_AUTHOR:-}"
# Break-glass: dfritz is exempt from all naming checks.
if [ "${AUTHOR}" = "dfritz" ]; then
echo "check-naming: dfritz break-glass — exempt"
exit 0
fi
FAILED=0
BRANCH_KIND="invalid"
BRANCH_BUG=""
# ---- branch form ----
# <role>/bug-<id>/<kebab>
if echo "${BRANCH}" | grep -qE "^(dev|ux|ops|security|perf|architect|support)/bug-[a-z0-9]+/[a-z0-9][a-z0-9-]*$"; then
BRANCH_KIND="role-bug"
BRANCH_BUG=$(echo "${BRANCH}" | sed -E 's|^[^/]+/(bug-[a-z0-9]+)/.*|\1|')
# chore/<kebab>
elif echo "${BRANCH}" | grep -qE "^chore/[a-z0-9][a-z0-9-]*$"; then
BRANCH_KIND="chore"
else
echo "FAIL[check-naming]: branch '${BRANCH}' does not match convention"
echo " expected: <role>/bug-<id>/<kebab> (role: dev|ux|ops|security|perf|architect|support)"
echo " or: chore/<kebab>"
FAILED=1
fi
# ---- title form ----
TITLE_BUG=""
if echo "${TITLE}" | grep -qE "^\[bug-[a-z0-9]+\] ."; then
TITLE_BUG=$(echo "${TITLE}" | sed -E 's|^\[(bug-[a-z0-9]+)\].*|\1|')
fi
if [ "${BRANCH_KIND}" = "role-bug" ]; then
if [ -z "${TITLE_BUG}" ]; then
echo "FAIL[check-naming]: title must lead with [${BRANCH_BUG}]"
echo " have: ${TITLE}"
echo " want: [${BRANCH_BUG}] ${TITLE}"
FAILED=1
elif [ "${TITLE_BUG}" != "${BRANCH_BUG}" ]; then
echo "FAIL[check-naming]: bug-id mismatch — branch carries '${BRANCH_BUG}' but title carries '${TITLE_BUG}'"
FAILED=1
fi
elif [ "${BRANCH_KIND}" = "chore" ] && [ -n "${TITLE_BUG}" ]; then
echo "FAIL[check-naming]: chore branch should not carry a [bug-id] title prefix"
FAILED=1
fi
if [ "${FAILED}" -eq 0 ]; then
echo "check-naming: ok"
fi
exit "${FAILED}"