-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-msg
More file actions
executable file
·32 lines (27 loc) · 1.01 KB
/
commit-msg
File metadata and controls
executable file
·32 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
# Validates conventional commit format: type(scope): description
# Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
# Optional ! for breaking changes: feat(api)!: change response format
# Merge commits and fixup/squash commits are always allowed.
msg_file="$1"
msg=$(head -1 "$msg_file")
# Allow merge commits
if echo "$msg" | grep -qE '^Merge '; then
exit 0
fi
# Allow fixup/squash commits
if echo "$msg" | grep -qE '^(fixup|squash)! '; then
exit 0
fi
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9_/-]+\))?!?: .+'
if ! echo "$msg" | grep -qE "$pattern"; then
echo "ERROR: Commit message does not follow Conventional Commits format."
echo ""
echo " Expected: <type>(<scope>): <description>"
echo " Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
echo " Example: feat(auth): add OAuth2 support"
echo " Breaking: feat(api)!: change response format"
echo ""
echo " Your message: $msg"
exit 1
fi