From 7cae75a6e1c4de5935e4694fbee236e5bef99181 Mon Sep 17 00:00:00 2001 From: Guillaume Cornut Date: Fri, 4 Sep 2026 11:00:20 +0200 Subject: [PATCH] fix(validator): accept JIRA keys that contain digits The old pattern required all letters before all digits. A key such as A11Y-160 mixes them, so the validator rejected it. The new pattern needs one uppercase letter first. It then accepts letters and digits in any order. It stays a superset of the old pattern, so LUM-1234 and LUM12-345 remain valid. --- validator.bats | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ validator.sh | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/validator.bats b/validator.bats index 201f382..ffb92ee 100644 --- a/validator.bats +++ b/validator.bats @@ -121,6 +121,50 @@ ABC-1234 DE-1234" [[ $GLOBAL_FOOTER == "" ]] } +@test "structure: valid commit message with header and JIRA key holding digits" { + COMMIT="plop plop + +A11Y-160" + + validate_overall_structure "$COMMIT" + [[ $GLOBAL_HEADER == "plop plop" ]] + [[ $GLOBAL_BODY == "" ]] + [[ $GLOBAL_JIRA == "A11Y-160" ]] + [[ $GLOBAL_FOOTER == "" ]] +} + +@test "structure: valid commit message with JIRA key holding digits in header" { + COMMIT="feat(abc): A11Y-160 + +plop" + + GLOBAL_JIRA_IN_HEADER="allow" validate_overall_structure "$COMMIT" + [[ $GLOBAL_HEADER == "feat(abc): A11Y-160" ]] + [[ $GLOBAL_JIRA == "A11Y-160" ]] + [[ $GLOBAL_BODY == "plop"$'\n' ]] + [[ $GLOBAL_FOOTER == "" ]] +} + +@test "structure: lowercase JIRA key is not a JIRA reference" { + COMMIT="plop plop + +a11y-160" + + validate_overall_structure "$COMMIT" + [[ $GLOBAL_JIRA == "" ]] + [[ $GLOBAL_BODY == "a11y-160"$'\n' ]] +} + +@test "structure: JIRA key must start with a letter" { + COMMIT="plop plop + +11Y-160" + + validate_overall_structure "$COMMIT" + [[ $GLOBAL_JIRA == "" ]] + [[ $GLOBAL_BODY == "11Y-160"$'\n' ]] +} + @test "structure: valid commit message with header and broken" { COMMIT="plop plop @@ -743,3 +787,34 @@ BROKEN: run validate "$MESSAGE" [[ "$status" -eq $ERROR_HEADER ]] } + +@test "overall validation with JIRA key holding digits" { + MESSAGE='feat(scope1): subject + +Commit about stuff + +A11Y-160' + + run validate "$MESSAGE" + [[ "$status" -eq 0 ]] +} + +@test "overall validation with long JIRA key holding digits" { + MESSAGE='fix(scope1): subject + +Commit about stuff + +LUM12-345' + + run validate "$MESSAGE" + [[ "$status" -eq 0 ]] +} + +@test "overall validation rejects lowercase JIRA key" { + MESSAGE='feat(scope1): subject + +a11y-160' + + run validate "$MESSAGE" + [[ "$status" -eq $ERROR_JIRA ]] +} diff --git a/validator.sh b/validator.sh index 56931fa..7f50e1b 100644 --- a/validator.sh +++ b/validator.sh @@ -2,7 +2,7 @@ readonly HEADER_PATTERN="^([^\(]+)\(([^\)]+)\): (.+)$" readonly TYPE_PATTERN="^(feat|fix|docs|gen|lint|refactor|test|chore)$" readonly SCOPE_PATTERN="^([a-z][a-z0-9]*)(-[a-z0-9]+)*$" readonly SUBJECT_PATTERN="^([A-Za-z0-9].*[^ ^\.])$" -readonly JIRA_PATTERN="[A-Z]{2,7}[0-9]{0,6}-[0-9]{1,6}" +readonly JIRA_PATTERN="[A-Z][A-Z0-9]{1,12}-[0-9]{1,6}" readonly JIRA_FOOTER_PATTERN="^(${JIRA_PATTERN} ?)+$" readonly JIRA_HEADER_PATTERN="^.*[^A-Z](${JIRA_PATTERN}).*$" readonly BROKE_PATTERN="^BROKEN:$"