Skip to content

Commit 5e29849

Browse files
chore(check-message): handle options for prehook
1 parent 01c8d9f commit 5e29849

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,16 @@ repos:
261261
hooks:
262262
- id: commit-message-validator
263263
stages: [commit-msg]
264+
args: [--allow-temp]
264265
...
265266
```
266267
Then run `pre-commit install --hook-type commit-msg` to install the `commit-message-validator`
267268

269+
### OPTIONS
270+
271+
- if `no_jira` is set, no validation is done on JIRA refs.
272+
- if `allow_temp` is set, no validation is done on `fixup!` and `squash!` commits.
273+
268274
<!-- ROADMAP -->
269275

270276
## Roadmap

check_message.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
set -eu
44

5+
OPTIONS=$(getopt --long no-jira allow-temp -- "$@")
6+
[ $? -eq 0 ] || {
7+
echo "Incorrect options provided"
8+
exit 1
9+
}
10+
11+
COMMIT_VALIDATOR_ALLOW_TEMP=
12+
COMMIT_VALIDATOR_NO_JIRA=
13+
14+
while true; do
15+
case "$1" in
16+
--no-jira ) COMMIT_VALIDATOR_NO_JIRA=1; shift ;;
17+
--allow-temp ) COMMIT_VALIDATOR_ALLOW_TEMP=1; shift ;;
18+
-- ) shift; break ;;
19+
* ) break ;;
20+
esac
21+
done
22+
523
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
624
# shellcheck source=validator.sh
725
source "$DIR/validator.sh"
@@ -25,6 +43,7 @@ fi
2543

2644
# print message so you don't lose it in case of errors
2745
# (in case you are not using `-m` option)
46+
echo "Options: JIRA=$COMMIT_VALIDATOR_NO_JIRA, TEMP=$COMMIT_VALIDATOR_ALLOW_TEMP"
2847
printf "checking commit message:\n\n#BEGIN#\n%s\n#END#\n\n" "$(grep -v "#" <<< "$MESSAGE")"
2948

30-
COMMIT_VALIDATOR_ALLOW_TEMP=1 COMMIT_VALIDATOR_NO_JIRA=1 validate "$MESSAGE"
49+
validate "$MESSAGE"

0 commit comments

Comments
 (0)