blob: 6869fbf6561064daad5bfca2ab4242722837ab99 [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')
Jon Loeliger171577e2019-11-26 08:11:11 -06004FEATURES=$(git show -s --format=%s --no-color \
John DeNiscodf35a202020-06-19 15:28:48 -04005 | sed -ne 's/^\([a-z0-9_ -]*\):.*$/\1/p')
Mohsin Kazmi574be8f2020-02-04 11:36:17 +01006KNOWN_TYPES="feature fix refactor improvement style docs test make"
Damjan Marion26ce6ca2019-06-12 17:41:39 +02007TYPE=$(git show -s --format=%b --no-color | sed -ne 's/^Type:[[:space:]]*//p')
8ERR="=============================== ERROR ==============================="
9
10# Chech that subject line contains at least one feature id
11if [ $(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."
Dave Barach6e5baf22019-06-25 10:16:10 -040016 echo "Please refer to the MAINTAINERS file (I: lines) for known feature ids."
Damjan Marion26ce6ca2019-06-12 17:41:39 +020017 echo $ERR
18 exit 1
19fi
20
21# Check that feature ids in subject line are known
22for 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."
Dave Barach6e5baf22019-06-25 10:16:10 -040030 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 "
Damjan Marion26ce6ca2019-06-12 17:41:39 +020032 echo "MAINTAINERS file."
33 echo $ERR
34 exit 1
35 fi
36done
37
38# Check that Message body contains valid Type: entry
39is_known=false
40for i in ${KNOWN_TYPES}; do
41 [ "${i}" = "${TYPE}" ] && is_known=true
42done
43if [ ${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
50fi
Dave Wallacee7906902019-11-14 12:19:32 -050051echo "*******************************************************************"
52echo "* VPP Commit Message Checkstyle Successfully Completed"
53echo "*******************************************************************"