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') |
Jon Loeliger | 171577e | 2019-11-26 08:11:11 -0600 | [diff] [blame] | 4 | FEATURES=$(git show -s --format=%s --no-color \ |
John DeNisco | df35a20 | 2020-06-19 15:28:48 -0400 | [diff] [blame] | 5 | | sed -ne 's/^\([a-z0-9_ -]*\):.*$/\1/p') |
Mohsin Kazmi | 574be8f | 2020-02-04 11:36:17 +0100 | [diff] [blame] | 6 | KNOWN_TYPES="feature fix refactor improvement style docs test make" |
Damjan Marion | 26ce6ca | 2019-06-12 17:41:39 +0200 | [diff] [blame] | 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." |
Dave Barach | 6e5baf2 | 2019-06-25 10:16:10 -0400 | [diff] [blame] | 16 | 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] | 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." |
Dave Barach | 6e5baf2 | 2019-06-25 10:16:10 -0400 | [diff] [blame] | 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 " |
Damjan Marion | 26ce6ca | 2019-06-12 17:41:39 +0200 | [diff] [blame] | 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 |
Dave Wallace | e790690 | 2019-11-14 12:19:32 -0500 | [diff] [blame] | 51 | echo "*******************************************************************" |
| 52 | echo "* VPP Commit Message Checkstyle Successfully Completed" |
| 53 | echo "*******************************************************************" |