Skip to content

Commit 0579955

Browse files
committed
feat(pre-commit): adding new options to the pre-commit shell script
Also making the whole thing posix when handling arguments as not being able to put = between args and values was frustrating
1 parent ad13636 commit 0579955

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ Then run `pre-commit install --hook-type commit-msg` to install the
311311
- if `allow-temp` is set, no validation is done on `fixup!` and `squash!`
312312
commits.
313313
- if `no-revert-sha1` is set, no validation is done on revert commits.
314+
- if `--jira-in-header` jira reference can be put in the commit header.
315+
- `--header-length` allow to override the max length of the header line.
316+
- `--jira-types` takes a space separated list `"feat fix"` as a parameter to override the default types requiring a jira
314317

315318
<!-- ROADMAP -->
316319

check_message.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
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-
}
5+
OPTIONS=$(getopt --long no-jira,allow-temp,jira-in-header,header-length:,jira-types: -- "$@")
106

11-
COMMIT_VALIDATOR_ALLOW_TEMP=
12-
COMMIT_VALIDATOR_NO_JIRA=
13-
COMMIT_VALIDATOR_NO_REVERT_SHA1=
7+
unset COMMIT_VALIDATOR_ALLOW_TEMP COMMIT_VALIDATOR_NO_JIRA COMMIT_VALIDATOR_NO_REVERT_SHA1 GLOBAL_JIRA_IN_HEADER GLOBAL_MAX_LENGTH GLOBAL_JIRA_TYPES
148

9+
eval set -- $OPTIONS
1510
while true; do
1611
case "$1" in
1712
--no-jira ) COMMIT_VALIDATOR_NO_JIRA=1; shift ;;
1813
--allow-temp ) COMMIT_VALIDATOR_ALLOW_TEMP=1; shift ;;
1914
--no-revert-sha1 ) COMMIT_VALIDATOR_NO_REVERT_SHA1=1; shift ;;
15+
--jira-in-header ) GLOBAL_JIRA_IN_HEADER=1; shift ;;
16+
--header-length ) GLOBAL_MAX_LENGTH="$2"; shift 2 ;;
17+
--jira-types ) GLOBAL_JIRA_TYPES="$2"; shift 2 ;;
2018
-- ) shift; break ;;
2119
* ) break ;;
2220
esac
@@ -47,9 +45,9 @@ fi
4745
# print message so you don't lose it in case of errors
4846
# (in case you are not using `-m` option)
4947
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"
48+
echo " JIRA=${COMMIT_VALIDATOR_NO_JIRA:-}"
49+
echo " TEMP=${COMMIT_VALIDATOR_ALLOW_TEMP:-}"
50+
echo " NO_REVERT_SHA1=${COMMIT_VALIDATOR_NO_REVERT_SHA1:-}"
5351
printf "checking commit message:\n\n#BEGIN#\n%s\n#END#\n\n" "$MESSAGE"
5452

5553
validate "$MESSAGE"

0 commit comments

Comments
 (0)