DPDK CI discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: ci@dpdk.org
Subject: [dpdk-ci] [PATCH] tools: add mail filter
Date: Thu, 24 Nov 2016 17:04:54 +0100	[thread overview]
Message-ID: <1480003494-9339-1-git-send-email-thomas.monjalon@6wind.com> (raw)

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

                 reply	other threads:[~2016-11-24 16:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480003494-9339-1-git-send-email-thomas.monjalon@6wind.com \
    --to=thomas.monjalon@6wind.com \
    --cc=ci@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).