Skip to content

Commit 4de6828

Browse files
author
Joshua Anderson
committed
docs(contributing): add commit-message hook
1 parent 5ebdc99 commit 4de6828

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ test-style:
9797
$(GOLINT) $$i; \
9898
done
9999
@$(foreach C, tests $(CLIENTS) $(COMPONENTS), $(MAKE) -C $(C) test-style &&) echo done
100+
101+
commit-hook:
102+
cp contrib/util/commit-msg .git/hooks/commit-msg

contrib/util/commit-msg

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
#
3+
# This hook verifies that the commit message follows deis commit style
4+
# To install this hook run the following command from the deis git root
5+
# cp contrib/util/commit-msg .git/hooks/commit-msg
6+
set -eo pipefail
7+
8+
RED=$(tput setaf 1)
9+
NORMAL=$(tput sgr0)
10+
subject_regex="^(feat|fix|docs|style|ref|test|chore)\(.+\): [\w\s\d]*"
11+
capital_regex="^.+\): [a-z][\w\s\d]*"
12+
13+
MESSAGE[1]="file"
14+
15+
i=1 # the first array variable is at index 1
16+
while read line
17+
do
18+
MESSAGE[$i]=$line
19+
let i++
20+
done < "$1"
21+
22+
SUBJECT=${MESSAGE[1]}
23+
24+
if ! [[ $SUBJECT =~ $subject_regex ]]; then
25+
echo "${RED}ERROR - Invalid subject line."
26+
echo ""
27+
echo "$SUBJECT"
28+
echo ""
29+
echo "It must be in the format: {type}({scope}): {subject}"
30+
echo ""
31+
echo "The following {type}s are allowed:"
32+
echo "feat"
33+
echo "fix"
34+
echo "docs"
35+
echo "style"
36+
echo "ref"
37+
echo "test"
38+
echo "chore"
39+
echo ""
40+
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
41+
exit 1
42+
fi
43+
44+
if ! [[ $SUBJECT =~ $capital_regex ]]; then
45+
echo "${RED}ERROR - Don't the capitalize commit message."
46+
echo ""
47+
echo "$SUBJECT"
48+
echo ""
49+
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
50+
exit 1
51+
fi
52+
53+
if [[ ${#SUBJECT} -gt 50 ]]; then
54+
echo "${RED}ERROR - Subject can't be longer than 50 characters."
55+
echo ""
56+
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
57+
exit 1
58+
fi
59+
60+
if [[ ${#MESSAGE[2]} -gt 0 ]]; then
61+
echo "${RED}ERROR - Second line must be blank"
62+
echo ""
63+
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
64+
exit 1
65+
fi
66+
67+
cnt=${#MESSAGE[@]}
68+
for (( i = 3 ; i <= cnt ; i++ ))
69+
do
70+
if [[ ${#MESSAGE[$i]} -gt 72 ]]; then
71+
echo "${RED}ERROR on line $i - can't be longer than 72 characters."
72+
echo ""
73+
echo "Read more at http://docs.deis.io/en/latest/contributing/standards/$NORMAL"
74+
exit 1
75+
fi
76+
done
77+
78+
echo "Your commit message follows the deis commit style"
79+
80+
exit 0

docs/contributing/standards.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ Example
122122
umVEX-8 series artifacts will need to be updated to umVX format
123123
with the consortium or vendor toolset.
124124

125+
.. note::
126+
127+
You can install a git hook that checks your commit message format with ``make commit-hook``
125128

126129
Subject Line
127130
""""""""""""

0 commit comments

Comments
 (0)