#!/usr/bin/env bash # Branch and PR title naming-standard checker. # Always exits 0 — warn-only until the Bugs system is live and STRICT=1 is set. 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 WARN=0 BRANCH_KIND="invalid" BRANCH_BUG="" # ---- branch form ---- # /bug-/ 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/ elif echo "${BRANCH}" | grep -qE "^chore/[a-z0-9][a-z0-9-]*$"; then BRANCH_KIND="chore" else echo "WARN[check-naming]: branch '${BRANCH}' does not match convention" echo " expected: /bug-/ (role: dev|ux|ops|security|perf|architect|support)" echo " or: chore/" WARN=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 "WARN[check-naming]: title missing [${BRANCH_BUG}] prefix for branch '${BRANCH}'" WARN=1 elif [ "${TITLE_BUG}" != "${BRANCH_BUG}" ]; then echo "WARN[check-naming]: bug-id mismatch — branch carries '${BRANCH_BUG}' but title carries '${TITLE_BUG}'" WARN=1 fi elif [ "${BRANCH_KIND}" = "chore" ] && [ -n "${TITLE_BUG}" ]; then echo "WARN[check-naming]: chore branch should not carry a [bug-id] title prefix" WARN=1 fi if [ "${WARN}" -eq 0 ]; then echo "check-naming: ok" fi exit 0