Files
check-naming/check.sh
T
architectandClaude Fable 5 9bfbd24461
test / test (pull_request) Successful in 4s
v2: fail (exit 1) on naming violation
The four wired repos flip the naming job to a required status check
(agenthub#557 WS6); a check that always exits 0 can never gate. v2 makes
the script exit nonzero with FAIL lines; warn-only stays available via
job-level continue-on-error or the legacy @v1 tag. dfritz break-glass
exemption unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-26 18:05:26 +00:00

60 lines
1.8 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 missing [${BRANCH_BUG}] prefix for branch '${BRANCH}'"
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}"