summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2019-06-12 17:41:39 +0200
committerFlorin Coras <florin.coras@gmail.com>2019-06-12 17:04:40 +0000
commit26ce6ca1fe6f524a9049444fe8d55042fd7530a6 (patch)
treeb95e3da1245220d08fb5b1375a6af7c6b292ef3f
parentc83311ddff9bce2a0e00cd6547c9680192cc3d8c (diff)
misc: add check_commit_msg.sh script
Type: feature Change-Id: I5e04991afd7500673db121e4529275e9aff15e65 Signed-off-by: Damjan Marion <damarion@cisco.com>
-rwxr-xr-xextras/scripts/check_commit_msg.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/extras/scripts/check_commit_msg.sh b/extras/scripts/check_commit_msg.sh
new file mode 100755
index 00000000000..ec9db60c15e
--- /dev/null
+++ b/extras/scripts/check_commit_msg.sh
@@ -0,0 +1,50 @@
+#/bin/env bash
+
+KNOWN_FEATURES=$(cat MAINTAINERS | sed -ne 's/^I:[[:space:]]*//p')
+FEATURES=$(git show -s --format=%s --no-color | sed -e 's/\(.*\):.*/\1/')
+KNOWN_TYPES="fix refactor style docs test make"
+TYPE=$(git show -s --format=%b --no-color | sed -ne 's/^Type:[[:space:]]*//p')
+ERR="=============================== ERROR ==============================="
+
+# Chech that subject line contains at least one feature id
+if [ $(echo ${FEATURES} | wc -w) -eq 0 ]; then
+ echo $ERR
+ echo "git commit 'Subject:' line must contain at least one known feature id."
+ echo "feature id(s) must be listed before ':' and space delimited "
+ echo "if more then one is listed."
+ echo "Please reffer to MAINTAINERS file (I: lines) for known feature ids."
+ echo $ERR
+ exit 1
+fi
+
+# Check that feature ids in subject line are known
+for i in ${FEATURES}; do
+ is_known=false
+ for j in ${KNOWN_FEATURES}; do
+ [ "${i}" = "${j}" ] && is_known=true
+ done
+ if [ ${is_known} = "false" ] ; then
+ echo $ERR
+ echo "Unknown feature '${i}' in commit 'Subject:' line."
+ echo "Feature must exist in MAINTAINERS file. If this commit intruduces "
+ echo "new feature, then this commit must add new entry into the "
+ echo "MAINTAINERS file."
+ echo $ERR
+ exit 1
+ fi
+done
+
+# Check that Message body contains valid Type: entry
+is_known=false
+for i in ${KNOWN_TYPES}; do
+ [ "${i}" = "${TYPE}" ] && is_known=true
+done
+if [ ${is_known} = "false" ] ; then
+ echo $ERR
+ echo "Unknown commit type '${TYPE}' in commit message body."
+ echo "Commit message must contain known 'Type:' entry."
+ echo "Known types are: ${KNOWN_TYPES}"
+ echo $ERR
+ exit 1
+fi
+