[dpdk-ci] [PATCH] tools: add mail filter
Thomas Monjalon
thomas.monjalon at 6wind.com
Thu Nov 24 17:04:54 CET 2016
This script acts as a pipe which blocks non-patch emails.
It can be used as a first filter before processing a patch.
Signed-off-by: Thomas Monjalon <thomas.monjalon at 6wind.com>
---
tools/filter-patch-email.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100755 tools/filter-patch-email.sh
diff --git a/tools/filter-patch-email.sh b/tools/filter-patch-email.sh
new file mode 100755
index 0000000..6686956
--- /dev/null
+++ b/tools/filter-patch-email.sh
@@ -0,0 +1,76 @@
+#! /bin/sh -e
+
+# This file is in the public domain.
+
+print_usage () {
+ cat <<- END_OF_HELP
+ usage: $(basename $0) < email
+
+ Filter out email from stdin if does not match patch criterias.
+ END_OF_HELP
+}
+
+while getopts h ARG ; do
+ case $ARG in
+ h ) print_usage ; exit 0 ;;
+ ? ) print_usage ; exit 1 ;;
+ esac
+done
+
+if [ -t 0 ] ; then
+ echo 'nothing to read on stdin' >&2
+ exit 0
+fi
+
+fifo=/tmp/$(basename $0 sh)$$
+mkfifo $fifo
+trap "rm -f $fifo" INT EXIT
+
+parse ()
+{
+ gitsend=false
+ patchsubject=false
+ content=false
+ minusline=false
+ plusline=false
+ atline=false
+ done=false
+ while IFS= read -r line ; do
+ printf '%s\n' "$line"
+ set -- $line
+ if ! $content ; then
+ [ "$1" != 'X-Mailer:' -o "$2" != 'git-send-email' ] || gitsend=true
+ if echo "$line" | grep -qa '^Subject:.*\[PATCH' ; then
+ subject=$(echo "$line" | sed 's,^Subject:[[:space:]]*,,')
+ while [ -n "$subject" ] ; do
+ echo "$subject" | grep -q '^\[' || break
+ if echo "$subject" | grep -q '^\[PATCH' ; then
+ patchsubject=true
+ break
+ fi
+ subject=$(echo "$subject" | sed 's,^[^]]*\][[:space:]]*,,')
+ done
+ fi
+ [ -n "$line" ] || content=true
+ elif ! $done ; then
+ $gitsend || $patchsubject || break
+ [ "$1" != '---' ] || minusline=true
+ [ "$1" != '+++' ] || plusline=true
+ [ "$1" != '@@' ] || atline=true
+ if $minusline && $plusline && $atline ; then
+ echo 1 >$fifo
+ done=true
+ fi
+ fi
+ done
+ $done || echo 0 >$fifo
+ exec >&-
+}
+
+waitparsing ()
+{
+ result=$(cat $fifo)
+ [ "$result" = 0 ] || cat
+}
+
+parse | waitparsing
--
2.7.0
More information about the ci
mailing list