Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions validator.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ]]
}
2 changes: 1 addition & 1 deletion validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:$"
Expand Down
Loading