Skip to content

Commit 99083da

Browse files
chore(validator): handle empty options as unset
Because there is no other way for github action.
1 parent d33bd38 commit 99083da

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ in `.git/hooks` directory of your repository.
199199

200200
### OPTIONS
201201

202-
- if `COMMIT_VALIDATOR_NO_JIRA` environment variable is set, no validation is done on JIRA refs.
203-
- if `COMMIT_VALIDATOR_ALLOW_TEMP` environment variable is set, no validation is done on `fixup!` and `squash!` commits.
202+
- if `COMMIT_VALIDATOR_NO_JIRA` environment variable is not empty, no validation is done on JIRA refs.
203+
- if `COMMIT_VALIDATOR_ALLOW_TEMP` environment variable is not empty, no validation is done on `fixup!` and `squash!` commits.
204204

205205
## Getting Started with github action
206206

Diff for: validator.bats

+23-8
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,26 @@ BROKEN:
264264
[ "$status" -eq $ERROR_HEADER ]
265265
}
266266

267-
@test "header overall should allow fixup if env set" {
268-
COMMIT_VALIDATOR_ALLOW_TEMP= validate_header "fixup! plopezrr"
267+
@test "header overall should allow fixup if env not empty" {
268+
COMMIT_VALIDATOR_ALLOW_TEMP=1 validate_header "fixup! plopezrr"
269269
[[ $GLOBAL_TYPE == "temp" ]]
270270
}
271271

272-
@test "header overall should allow squash if env set" {
273-
COMMIT_VALIDATOR_ALLOW_TEMP= validate_header "squash! plopezrr"
272+
@test "header overall should allow squash if env not empty" {
273+
COMMIT_VALIDATOR_ALLOW_TEMP=1 validate_header "squash! plopezrr"
274274
[[ $GLOBAL_TYPE == "temp" ]]
275275
}
276276

277+
@test "header overall should reject fixup if env empty" {
278+
COMMIT_VALIDATOR_ALLOW_TEMP= run validate_header "fixup! plopezrr"
279+
[[ "$status" -eq $ERROR_HEADER ]]
280+
}
281+
282+
@test "header overall should reject squash if env empty" {
283+
COMMIT_VALIDATOR_ALLOW_TEMP= run validate_header "squash! plopezrr"
284+
[[ "$status" -eq $ERROR_HEADER ]]
285+
}
286+
277287
@test "header overall should reject fixup if env not set" {
278288
run validate_header "fixup! plopezrr"
279289
[[ "$status" -eq $ERROR_HEADER ]]
@@ -480,9 +490,14 @@ LUM-2345'
480490
[[ `need_jira "fix"` -eq 1 ]]
481491
}
482492

483-
@test "features and fixes commits don't need jira reference if set" {
484-
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "feat"` -eq 0 ]]
485-
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "fix"` -eq 0 ]]
493+
@test "features and fixes commits need jira reference if env empty" {
494+
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "feat"` -eq 1 ]]
495+
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "fix"` -eq 1 ]]
496+
}
497+
498+
@test "features and fixes commits don't need jira reference if env non empty" {
499+
[[ `COMMIT_VALIDATOR_NO_JIRA=1 need_jira "feat"` -eq 0 ]]
500+
[[ `COMMIT_VALIDATOR_NO_JIRA=1 need_jira "fix"` -eq 0 ]]
486501
}
487502

488503
@test "other commits don't need jira reference" {
@@ -665,7 +680,7 @@ BROKEN:
665680
- plop
666681
- plop'
667682

668-
COMMIT_VALIDATOR_ALLOW_TEMP= run validate "$MESSAGE"
683+
COMMIT_VALIDATOR_ALLOW_TEMP=1 run validate "$MESSAGE"
669684
[[ "$status" -eq 0 ]]
670685
}
671686

Diff for: validator.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ validate_overall_structure() {
125125
validate_header() {
126126
local HEADER="$1"
127127

128-
if [[ -v COMMIT_VALIDATOR_ALLOW_TEMP && $HEADER =~ $TEMP_HEADER_PATTERN ]]; then
128+
if [[ ! -z "${COMMIT_VALIDATOR_ALLOW_TEMP:-}" && $HEADER =~ $TEMP_HEADER_PATTERN ]]; then
129129
GLOBAL_TYPE="temp"
130130
elif [[ $HEADER =~ $REVERT_HEADER_PATTERN ]]; then
131131
GLOBAL_TYPE="revert"
@@ -211,7 +211,7 @@ validate_trailing_space() {
211211
need_jira() {
212212
local TYPE=$1
213213

214-
if [[ -v COMMIT_VALIDATOR_NO_JIRA ]]; then
214+
if [[ ! -z "${COMMIT_VALIDATOR_NO_JIRA:-}" ]]; then
215215
echo 0
216216
else
217217
case $TYPE in

0 commit comments

Comments
 (0)