-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare-commit-msg
39 lines (32 loc) · 903 Bytes
/
prepare-commit-msg
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
#!/bin/bash
if [[ $(git remote -v | grep github.com) ]]; then
echo "Commit Rules NOT enforced"
exit 0
else
echo "Commit Rules enforced"
fi
MSG_FILE=$1
MSG_TYPE=$2
FILE_CONTENT="$(cat $MSG_FILE)"
export REGEX='^(DE[0-9]+:|US[0-9]+:|Merge) .+'
# If commit is already good, take it
if [[ $FILE_CONTENT =~ $REGEX ]]; then
exit 0
fi
# Skip files
skip_list=`git rev-parse --git-dir`"/hooks/pre-commit.skip"
if [[ -f $skip_list ]]; then
if grep -E "^$BRANCH$" $skip_list; then
exit 0
fi
fi
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
STORY=$(echo ${BRANCH} | awk 'match($0, /US[0-9]+|DE[0-9]+/) {print toupper(substr($0, RSTART, 1)) substr($0, RSTART + 1, RLENGTH - 1)}')
if [[ ! $STORY ]]; then
exit 0
fi
# Add story to commit in attempt to make it good
echo "Prepending branch information \"$STORY\"..."
echo "Message Type: $MSG_TYPE"
echo "$STORY: $FILE_CONTENT" > $MSG_FILE
exit 0