Skip to content

Commit 9055752

Browse files
committed
feat(validator): add body length parameter
1 parent e046333 commit 9055752

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ Then run `pre-commit install --hook-type commit-msg` to install the
316316
- if `no-revert-sha1` is set, no validation is done on revert commits.
317317
- if `--jira-in-header` jira reference can be put in the commit header.
318318
- `--header-length` allow to override the max length of the header line.
319+
- `--body-length` allow to override the max length of body lines.
319320
- `--jira-types` takes a space separated list `"feat fix"` as a parameter to override the default types requiring a jira
320321

321322
<!-- ROADMAP -->

Diff for: action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ inputs:
1919
header_length:
2020
description: 'If not empty, max header_length'
2121
required: false
22+
body_length:
23+
description: 'If not empty, max body_length'
24+
required: false
2225
jira_types:
2326
description: 'If not empty, space separated list of types that require Jira refs'
2427
required: false
@@ -46,5 +49,6 @@ runs:
4649
COMMIT_VALIDATOR_NO_REVERT_SHA1: ${{ inputs.no_revert_sha1 }}
4750
GLOBAL_JIRA_TYPES: ${{ inputs.jira_types }}
4851
GLOBAL_MAX_LENGTH: ${{ inputs.header_length }}
52+
GLOBAL_BODY_MAX_LENGTH: ${{ inputs.body_length }}
4953
GLOBAL_JIRA_IN_HEADER: ${{ inputs.jira_in_header }}
5054
shell: bash

Diff for: check_message.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
set -eu
44

5-
OPTIONS=$(getopt --longoptions no-jira,allow-temp,jira-in-header,header-length:,jira-types: --options "" -- "$@")
6-
unset COMMIT_VALIDATOR_ALLOW_TEMP COMMIT_VALIDATOR_NO_JIRA COMMIT_VALIDATOR_NO_REVERT_SHA1 GLOBAL_JIRA_IN_HEADER GLOBAL_MAX_LENGTH GLOBAL_JIRA_TYPES
5+
OPTIONS=$(getopt --longoptions no-jira,allow-temp,jira-in-header,header-length,body-length:,jira-types: --options "" -- "$@")
6+
unset COMMIT_VALIDATOR_ALLOW_TEMP COMMIT_VALIDATOR_NO_JIRA COMMIT_VALIDATOR_NO_REVERT_SHA1 GLOBAL_JIRA_IN_HEADER GLOBAL_MAX_LENGTH GLOBAL_BODY_MAX_LENGTH GLOBAL_JIRA_TYPES
77

88
eval set -- $OPTIONS
99
while true; do
@@ -13,6 +13,7 @@ while true; do
1313
--no-revert-sha1 ) COMMIT_VALIDATOR_NO_REVERT_SHA1=1; shift ;;
1414
--jira-in-header ) GLOBAL_JIRA_IN_HEADER=1; shift ;;
1515
--header-length ) GLOBAL_MAX_LENGTH="$2"; shift 2 ;;
16+
--body-length ) GLOBAL_BODY_MAX_LENGTH="$2"; shift 2 ;;
1617
--jira-types ) GLOBAL_JIRA_TYPES="$2"; shift 2 ;;
1718
-- ) shift; break ;;
1819
* ) break ;;

Diff for: validator.bats

+4
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ LUM-2345'
457457
[[ "$status" -eq 0 ]]
458458
}
459459

460+
@test "body length cannot be more than 150 with spaces. overridden" {
461+
GLOBAL_BODY_MAX_LENGTH=150 validate_body_length "012345678 012345678 012345678 012345678 012345678 012345678 012345678 1"
462+
}
463+
460464
@test "body with trailing space on line should not be valid" {
461465
MESSAGE='pdzofjzf '
462466

Diff for: validator.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ GLOBAL_FOOTER=""
3636
# Overridable variables
3737
GLOBAL_JIRA_TYPES="${GLOBAL_JIRA_TYPES:-feat fix}"
3838
GLOBAL_MAX_LENGTH="${GLOBAL_MAX_LENGTH:-100}"
39+
GLOBAL_BODY_MAX_LENGTH="${GLOBAL_BODY_MAX_LENGTH:-100}"
3940
GLOBAL_JIRA_IN_HEADER="${GLOBAL_JIRA_IN_HEADER:-}"
4041

4142
GLOBAL_TYPE=""
@@ -197,8 +198,8 @@ validate_body_length() {
197198

198199
LENGTH="$(echo -n "$LINE" | wc -c)"
199200

200-
if [[ $LENGTH -gt 100 ]]; then
201-
echo -e "body message line length is more than 100 charaters"
201+
if [[ $LENGTH -gt ${GLOBAL_BODY_MAX_LENGTH} ]]; then
202+
echo -e "body message line length is more than ${GLOBAL_BODY_MAX_LENGTH} characters"
202203
exit $ERROR_BODY_LENGTH
203204
fi
204205
done <<< "$BODY"

0 commit comments

Comments
 (0)