-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-msg
More file actions
executable file
·64 lines (56 loc) · 2.21 KB
/
commit-msg
File metadata and controls
executable file
·64 lines (56 loc) · 2.21 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#===============================================================================
#
# FILE: commit-msg
#
# USAGE: ./commit-msg commit_file
#
# DESCRIPTION: Validates whatever a commit follows the Conventional Commit Guidelines
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: ---,
# ORGANIZATION: ---
# CREATED: 09/27/2021 01:24:48 AM
# REVISION: 2021-10-29 15:11
#===============================================================================
set -o nounset
function main(){
__TEMP=$(cat $1)
COMMIT_MSG=$(awk 'NR==1' $1)
CONVENTIONAL_REGEX="^(?:perf|build|test|refactor|feat|ci|fix|docs|chore|style)!?(?:\([\w\s]+\))?:\s[\s\d\w&]+(?!\.)$"
IGNORE_FLAG="^\!{2}"
[[ $COMMIT_MSG =~ $IGNORE_FLAG ]] && echo "${__TEMP:2}" > $1 && echo "IGNORING CONVENTIONAL COMMIT RULES..." && exit 0
[[ -z $(echo $COMMIT_MSG | grep -P $CONVENTIONAL_REGEX ) ]] && saveBackup $1 && conventionalError
[[ ${#COMMIT_MSG} -gt 72 ]] && saveBackup $1 && conventionalError
exit 0;
}
function conventionalError() {
cat << EOF
------------------------------------------------------
| PLEASE FOLLOW THE CONVENTIONAL COMMIT GUIDELINES |
| |
| 1) Start with -> refactor | feat | ci | fix | docs |
| chore | style | test | perf | build |
| |
| 2) Add an optional \`(scope)\` after rule #1 |
| |
| 3) The title should contain less than 73 characters|
| |
| 4) Add a short description |
| |
| 5) You could add a body and footer if u want |
------------------------------------------------------
Start the commit message with !! to ignore all the rules. Note: The !! will be automatically removed
Type \`git commit\` and fix the previous commit message ~
EOF
exit 1;
}
function saveBackup() {
CLOG=/var/run/user/$UID/last_commit.log
[[ -e $CLOG ]] && rm $CLOG
cp $1 /var/run/user/$UID/last_commit.log
} > /dev/null
main $@