Skip to content

Commit 012eea2

Browse files
committed
feat: simple grep check of commit message
commit message expected in a text file passed as first arg print help text for failure
1 parent 92352be commit 012eea2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

conventional-pre-commit.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
if ! grep -Pq '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([\w][\w -]+\))?!?: [\w][\s\S]+$' "$1"; then
4+
echo "[Commit message] $( cat $1 )"
5+
echo "
6+
Your commit message doesn't look like a Conventional Commit https://www.conventionalcommits.org/
7+
8+
Conventional Commits start with one of the below types, followed by a colon, followed by the commit message:
9+
10+
build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test
11+
12+
Example commit message adding a feature:
13+
14+
'feat: add great new feature'
15+
16+
Example commit message fixing an issue:
17+
18+
'fix: remove infinite loop'
19+
20+
Optionally, include a scope in parentheses after the type for more context:
21+
22+
'fix(account): remove infinite loop'
23+
"
24+
exit 1
25+
fi

0 commit comments

Comments
 (0)