From 52d99b46c10c792df3a4c9607d0e8848e00cb2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Boulle?= Date: Fri, 14 Aug 2020 17:31:58 +0200 Subject: [PATCH] chore(validator): allow to not check jira reference --- README.md | 6 +++++- validator.bats | 5 +++++ validator.sh | 24 ++++++++++++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3fdfab0..bf5b42c 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,10 @@ Behind the hood, the script use `git log` to list all the commit thus any syntax You can also use the pre-push commit validator, simply copy, `pre-push`, `validator.sh` and `check.sh` files in `.git/hooks` directory of your repository. +### OPTIONS + +- if `COMMIT_VALIDATOR_NO_JIRA` environment variable is set, no validation is done on JIRA refs. + ## Roadmap @@ -216,7 +220,7 @@ See the [open issues](https://github.com/lumapps/commit-msg-validator/issues) fo - [x] avoid trailing space - [x] allow automated revert commit - [ ] allow fixup! and squash! commit with an option -- [ ] allow to not check JIRA reference with an option +- [x] allow to not check JIRA reference with an option - [ ] enforce subject length (3 words at least) diff --git a/validator.bats b/validator.bats index e377e8f..541fadd 100644 --- a/validator.bats +++ b/validator.bats @@ -460,6 +460,11 @@ 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 "other commits don't need jira reference" { [[ `need_jira "docs"` -eq 0 ]] [[ `need_jira "test"` -eq 0 ]] diff --git a/validator.sh b/validator.sh index e89e440..cbe6f89 100644 --- a/validator.sh +++ b/validator.sh @@ -208,16 +208,20 @@ validate_trailing_space() { need_jira() { local TYPE=$1 - case $TYPE in - feat) - echo 1 - ;; - fix) - echo 1 - ;; - *) - echo 0 - esac + if [[ -v COMMIT_VALIDATOR_NO_JIRA ]]; then + echo 0 + else + case $TYPE in + feat) + echo 1 + ;; + fix) + echo 1 + ;; + *) + echo 0 + esac + fi } validate_jira() {