Damjan Marion | 26ce6ca | 2019-06-12 17:41:39 +0200 | [diff] [blame] | 1 | #/bin/env bash |
| 2 | |
| 3 | KNOWN_FEATURES=$(cat MAINTAINERS | sed -ne 's/^I:[[:space:]]*//p') |
Damjan Marion | 94bef09 | 2019-06-29 11:27:40 +0200 | [diff] [blame] | 4 | FEATURES=$(git show -s --format=%s --no-color | sed -e 's/\([a-z0-9 -]*\):.*/\1/') |
Neale Ranns | ff34b91 | 2019-06-14 02:09:43 -0700 | [diff] [blame] | 5 | KNOWN_TYPES="feature fix refactor style docs test make" |
Damjan Marion | 26ce6ca | 2019-06-12 17:41:39 +0200 | [diff] [blame] | 6 | TYPE=$(git show -s --format=%b --no-color | sed -ne 's/^Type:[[:space:]]*//p') |
| 7 | ERR="=============================== ERROR ===============================" |
| 8 | |
| 9 | # Chech that subject line contains at least one feature id |
| 10 | if [ $(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 Barach | 6e5baf2 | 2019-06-25 10:16:10 -0400 | [diff] [blame] | 15 | echo "Please refer to the MAINTAINERS file (I: lines) for known feature ids." |
Damjan Marion | 26ce6ca | 2019-06-12 17:41:39 +0200 | [diff] [blame] | 16 | echo $ERR |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | # Check that feature ids in subject line are known |
| 21 | for 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 Barach | 6e5baf2 | 2019-06-25 10:16:10 -0400 | [diff] [blame] | 29 | 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 Marion | 26ce6ca | 2019-06-12 17:41:39 +0200 | [diff] [blame] | 31 | echo "MAINTAINERS file." |
| 32 | echo $ERR |
| 33 | exit 1 |
| 34 | fi |
| 35 | done |
| 36 | |
| 37 | # Check that Message body contains valid Type: entry |
| 38 | is_known=false |
| 39 | for i in ${KNOWN_TYPES}; do |
| 40 | [ "${i}" = "${TYPE}" ] && is_known=true |
| 41 | done |
| 42 | if [ ${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 |
| 49 | fi |
Dave Wallace | e790690 | 2019-11-14 12:19:32 -0500 | [diff] [blame] | 50 | echo "*******************************************************************" |
| 51 | echo "* VPP Commit Message Checkstyle Successfully Completed" |
| 52 | echo "*******************************************************************" |