From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id 95C4C58D6 for ; Fri, 25 Nov 2016 18:02:26 +0100 (CET) Received: by mail-wm0-f42.google.com with SMTP id f82so97464209wmf.1 for ; Fri, 25 Nov 2016 09:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=cXB8dPn9K7qO+QpBMQkjAbsM3ZFaCQttSFZM1CbT9qc=; b=BOe3kGRfrToAi1zwmMaV3CUdYAeP4jJQnBYtV/cuE95KSk0PmcMBYp7zPF0naQI5+D /x90kgAcV0T1b2SQ7pjKh96DZLI5QQSwN2CdaYYO3Z6wAXnoWn7RORTKiR4jBgxE/znR E3nFGb7Nm2s3dk/QwRFZEX9fZX4L7iHZLk3KEcueq5mCNyINV45VEKil88eKzRw7Hp/3 mb1GZBNEr5Zz6NegVGn8mii7BeVTjr5p3dHDEFKVIpiVxkeBjCJYno1hJT0Mu72weFeE BDJmVLLvnDyJToAhT7BWiXBqSX5Qv3tfXxrjIbrc+a2S74bQ88iQLlpIeImFTU3odSRJ axbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=cXB8dPn9K7qO+QpBMQkjAbsM3ZFaCQttSFZM1CbT9qc=; b=B8qG51+hn0EVbv9Xz2IHkOUhwgn3WY4NAQMmAPWM1HfFd6yHldodFU1FqtN8NLgkDT +/IK+UgrWZNX71HXHaHjxJvrK8pLDz6J6tVUqZgdL7EX81YAbi3q05fFfdGJ4mZuuBSi Xx4suYA2gHaa/V+kGPAlDA54vcA92IS37T1gx/wwIGKrQIC9RVMkLNM/mIKPxxraBqMe OQGPqNhads/ved+tOJKPr9EM/ydJ4Il+YwRG2Ukxugy9dbQHS2s120WayFa+IREHw0p9 sg1UPLCQl28JiwzgAvmeGiOtADzdYRdZciRzvqglVwOo3L+qU1+2ItieJ9gwsJT5DjOp rAAQ== X-Gm-Message-State: AKaTC01WKfoTag65qSxJpbCSYKdo4/qJosTBoisFCLUaRNgZnSRgn0Ds2PCbjFE2nZBMIh+r X-Received: by 10.28.199.71 with SMTP id x68mr8186284wmf.34.1480093346047; Fri, 25 Nov 2016 09:02:26 -0800 (PST) Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id ct7sm29707757wjc.2.2016.11.25.09.02.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Nov 2016 09:02:25 -0800 (PST) From: Thomas Monjalon To: ci@dpdk.org Date: Fri, 25 Nov 2016 18:02:08 +0100 Message-Id: <1480093334-29957-2-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1480093334-29957-1-git-send-email-thomas.monjalon@6wind.com> References: <1480093334-29957-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-ci] [PATCH 1/7] tools: add mail filter X-BeenThere: ci@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: CI discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Nov 2016 17:02:26 -0000 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 --- 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..fd75271 --- /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