Skip to content

Commit d29ee32

Browse files
author
Atiqur Rahman
committed
feat: add conventional-pre-commit hook
1 parent 5e703d4 commit d29ee32

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

scripts/conventional-pre-commit.sh

+7-11
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ fi
1818
# the commit message file is the last remaining arg
1919
msg_file="$1"
2020

21-
# join types with | to form regex ORs
22-
r_types="($(IFS='|'; echo "${types[*]}"))"
23-
# optional (scope)
24-
r_scope="(\([[:alnum:] \/-]+\))?"
25-
# optional breaking change indicator and colon delimiter
26-
r_delim='!?:'
27-
# subject line, body, footer
28-
r_subject=" [[:alnum:]].+"
29-
# the full regex pattern
30-
pattern="^$r_types$r_scope$r_delim$r_subject$"
21+
commit_msg_type_regex='feat|fix|refactor|style|test|docs|build'
22+
commit_msg_scope_regex='.{1,20}'
23+
commit_msg_subject_regex='.{1,100}'
24+
commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_subject_regex})\$"
3125
merge_msg_regex="^Merge branch '.+'\$"
3226

27+
commit_msg_header=$(git show -s --format=%s $msg_file)
28+
3329
# Check if commit is conventional commit
34-
if grep -Eq "$pattern|$merge_msg_regex" "$msg_file"; then
30+
if ! [[ "$commit_msg_header" =~ (${commit_msg_regex})|(${merge_msg_regex}) ]]; then
3531
exit 0
3632
fi
3733

0 commit comments

Comments
 (0)