From 9743dd0eda75dcde7ebe392c640cd7365e11693f Mon Sep 17 00:00:00 2001 From: AmineSalah Date: Thu, 24 Feb 2022 12:00:20 +0100 Subject: [PATCH 1/9] fix(bash): jira pattern accept numbers and must have a charater --- validator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator.sh b/validator.sh index b3947e7..1eac725 100644 --- a/validator.sh +++ b/validator.sh @@ -8,7 +8,7 @@ readonly HEADER_PATTERN="^([^\(]+)\(([^\)]+)\): (.+)$" readonly TYPE_PATTERN="^(feat|fix|docs|gen|lint|refactor|test|chore)$" readonly SCOPE_PATTERN="^([a-z][a-z0-9]*)(-[a-z0-9]+)*$" readonly SUBJECT_PATTERN="^([a-z0-9].*[^ ^\.])$" -readonly JIRA_PATTERN="^([A-Z]{2,4}-[0-9]{1,6} ?)+$" +readonly JIRA_PATTERN="^([A-Z]{2,4}[0-9]{0,6}-[0-9]{1,6} ?)+$" readonly JIRA_HEADER_PATTERN="^.*([A-Z]{3,4}-[0-9]{1,6}).*$" readonly BROKE_PATTERN="^BROKEN:$" readonly TRAILING_SPACE_PATTERN=" +$" From 559f5e00d9ef57808e646e32936a7c9ff3ccf4c2 Mon Sep 17 00:00:00 2001 From: Luis Menina Date: Thu, 5 May 2022 15:20:28 +0200 Subject: [PATCH 2/9] chore(validator): fix indentation mismatch between tabs and spaces --- validator.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/validator.sh b/validator.sh index 1eac725..125c1db 100644 --- a/validator.sh +++ b/validator.sh @@ -64,55 +64,55 @@ validate_overall_structure() { elif [[ $STATE -eq $WAITING_EMPTY ]]; then if [[ $LINE != "" ]]; then - echo -e "missing empty line in commit message between header and body or body and footer" + echo -e "missing empty line in commit message between header and body or body and footer" exit $ERROR_STRUCTURE fi STATE="$START_TEXT" elif [[ $STATE -eq $START_TEXT ]]; then if [[ $LINE = "" ]]; then - echo -e "double empty line is not allowed" + echo -e "double empty line is not allowed" exit $ERROR_STRUCTURE fi if [[ $LINE =~ $BROKE_PATTERN ]]; then - STATE="$READING_FOOTER" + STATE="$READING_FOOTER" elif [[ $LINE =~ $JIRA_PATTERN ]]; then - STATE="$READING_BROKEN" - GLOBAL_JIRA=${BASH_REMATCH[0]} + STATE="$READING_BROKEN" + GLOBAL_JIRA=${BASH_REMATCH[0]} else - STATE="$READING_BODY" - GLOBAL_BODY=$GLOBAL_BODY$LINE$'\n' + STATE="$READING_BODY" + GLOBAL_BODY=$GLOBAL_BODY$LINE$'\n' fi elif [[ $STATE -eq $READING_BODY ]]; then if [[ $LINE =~ $BROKE_PATTERN ]]; then - echo -e "missing empty line before broke part" + echo -e "missing empty line before broke part" exit $ERROR_STRUCTURE fi if [[ $LINE =~ $JIRA_PATTERN ]]; then - echo -e "missing empty line before JIRA reference" + echo -e "missing empty line before JIRA reference" exit $ERROR_STRUCTURE fi if [[ $LINE = "" ]]; then - STATE=$START_TEXT + STATE=$START_TEXT else - GLOBAL_BODY=$GLOBAL_BODY$LINE$'\n' + GLOBAL_BODY=$GLOBAL_BODY$LINE$'\n' fi elif [[ $STATE -eq $READING_BROKEN ]]; then if [[ $LINE =~ $BROKE_PATTERN ]]; then - STATE="$READING_FOOTER" + STATE="$READING_FOOTER" else - echo -e "only broken part could be after the JIRA reference" + echo -e "only broken part could be after the JIRA reference" exit $ERROR_STRUCTURE fi elif [[ $STATE -eq $READING_FOOTER ]]; then if [[ $LINE = "" ]]; then - echo -e "no empty line allowed in broken part" + echo -e "no empty line allowed in broken part" exit $ERROR_STRUCTURE fi @@ -252,7 +252,7 @@ validate_revert() { while IFS= read -r LINE ; do if [[ $LINE =~ $REVERT_COMMIT_PATTERN ]]; then - REVERTED_COMMIT=${BASH_REMATCH[1]} + REVERTED_COMMIT=${BASH_REMATCH[1]} fi done <<< "$BODY" From 4293d0f7c33bfc3914ed12fd593f921aaf72fd82 Mon Sep 17 00:00:00 2001 From: Thomas Magalhaes Date: Thu, 21 Jul 2022 16:22:27 +0200 Subject: [PATCH 3/9] feat(validator): allow lines longer than max if no spaces --- validator.bats | 12 +++++++++++- validator.sh | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/validator.bats b/validator.bats index ae1c11b..db7444c 100644 --- a/validator.bats +++ b/validator.bats @@ -452,6 +452,16 @@ LUM-2345' [[ "$status" -eq 0 ]] } +@test "body with 100+ line length should be valid if no space" { + MESSAGE=' +0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_ + +LUM-2345' + + run validate_body_length "$MESSAGE" + [[ "$status" -eq 0 ]] +} + @test "body with trailing space on line should not be valid" { MESSAGE='pdzofjzf ' @@ -612,7 +622,7 @@ LUM-2345' @test "overall validation invalid body length" { MESSAGE='feat(scope1): subject -12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 +1 2 3 4 5678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 LUM-2345' diff --git a/validator.sh b/validator.sh index 125c1db..6c4b638 100644 --- a/validator.sh +++ b/validator.sh @@ -189,6 +189,9 @@ validate_body_length() { while IFS= read -r LINE ; do + # Skip lines with no spaces as they can't be split + $(echo -n "$LINE" | grep -q "\s") || continue + local LENGTH LENGTH="$(echo -n "$LINE" | wc -c)" From 2e82b608e68afc98186b76000d4c853517bc3420 Mon Sep 17 00:00:00 2001 From: pampul Date: Fri, 5 Aug 2022 16:56:19 +0200 Subject: [PATCH 4/9] chore(jira-pattern): allow 6 characters --- validator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator.sh b/validator.sh index 6c4b638..274cb5f 100644 --- a/validator.sh +++ b/validator.sh @@ -8,7 +8,7 @@ readonly HEADER_PATTERN="^([^\(]+)\(([^\)]+)\): (.+)$" readonly TYPE_PATTERN="^(feat|fix|docs|gen|lint|refactor|test|chore)$" readonly SCOPE_PATTERN="^([a-z][a-z0-9]*)(-[a-z0-9]+)*$" readonly SUBJECT_PATTERN="^([a-z0-9].*[^ ^\.])$" -readonly JIRA_PATTERN="^([A-Z]{2,4}[0-9]{0,6}-[0-9]{1,6} ?)+$" +readonly JIRA_PATTERN="^([A-Z]{2,6}[0-9]{0,6}-[0-9]{1,6} ?)+$" readonly JIRA_HEADER_PATTERN="^.*([A-Z]{3,4}-[0-9]{1,6}).*$" readonly BROKE_PATTERN="^BROKEN:$" readonly TRAILING_SPACE_PATTERN=" +$" From 1808fbb88d2cdb58fc0d4e7346978ec0ecac8b06 Mon Sep 17 00:00:00 2001 From: Anis Campos Date: Tue, 3 Jan 2023 11:45:43 +0100 Subject: [PATCH 5/9] fix(jira): the jira pattern reuse the same pattern for both footer and header --- validator.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/validator.sh b/validator.sh index 274cb5f..57e9f8f 100644 --- a/validator.sh +++ b/validator.sh @@ -8,8 +8,9 @@ readonly HEADER_PATTERN="^([^\(]+)\(([^\)]+)\): (.+)$" readonly TYPE_PATTERN="^(feat|fix|docs|gen|lint|refactor|test|chore)$" readonly SCOPE_PATTERN="^([a-z][a-z0-9]*)(-[a-z0-9]+)*$" readonly SUBJECT_PATTERN="^([a-z0-9].*[^ ^\.])$" -readonly JIRA_PATTERN="^([A-Z]{2,6}[0-9]{0,6}-[0-9]{1,6} ?)+$" -readonly JIRA_HEADER_PATTERN="^.*([A-Z]{3,4}-[0-9]{1,6}).*$" +readonly JIRA_PATTERN="[A-Z]{2,6}[0-9]{0,6}-[0-9]{1,6}" +readonly JIRA_FOOTER_PATTERN="^(${JIRA_PATTERN} ?)+$" +readonly JIRA_HEADER_PATTERN="^.*[^A-Z](${JIRA_PATTERN}).*$" readonly BROKE_PATTERN="^BROKEN:$" readonly TRAILING_SPACE_PATTERN=" +$" readonly REVERT_HEADER_PATTERN="^[R|r]evert[: ].*$" @@ -77,7 +78,7 @@ validate_overall_structure() { if [[ $LINE =~ $BROKE_PATTERN ]]; then STATE="$READING_FOOTER" - elif [[ $LINE =~ $JIRA_PATTERN ]]; then + elif [[ $LINE =~ $JIRA_FOOTER_PATTERN ]]; then STATE="$READING_BROKEN" GLOBAL_JIRA=${BASH_REMATCH[0]} else @@ -91,7 +92,7 @@ validate_overall_structure() { exit $ERROR_STRUCTURE fi - if [[ $LINE =~ $JIRA_PATTERN ]]; then + if [[ $LINE =~ $JIRA_FOOTER_PATTERN ]]; then echo -e "missing empty line before JIRA reference" exit $ERROR_STRUCTURE fi From 97911f3b9477f1243d1845f74718ec0ceb40bc85 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Fri, 11 Aug 2023 10:18:39 +0200 Subject: [PATCH 6/9] feat(subject): no longer prevent commit subjects from starting with a capital letter --- README.md | 1 - git-commit-template | 1 - validator.bats | 7 +------ validator.sh | 4 ++-- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a0f665c..58652cc 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,6 @@ A brief but meaningfull description of the change. Here are recommandations for writing your subject: - use the imperative, present tense: "change" not "changed" nor "changes" -- don't capitalize first letter - no "." (dot) at the end ### Body diff --git a/git-commit-template b/git-commit-template index 126f1ee..76c655e 100644 --- a/git-commit-template +++ b/git-commit-template @@ -25,7 +25,6 @@ type(scope): subject # A brief but meaningful description of the change. Here are some # recommendation for writing your subject: # - use the imperative, present tense: "change" not "changed" nor "changes" -# - don't capitalize first letter # - no "." (dot) at the end ## Body diff --git a/validator.bats b/validator.bats index db7444c..892b00b 100644 --- a/validator.bats +++ b/validator.bats @@ -414,11 +414,6 @@ BROKEN: [ "$status" -eq $ERROR_SUBJECT ] } -@test "subject cannot start with a capitalized letter" { - run validate_subject "Plop" - [ "$status" -eq $ERROR_SUBJECT ] -} - @test "subject cannot end with a point" { run validate_subject "plop." [ "$status" -eq $ERROR_SUBJECT ] @@ -616,7 +611,7 @@ Commit about stuff\"plop \" LUM-2345' run validate "$MESSAGE" - [[ "$status" -eq $ERROR_SUBJECT ]] + [[ "$status" -ne $ERROR_SUBJECT ]] } @test "overall validation invalid body length" { diff --git a/validator.sh b/validator.sh index 57e9f8f..84d5c6a 100644 --- a/validator.sh +++ b/validator.sh @@ -7,7 +7,7 @@ fi readonly HEADER_PATTERN="^([^\(]+)\(([^\)]+)\): (.+)$" readonly TYPE_PATTERN="^(feat|fix|docs|gen|lint|refactor|test|chore)$" readonly SCOPE_PATTERN="^([a-z][a-z0-9]*)(-[a-z0-9]+)*$" -readonly SUBJECT_PATTERN="^([a-z0-9].*[^ ^\.])$" +readonly SUBJECT_PATTERN="^([A-Za-z0-9].*[^ ^\.])$" readonly JIRA_PATTERN="[A-Z]{2,6}[0-9]{0,6}-[0-9]{1,6}" readonly JIRA_FOOTER_PATTERN="^(${JIRA_PATTERN} ?)+$" readonly JIRA_HEADER_PATTERN="^.*[^A-Z](${JIRA_PATTERN}).*$" @@ -179,7 +179,7 @@ validate_subject() { local SUBJECT=$1 if [[ ! $SUBJECT =~ $SUBJECT_PATTERN ]]; then - echo -e "commit subject '$SUBJECT' should start with a lower case and not end with a '.'" + echo -e "commit subject '$SUBJECT' should not end with a '.'" exit $ERROR_SUBJECT fi } From 62fa57d8e5e0e7eb9eec4106b06d238ddc26e38b Mon Sep 17 00:00:00 2001 From: Lumapps Automation Date: Wed, 11 Sep 2024 14:46:41 +0000 Subject: [PATCH 7/9] chore(codeowner): Updating CODEOWNERS file --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fc4dafc..d1dfe82 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # automatically generated by terraform - please do not edit here -* @lumapps/core @lumautomation +* @lumapps/core @lumapps/triarii @lumautomation From 9055752c7ab454883cc9fd3dd17ffe12adf0e424 Mon Sep 17 00:00:00 2001 From: Guillaume Cornut Date: Thu, 26 Sep 2024 11:42:12 +0200 Subject: [PATCH 8/9] feat(validator): add body length parameter --- README.md | 1 + action.yml | 4 ++++ check_message.sh | 5 +++-- validator.bats | 4 ++++ validator.sh | 5 +++-- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 58652cc..6485518 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,7 @@ Then run `pre-commit install --hook-type commit-msg` to install the - if `no-revert-sha1` is set, no validation is done on revert commits. - if `--jira-in-header` jira reference can be put in the commit header. - `--header-length` allow to override the max length of the header line. +- `--body-length` allow to override the max length of body lines. - `--jira-types` takes a space separated list `"feat fix"` as a parameter to override the default types requiring a jira diff --git a/action.yml b/action.yml index 34d981c..2ec348e 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,9 @@ inputs: header_length: description: 'If not empty, max header_length' required: false + body_length: + description: 'If not empty, max body_length' + required: false jira_types: description: 'If not empty, space separated list of types that require Jira refs' required: false @@ -46,5 +49,6 @@ runs: COMMIT_VALIDATOR_NO_REVERT_SHA1: ${{ inputs.no_revert_sha1 }} GLOBAL_JIRA_TYPES: ${{ inputs.jira_types }} GLOBAL_MAX_LENGTH: ${{ inputs.header_length }} + GLOBAL_BODY_MAX_LENGTH: ${{ inputs.body_length }} GLOBAL_JIRA_IN_HEADER: ${{ inputs.jira_in_header }} shell: bash diff --git a/check_message.sh b/check_message.sh index 13de8d7..619f362 100755 --- a/check_message.sh +++ b/check_message.sh @@ -2,8 +2,8 @@ set -eu -OPTIONS=$(getopt --longoptions no-jira,allow-temp,jira-in-header,header-length:,jira-types: --options "" -- "$@") -unset COMMIT_VALIDATOR_ALLOW_TEMP COMMIT_VALIDATOR_NO_JIRA COMMIT_VALIDATOR_NO_REVERT_SHA1 GLOBAL_JIRA_IN_HEADER GLOBAL_MAX_LENGTH GLOBAL_JIRA_TYPES +OPTIONS=$(getopt --longoptions no-jira,allow-temp,jira-in-header,header-length,body-length:,jira-types: --options "" -- "$@") +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 eval set -- $OPTIONS while true; do @@ -13,6 +13,7 @@ while true; do --no-revert-sha1 ) COMMIT_VALIDATOR_NO_REVERT_SHA1=1; shift ;; --jira-in-header ) GLOBAL_JIRA_IN_HEADER=1; shift ;; --header-length ) GLOBAL_MAX_LENGTH="$2"; shift 2 ;; + --body-length ) GLOBAL_BODY_MAX_LENGTH="$2"; shift 2 ;; --jira-types ) GLOBAL_JIRA_TYPES="$2"; shift 2 ;; -- ) shift; break ;; * ) break ;; diff --git a/validator.bats b/validator.bats index 892b00b..201f382 100644 --- a/validator.bats +++ b/validator.bats @@ -457,6 +457,10 @@ LUM-2345' [[ "$status" -eq 0 ]] } +@test "body length cannot be more than 150 with spaces. overridden" { + GLOBAL_BODY_MAX_LENGTH=150 validate_body_length "012345678 012345678 012345678 012345678 012345678 012345678 012345678 1" +} + @test "body with trailing space on line should not be valid" { MESSAGE='pdzofjzf ' diff --git a/validator.sh b/validator.sh index 84d5c6a..ef073f9 100644 --- a/validator.sh +++ b/validator.sh @@ -36,6 +36,7 @@ GLOBAL_FOOTER="" # Overridable variables GLOBAL_JIRA_TYPES="${GLOBAL_JIRA_TYPES:-feat fix}" GLOBAL_MAX_LENGTH="${GLOBAL_MAX_LENGTH:-100}" +GLOBAL_BODY_MAX_LENGTH="${GLOBAL_BODY_MAX_LENGTH:-100}" GLOBAL_JIRA_IN_HEADER="${GLOBAL_JIRA_IN_HEADER:-}" GLOBAL_TYPE="" @@ -197,8 +198,8 @@ validate_body_length() { LENGTH="$(echo -n "$LINE" | wc -c)" - if [[ $LENGTH -gt 100 ]]; then - echo -e "body message line length is more than 100 charaters" + if [[ $LENGTH -gt ${GLOBAL_BODY_MAX_LENGTH} ]]; then + echo -e "body message line length is more than ${GLOBAL_BODY_MAX_LENGTH} characters" exit $ERROR_BODY_LENGTH fi done <<< "$BODY" From d60eb1c599d36a8addf9ff285b98535cddf6e1cf Mon Sep 17 00:00:00 2001 From: Thomas Magalhaes Date: Tue, 2 Sep 2025 11:41:59 +0200 Subject: [PATCH 9/9] chore(action): output in github step summary --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2ec348e..b7e5e77 100644 --- a/action.yml +++ b/action.yml @@ -42,7 +42,7 @@ runs: - name: Validation run: | ${{ github.action_path }}/check.sh \ - ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} + ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} >> $GITHUB_STEP_SUMMARY env: COMMIT_VALIDATOR_NO_JIRA: ${{ inputs.no_jira }} COMMIT_VALIDATOR_ALLOW_TEMP: ${{ inputs.allow_temp }}