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