diff options
author | Darren Hart <dvhart@linux.intel.com> | 2010-11-06 10:06:11 -0400 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-11-10 21:22:27 +0800 |
commit | 2e0ab8c18f1869a6fd1f53140fed0b4f3a1c3274 (patch) | |
tree | 1a2587e13317e5d2ee2415fcb7a239a98f2608af /scripts | |
parent | 1f0e2cf16afdc7d8e895a28d45b0d956144c56d6 (diff) | |
download | openembedded-core-contrib-2e0ab8c18f1869a6fd1f53140fed0b4f3a1c3274.tar.gz |
git-pull: add send-pull-request script
send-pull-request facilitates sending pull requests generated by
create-pull-request. The primary role of this script is to harvest email
addresses from the patches and send them out. A working installation of sendmail
(exim, postfix, msmtp, etc.) is required to use this script.
You can explicitly specify To addresses with the -t option. As this can be
tedious, the -a option will scan all the patches for To, CC, and *-by lines and
the collected addresses to the To and CC headers for each patch.
This script uses an identical recipients list for every patch, including the
cover letter. This is by design. Existing tools will auto-generate the CC header
for individual patches, but since they don't apply it to the other patches, the
recipients can lack the necessary context to provide a meaningful review. This
is especially true of the cover letter.
The pull directory generated by the create-pull-request script is specified
using the -p option.
Signed-off-by: Darren Hart <dvhart@linux.intel.com>
CC: Nitin A Kamble <nitin.a.kamble@intel.com>
CC: Richard Purdie <rpurdie@linux.intel.com>
CC: Saul Wold <saul.wold@intel.com>
CC: Bruce Ashfield <bruce.ashfield@windriver.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/send-pull-request | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/scripts/send-pull-request b/scripts/send-pull-request new file mode 100755 index 00000000000..0576a5dd441 --- /dev/null +++ b/scripts/send-pull-request @@ -0,0 +1,133 @@ +#!/bin/bash +AUTO=0 + +usage() +{ +cat <<EOM +Usage: $(basename $0) [-h] [-a] [[-t email]...] -p pull-dir + -t email Explicitly add email to the recipients + -a Automatically harvest recipients from "*-by: email" lines + in the patches in the pull-dir + -p pull-dir Directory containing summary and patch files +EOM +} + +# Collect To and CC addresses from the patch files if they exist +# $1: Which header to add the recipients to, "TO" or "CC" +# $2: The regex to match and strip from the line with email addresses +harvest_recipients() +{ + TO_CC=$1 + REGX=$2 + export IFS=$',\n' + for PATCH in $PDIR/*.patch; do + # Grab To addresses + for EMAIL in $(sed '/^---$/q' $PATCH | grep -e "$REGX" | sed "s/$REGX//"); do + if [ "$TO_CC" == "TO" ] && [ "${TO/$EMAIL/}" == "$TO" ] && [ -n "$EMAIL" ]; then + if [ -z "$TO" ]; then TO=$EMAIL; else TO="$TO,$EMAIL"; fi + elif [ "$TO_CC" == "CC" ] && [ "${CC/$EMAIL/}" == "$CC" ] && [ -n "$EMAIL" ]; then + if [ -z "$CC" ]; then CC=$EMAIL; else CC="$CC,$EMAIL"; fi + fi + done + done + unset IFS +} + + +# Parse and verify arguments +while getopts "ahp:t:" OPT; do + case $OPT in + a) + AUTO=1 + ;; + h) + usage + exit 0 + ;; + p) + PDIR=${OPTARG%/} + if [ ! -d $PDIR ]; then + echo "ERROR: pull-dir \"$PDIR\" does not exist." + usage + exit 1 + fi + ;; + t) + if [ -n "$TO" ]; then + TO="$TO,$OPTARG" + else + TO="$OPTARG" + fi + ;; + esac +done + +if [ -z "$PDIR" ]; then + echo "ERROR: you must specify a pull-dir." + usage + exit 1 +fi + + +# Verify the cover letter is complete and free of tokens +CL="$PDIR/0000-cover-letter.patch" +for TOKEN in SUBJECT BLURB; do + grep -q "*** $TOKEN HERE ***" "$CL" + if [ $? -eq 0 ]; then + echo "ERROR: Please edit $CL and try again (Look for '*** $TOKEN HERE ***')." + exit 1 + fi +done + + +# Harvest emails from the generated patches and populate the TO and CC variables +# In addition to To and CC headers/lines, the common Signed-off-by, Tested-by, +# etc. (*-by) will be added to CC. +if [ $AUTO -eq 1 ]; then + harvest_recipients TO "^[Tt][Oo]: *" + harvest_recipients CC "^[Cc][Cc]: *" + harvest_recipients CC "^.*-[Bb][Yy]: *" +fi + +if [ -z "$TO" ] && [ -z "$CC" ]; then + echo "ERROR: you have not specified any recipients." + usage + exit 1 +fi + + +# Generate report for the user and require confirmation before sending +cat <<EOM +The following patches: +$(for PATCH in $PDIR/*.patch; do echo " $PATCH"; done) + +will be sent to the following recipients: + To: $TO + CC: $CC + +EOM +echo "Continue? [y/N] " +read cont + +if [ "$cont" == "y" ] || [ "$cont" == "Y" ]; then + ERROR=0 + for PATCH in $PDIR/*patch; do + # Insert To and CC headers via formail to keep them separate and + # appending them to the sendmail command as -- $TO $CC has proven + # to be an exercise in futility. + # + # Use tail to remove the email envelope from git or formail as + # msmtp (sendmail) would choke on them. + cat $PATCH | formail -I "To: $TO" -I "CC: $CC" | tail -n +2 | sendmail -t + if [ $? -eq 1 ]; then + ERROR=1 + fi + done + if [ $ERROR -eq 1 ]; then + echo "ERROR: sendmail failed to send one or more messages. Check your" + echo " sendmail log for details." + fi +else + echo "Send aborted." +fi + |