Skip to content

Commit aece264

Browse files
feat(revert): allow to not specify the reverted commit sha1
With github revert no sha1 is specified, thus we don't the validator to fail on this revert.
1 parent 6fe8b63 commit aece264

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ in `.git/hooks` directory of your repository.
233233
no validation is done on JIRA refs.
234234
- if `COMMIT_VALIDATOR_ALLOW_TEMP` environment variable is not empty,
235235
no validation is done on `fixup!` and `squash!` commits.
236+
- if `COMMIT_VALIDATOR_NO_REVERT_SHA1` environment variable is not empty,
237+
no validation is done revert commits.
236238

237239
### Commit template
238240

@@ -276,6 +278,8 @@ jobs:
276278
- if `no_jira` is not empty, no validation is done on JIRA refs.
277279
- if `allow_temp` is not empty, no validation is done on `fixup!`
278280
and `squash!` commits.
281+
- if `no_revert_sha1` is not empty, no validation is done on revert
282+
commits.
279283

280284
## Add pre-commit plugin
281285

@@ -303,9 +307,10 @@ Then run `pre-commit install --hook-type commit-msg` to install the
303307

304308
### Pre commit hook options
305309

306-
- if `no_jira` is set, no validation is done on JIRA refs.
307-
- if `allow_temp` is set, no validation is done on `fixup!` and `squash!`
310+
- if `no-jira` is set, no validation is done on JIRA refs.
311+
- if `allow-temp` is set, no validation is done on `fixup!` and `squash!`
308312
commits.
313+
- if `no-revert-sha1` is set, no validation is done on revert commits.
309314

310315
<!-- ROADMAP -->
311316

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
allow_temp:
1414
description: 'If not empty, no validation is done on `fixup!` and `squash!` commits.'
1515
required: false
16+
no_revert_sha1:
17+
description: 'If not empty, reverted sha1 commit is not mandatory in revert commit message.'
18+
required: false
1619
runs:
1720
using: "composite"
1821
steps:
@@ -31,4 +34,5 @@ runs:
3134
env:
3235
COMMIT_VALIDATOR_NO_JIRA: ${{ inputs.no_jira }}
3336
COMMIT_VALIDATOR_ALLOW_TEMP: ${{ inputs.allow_temp }}
37+
COMMIT_VALIDATOR_NO_REVERT_SHA1: ${{ inputs.no_revert_sha1 }}
3438
shell: bash

check_message.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ OPTIONS=$(getopt --long no-jira allow-temp -- "$@")
1010

1111
COMMIT_VALIDATOR_ALLOW_TEMP=
1212
COMMIT_VALIDATOR_NO_JIRA=
13+
COMMIT_VALIDATOR_NO_REVERT_SHA1=
1314

1415
while true; do
1516
case "$1" in
1617
--no-jira ) COMMIT_VALIDATOR_NO_JIRA=1; shift ;;
1718
--allow-temp ) COMMIT_VALIDATOR_ALLOW_TEMP=1; shift ;;
19+
--no-revert-sha1 ) COMMIT_VALIDATOR_NO_REVERT_SHA1=1; shift ;;
1820
-- ) shift; break ;;
1921
* ) break ;;
2022
esac
@@ -44,7 +46,10 @@ fi
4446

4547
# print message so you don't lose it in case of errors
4648
# (in case you are not using `-m` option)
47-
echo "Options: JIRA=$COMMIT_VALIDATOR_NO_JIRA, TEMP=$COMMIT_VALIDATOR_ALLOW_TEMP"
49+
echo "Options: "
50+
echo " JIRA=$COMMIT_VALIDATOR_NO_JIRA"
51+
echo " TEMP=$COMMIT_VALIDATOR_ALLOW_TEMP"
52+
echo " NO_REVERT_SHA1=$COMMIT_VALIDATOR_NO_REVERT_SHA1"
4853
printf "checking commit message:\n\n#BEGIN#\n%s\n#END#\n\n" "$MESSAGE"
4954

5055
validate "$MESSAGE"

validator.bats

+13
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ LUM-2345'
472472

473473
run validate_revert "$MESSAGE"
474474
[[ "$status" -eq $ERROR_REVERT ]]
475+
COMMIT_VALIDATOR_NO_REVERT_SHA1= run validate_revert "$MESSAGE"
476+
[[ "$status" -eq $ERROR_REVERT ]]
475477
}
476478

477479
@test "revert body with commit sha1 should be valid" {
@@ -483,6 +485,17 @@ LUM-2345'
483485

484486
run validate_revert "$MESSAGE"
485487
[[ "$status" -eq 0 ]]
488+
COMMIT_VALIDATOR_NO_REVERT_SHA1= run validate_revert "$MESSAGE"
489+
[[ "$status" -eq 0 ]]
490+
}
491+
492+
@test "revert body without sha1 should be valid with the flag" {
493+
MESSAGE='rerer
494+
495+
LUM-2345'
496+
497+
COMMIT_VALIDATOR_NO_REVERT_SHA1=1 run validate_revert "$MESSAGE"
498+
[[ "$status" -eq 0 ]]
486499
}
487500

488501
@test "features and fixes commits need jira reference" {

validator.sh

+4
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ validate_revert() {
242242
local LINE=""
243243
local REVERTED_COMMIT=""
244244

245+
if [[ ! -z "${COMMIT_VALIDATOR_NO_REVERT_SHA1:-}" ]]; then
246+
exit 0
247+
fi
248+
245249
while IFS= read -r LINE ;
246250
do
247251
if [[ $LINE =~ $REVERT_COMMIT_PATTERN ]]; then

0 commit comments

Comments
 (0)