Skip to content

Commit 6d183af

Browse files
committed
feat(length): make the length configurable
also better the shell in the function
1 parent 5c8c201 commit 6d183af

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

validator.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ BROKEN:
328328
[ "$status" -eq $ERROR_HEADER_LENGTH ]
329329
}
330330

331+
@test "header length cannot be more than 150 with spaces. overriden" {
332+
GLOBAL_MAX_LENGTH=150 validate_header_length "012345678 012345678 012345678 012345678 012345678 012345678 012345678 1"
333+
}
334+
331335
@test "header length can be 70" {
332336
run validate_header_length "0123456789012345678901234567890123456789012345678901234567890123456789"
333337
[ "$status" -eq 0 ]

validator.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ GLOBAL_HEADER=""
3030
GLOBAL_BODY=""
3131
GLOBAL_JIRA=""
3232
GLOBAL_JIRA_TYPES="${GLOBAL_JIRA_TYPES:-feat fix}"
33+
GLOBAL_MAX_LENGTH="${GLOBAL_MAX_LENGTH:-70}"
3334
GLOBAL_FOOTER=""
3435

3536
GLOBAL_TYPE=""
@@ -142,12 +143,8 @@ validate_header() {
142143

143144
validate_header_length() {
144145
local HEADER="$1"
145-
local LENGTH
146-
147-
LENGTH="$(echo -n "$HEADER" | wc -c)"
148-
149-
if [[ $LENGTH -gt 70 ]]; then
150-
echo -e "commit header length is more than 70 charaters"
146+
if [[ ${#HEADER} -gt ${GLOBAL_MAX_LENGTH} ]]; then
147+
echo -e "commit header length is more than ${GLOBAL_MAX_LENGTH} characters"
151148
exit $ERROR_HEADER_LENGTH
152149
fi
153150
}

0 commit comments

Comments
 (0)