DPDK CI discussions
 help / color / mirror / Atom feed
* [dpdk-ci] [PATCH] tools: add mail filter
@ 2016-11-24 16:04 Thomas Monjalon
  0 siblings, 0 replies; only message in thread
From: Thomas Monjalon @ 2016-11-24 16:04 UTC (permalink / raw)
  To: ci

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@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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-11-24 16:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-24 16:04 [dpdk-ci] [PATCH] tools: add mail filter Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).