Skip to content

Commit

Permalink
chore(validator): handle empty options as unset
Browse files Browse the repository at this point in the history
Because there is no other way for github action.
  • Loading branch information
sebastien-boulle committed Aug 20, 2020
1 parent d33bd38 commit 99083da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ in `.git/hooks` directory of your repository.

### OPTIONS

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

## Getting Started with github action

Expand Down
31 changes: 23 additions & 8 deletions validator.bats
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,26 @@ BROKEN:
[ "$status" -eq $ERROR_HEADER ]
}

@test "header overall should allow fixup if env set" {
COMMIT_VALIDATOR_ALLOW_TEMP= validate_header "fixup! plopezrr"
@test "header overall should allow fixup if env not empty" {
COMMIT_VALIDATOR_ALLOW_TEMP=1 validate_header "fixup! plopezrr"
[[ $GLOBAL_TYPE == "temp" ]]
}

@test "header overall should allow squash if env set" {
COMMIT_VALIDATOR_ALLOW_TEMP= validate_header "squash! plopezrr"
@test "header overall should allow squash if env not empty" {
COMMIT_VALIDATOR_ALLOW_TEMP=1 validate_header "squash! plopezrr"
[[ $GLOBAL_TYPE == "temp" ]]
}

@test "header overall should reject fixup if env empty" {
COMMIT_VALIDATOR_ALLOW_TEMP= run validate_header "fixup! plopezrr"
[[ "$status" -eq $ERROR_HEADER ]]
}

@test "header overall should reject squash if env empty" {
COMMIT_VALIDATOR_ALLOW_TEMP= run validate_header "squash! plopezrr"
[[ "$status" -eq $ERROR_HEADER ]]
}

@test "header overall should reject fixup if env not set" {
run validate_header "fixup! plopezrr"
[[ "$status" -eq $ERROR_HEADER ]]
Expand Down Expand Up @@ -480,9 +490,14 @@ LUM-2345'
[[ `need_jira "fix"` -eq 1 ]]
}

@test "features and fixes commits don't need jira reference if set" {
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "feat"` -eq 0 ]]
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "fix"` -eq 0 ]]
@test "features and fixes commits need jira reference if env empty" {
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "feat"` -eq 1 ]]
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "fix"` -eq 1 ]]
}

@test "features and fixes commits don't need jira reference if env non empty" {
[[ `COMMIT_VALIDATOR_NO_JIRA=1 need_jira "feat"` -eq 0 ]]
[[ `COMMIT_VALIDATOR_NO_JIRA=1 need_jira "fix"` -eq 0 ]]
}

@test "other commits don't need jira reference" {
Expand Down Expand Up @@ -665,7 +680,7 @@ BROKEN:
- plop
- plop'

COMMIT_VALIDATOR_ALLOW_TEMP= run validate "$MESSAGE"
COMMIT_VALIDATOR_ALLOW_TEMP=1 run validate "$MESSAGE"
[[ "$status" -eq 0 ]]
}

Expand Down
4 changes: 2 additions & 2 deletions validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ validate_overall_structure() {
validate_header() {
local HEADER="$1"

if [[ -v COMMIT_VALIDATOR_ALLOW_TEMP && $HEADER =~ $TEMP_HEADER_PATTERN ]]; then
if [[ ! -z "${COMMIT_VALIDATOR_ALLOW_TEMP:-}" && $HEADER =~ $TEMP_HEADER_PATTERN ]]; then
GLOBAL_TYPE="temp"
elif [[ $HEADER =~ $REVERT_HEADER_PATTERN ]]; then
GLOBAL_TYPE="revert"
Expand Down Expand Up @@ -211,7 +211,7 @@ validate_trailing_space() {
need_jira() {
local TYPE=$1

if [[ -v COMMIT_VALIDATOR_NO_JIRA ]]; then
if [[ ! -z "${COMMIT_VALIDATOR_NO_JIRA:-}" ]]; then
echo 0
else
case $TYPE in
Expand Down

0 comments on commit 99083da

Please sign in to comment.