blob: 2cc63c5fbd1208e3053d71f41d494c7d8bc2c074 [file] [log] [blame]
Damjan Marion26ce6ca2019-06-12 17:41:39 +02001#/bin/env bash
2
3KNOWN_FEATURES=$(cat MAINTAINERS | sed -ne 's/^I:[[:space:]]*//p')
Damjan Marion94bef092019-06-29 11:27:40 +02004FEATURES=$(git show -s --format=%s --no-color | sed -e 's/\([a-z0-9 -]*\):.*/\1/')
Neale Rannsff34b912019-06-14 02:09:43 -07005KNOWN_TYPES="feature fix refactor style docs test make"
Damjan Marion26ce6ca2019-06-12 17:41:39 +02006TYPE=$(git show -s --format=%b --no-color | sed -ne 's/^Type:[[:space:]]*//p')
7ERR="=============================== ERROR ==============================="
8
9# Chech that subject line contains at least one feature id
10if [ $(echo ${FEATURES} | wc -w) -eq 0 ]; then
11 echo $ERR
12 echo "git commit 'Subject:' line must contain at least one known feature id."
13 echo "feature id(s) must be listed before ':' and space delimited "
14 echo "if more then one is listed."
Dave Barach6e5baf22019-06-25 10:16:10 -040015 echo "Please refer to the MAINTAINERS file (I: lines) for known feature ids."
Damjan Marion26ce6ca2019-06-12 17:41:39 +020016 echo $ERR
17 exit 1
18fi
19
20# Check that feature ids in subject line are known
21for i in ${FEATURES}; do
22 is_known=false
23 for j in ${KNOWN_FEATURES}; do
24 [ "${i}" = "${j}" ] && is_known=true
25 done
26 if [ ${is_known} = "false" ] ; then
27 echo $ERR
28 echo "Unknown feature '${i}' in commit 'Subject:' line."
Dave Barach6e5baf22019-06-25 10:16:10 -040029 echo "Feature must exist in MAINTAINERS file. If this commit introduces "
30 echo "a new feature, then this commit must add an entry to the "
Damjan Marion26ce6ca2019-06-12 17:41:39 +020031 echo "MAINTAINERS file."
32 echo $ERR
33 exit 1
34 fi
35done
36
37# Check that Message body contains valid Type: entry
38is_known=false
39for i in ${KNOWN_TYPES}; do
40 [ "${i}" = "${TYPE}" ] && is_known=true
41done
42if [ ${is_known} = "false" ] ; then
43 echo $ERR
44 echo "Unknown commit type '${TYPE}' in commit message body."
45 echo "Commit message must contain known 'Type:' entry."
46 echo "Known types are: ${KNOWN_TYPES}"
47 echo $ERR
48 exit 1
49fi
Dave Wallacee7906902019-11-14 12:19:32 -050050echo "*******************************************************************"
51echo "* VPP Commit Message Checkstyle Successfully Completed"
52echo "*******************************************************************"