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 | poky-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 0000000000..0576a5dd44 --- /dev/null +++ b/scripts/send-pull-request | |||
@@ -0,0 +1,133 @@ | |||
1 | #!/bin/bash | ||
2 | AUTO=0 | ||
3 | |||
4 | usage() | ||
5 | { | ||
6 | cat <<EOM | ||
7 | Usage: $(basename $0) [-h] [-a] [[-t email]...] -p pull-dir | ||
8 | -t email Explicitly add email to the recipients | ||
9 | -a Automatically harvest recipients from "*-by: email" lines | ||
10 | in the patches in the pull-dir | ||
11 | -p pull-dir Directory containing summary and patch files | ||
12 | EOM | ||
13 | } | ||
14 | |||
15 | # Collect To and CC addresses from the patch files if they exist | ||
16 | # $1: Which header to add the recipients to, "TO" or "CC" | ||
17 | # $2: The regex to match and strip from the line with email addresses | ||
18 | harvest_recipients() | ||
19 | { | ||
20 | TO_CC=$1 | ||
21 | REGX=$2 | ||
22 | export IFS=$',\n' | ||
23 | for PATCH in $PDIR/*.patch; do | ||
24 | # Grab To addresses | ||
25 | for EMAIL in $(sed '/^---$/q' $PATCH | grep -e "$REGX" | sed "s/$REGX//"); do | ||
26 | if [ "$TO_CC" == "TO" ] && [ "${TO/$EMAIL/}" == "$TO" ] && [ -n "$EMAIL" ]; then | ||
27 | if [ -z "$TO" ]; then TO=$EMAIL; else TO="$TO,$EMAIL"; fi | ||
28 | elif [ "$TO_CC" == "CC" ] && [ "${CC/$EMAIL/}" == "$CC" ] && [ -n "$EMAIL" ]; then | ||
29 | if [ -z "$CC" ]; then CC=$EMAIL; else CC="$CC,$EMAIL"; fi | ||
30 | fi | ||
31 | done | ||
32 | done | ||
33 | unset IFS | ||
34 | } | ||
35 | |||
36 | |||
37 | # Parse and verify arguments | ||
38 | while getopts "ahp:t:" OPT; do | ||
39 | case $OPT in | ||
40 | a) | ||
41 | AUTO=1 | ||
42 | ;; | ||
43 | h) | ||
44 | usage | ||
45 | exit 0 | ||
46 | ;; | ||
47 | p) | ||
48 | PDIR=${OPTARG%/} | ||
49 | if [ ! -d $PDIR ]; then | ||
50 | echo "ERROR: pull-dir \"$PDIR\" does not exist." | ||
51 | usage | ||
52 | exit 1 | ||
53 | fi | ||
54 | ;; | ||
55 | t) | ||
56 | if [ -n "$TO" ]; then | ||
57 | TO="$TO,$OPTARG" | ||
58 | else | ||
59 | TO="$OPTARG" | ||
60 | fi | ||
61 | ;; | ||
62 | esac | ||
63 | done | ||
64 | |||
65 | if [ -z "$PDIR" ]; then | ||
66 | echo "ERROR: you must specify a pull-dir." | ||
67 | usage | ||
68 | exit 1 | ||
69 | fi | ||
70 | |||
71 | |||
72 | # Verify the cover letter is complete and free of tokens | ||
73 | CL="$PDIR/0000-cover-letter.patch" | ||
74 | for TOKEN in SUBJECT BLURB; do | ||
75 | grep -q "*** $TOKEN HERE ***" "$CL" | ||
76 | if [ $? -eq 0 ]; then | ||
77 | echo "ERROR: Please edit $CL and try again (Look for '*** $TOKEN HERE ***')." | ||
78 | exit 1 | ||
79 | fi | ||
80 | done | ||
81 | |||
82 | |||
83 | # Harvest emails from the generated patches and populate the TO and CC variables | ||
84 | # In addition to To and CC headers/lines, the common Signed-off-by, Tested-by, | ||
85 | # etc. (*-by) will be added to CC. | ||
86 | if [ $AUTO -eq 1 ]; then | ||
87 | harvest_recipients TO "^[Tt][Oo]: *" | ||
88 | harvest_recipients CC "^[Cc][Cc]: *" | ||
89 | harvest_recipients CC "^.*-[Bb][Yy]: *" | ||
90 | fi | ||
91 | |||
92 | if [ -z "$TO" ] && [ -z "$CC" ]; then | ||
93 | echo "ERROR: you have not specified any recipients." | ||
94 | usage | ||
95 | exit 1 | ||
96 | fi | ||
97 | |||
98 | |||
99 | # Generate report for the user and require confirmation before sending | ||
100 | cat <<EOM | ||
101 | The following patches: | ||
102 | $(for PATCH in $PDIR/*.patch; do echo " $PATCH"; done) | ||
103 | |||
104 | will be sent to the following recipients: | ||
105 | To: $TO | ||
106 | CC: $CC | ||
107 | |||
108 | EOM | ||
109 | echo "Continue? [y/N] " | ||
110 | read cont | ||
111 | |||
112 | if [ "$cont" == "y" ] || [ "$cont" == "Y" ]; then | ||
113 | ERROR=0 | ||
114 | for PATCH in $PDIR/*patch; do | ||
115 | # Insert To and CC headers via formail to keep them separate and | ||
116 | # appending them to the sendmail command as -- $TO $CC has proven | ||
117 | # to be an exercise in futility. | ||
118 | # | ||
119 | # Use tail to remove the email envelope from git or formail as | ||
120 | # msmtp (sendmail) would choke on them. | ||
121 | cat $PATCH | formail -I "To: $TO" -I "CC: $CC" | tail -n +2 | sendmail -t | ||
122 | if [ $? -eq 1 ]; then | ||
123 | ERROR=1 | ||
124 | fi | ||
125 | done | ||
126 | if [ $ERROR -eq 1 ]; then | ||
127 | echo "ERROR: sendmail failed to send one or more messages. Check your" | ||
128 | echo " sendmail log for details." | ||
129 | fi | ||
130 | else | ||
131 | echo "Send aborted." | ||
132 | fi | ||
133 | |||