diff options
| -rwxr-xr-x | scripts/create-pull-request | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/scripts/create-pull-request b/scripts/create-pull-request new file mode 100755 index 0000000000..5ad7666ab3 --- /dev/null +++ b/scripts/create-pull-request | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | ODIR=pull-$$ | ||
| 3 | RELATIVE_TO="master" | ||
| 4 | COMMIT_ID="HEAD" | ||
| 5 | PULL_URL="git://git.pokylinux.org/poky-contrib.git" | ||
| 6 | PREFIX="PATCH" | ||
| 7 | |||
| 8 | usage() { | ||
| 9 | CMD=$(basename $0) | ||
| 10 | cat <<EOM | ||
| 11 | Usage: $CMD [-h] [-o output_dir] [-m msg_body_file] [-s subject] [-r relative_to] [-i commit_id] -b contrib_branch | ||
| 12 | -h Display this help message | ||
| 13 | -o output_dir Specify the output directory for the messages (default: pull-PID) | ||
| 14 | -m msg_body_file The file containing a blurb to be inserted into the summary email | ||
| 15 | -r relative_to Starting commit (default: master) | ||
| 16 | -i commit_id Ending commit (default: HEAD) | ||
| 17 | -b contrib_branch Branch-name in the git.pokylinux.org/poky-contrib tree | ||
| 18 | -s subject The subject to be inserted into the summary email | ||
| 19 | -p prefix Use [prefix N/M] instead of [PATCH N/M] as the subject prefix | ||
| 20 | |||
| 21 | Examples: | ||
| 22 | $CMD -b nitin/basic | ||
| 23 | $CMD -r distro/master -i nitin/distro -b nitin/distro | ||
| 24 | $CMD -r master -i misc -b nitin/misc -o pull-misc | ||
| 25 | $CMD -p "RFC PATCH" -b nitin/experimental | ||
| 26 | EOM | ||
| 27 | } | ||
| 28 | |||
| 29 | # Parse and validate arguments | ||
| 30 | while getopts "b:hi:m:o:r:s:p:" OPT; do | ||
| 31 | case $OPT in | ||
| 32 | b) | ||
| 33 | CONTRIB_BRANCH="$OPTARG" | ||
| 34 | ;; | ||
| 35 | h) | ||
| 36 | usage | ||
| 37 | exit 0 | ||
| 38 | ;; | ||
| 39 | i) | ||
| 40 | COMMIT_ID="$OPTARG" | ||
| 41 | ;; | ||
| 42 | m) | ||
| 43 | BODY="$OPTARG" | ||
| 44 | if [ ! -e "$BODY" ]; then | ||
| 45 | echo "ERROR: Body file does not exist" | ||
| 46 | exit 1 | ||
| 47 | fi | ||
| 48 | ;; | ||
| 49 | o) | ||
| 50 | ODIR="$OPTARG" | ||
| 51 | ;; | ||
| 52 | p) | ||
| 53 | PREFIX="$OPTARG" | ||
| 54 | ;; | ||
| 55 | r) | ||
| 56 | RELATIVE_TO="$OPTARG" | ||
| 57 | ;; | ||
| 58 | s) | ||
| 59 | SUBJECT="$OPTARG" | ||
| 60 | ;; | ||
| 61 | esac | ||
| 62 | done | ||
| 63 | |||
| 64 | if [ -z "$CONTRIB_BRANCH" ]; then | ||
| 65 | usage | ||
| 66 | exit 1 | ||
| 67 | fi | ||
| 68 | |||
| 69 | |||
| 70 | # Perform a sanity test on the web URL. Issue a warning if it is not | ||
| 71 | # accessible, but do not abort as users may want to run offline. | ||
| 72 | WEB_URL="http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=$CONTRIB_BRANCH" | ||
| 73 | wget -q $WEB_URL -O /dev/null | ||
| 74 | if [ $? -ne 0 ]; then | ||
| 75 | echo "WARNING: Branch '$CONTRIB_BRANCH' was not found on the contrib git tree." | ||
| 76 | echo " Please check your contrib-branch parameter before sending." | ||
| 77 | echo "" | ||
| 78 | fi | ||
| 79 | |||
| 80 | if [ -e $ODIR ]; then | ||
| 81 | echo "ERROR: output directory $ODIR exists." | ||
| 82 | exit 1 | ||
| 83 | fi | ||
| 84 | mkdir $ODIR | ||
| 85 | |||
| 86 | |||
| 87 | # Generate the patches and cover letter | ||
| 88 | git format-patch -M --subject-prefix="$PREFIX" -n -o $ODIR --thread=shallow --cover-letter $RELATIVE_TO..$COMMIT_ID > /dev/null | ||
| 89 | |||
| 90 | |||
| 91 | # Customize the cover letter | ||
| 92 | CL="$ODIR/0000-cover-letter.patch" | ||
| 93 | (cat <<EOM | ||
| 94 | |||
| 95 | Pull URL: $PULL_URL | ||
| 96 | Branch: $CONTRIB_BRANCH | ||
| 97 | Browse: $WEB_URL | ||
| 98 | |||
| 99 | Thanks, | ||
| 100 | $(git config user.name) <$(git config user.email)> | ||
| 101 | --- | ||
| 102 | |||
| 103 | EOM | ||
| 104 | ) | sed -i "/BLURB HERE/ r /dev/stdin" "$CL" | ||
| 105 | |||
| 106 | # If the user specified a message body, insert it into the cover letter and | ||
| 107 | # remove the BLURB token. | ||
| 108 | if [ -n "$BODY" ]; then | ||
| 109 | sed -i "/BLURB HERE/ r $BODY" "$CL" | ||
| 110 | sed -i "/BLURB HERE/ d" "$CL" | ||
| 111 | fi | ||
| 112 | |||
| 113 | # If the user specified a subject, replace the SUBJECT token with it. | ||
| 114 | if [ -n "$SUBJECT" ]; then | ||
| 115 | sed -i -e "s/\*\*\* SUBJECT HERE \*\*\*/$SUBJECT/" "$CL" | ||
| 116 | fi | ||
| 117 | |||
| 118 | |||
| 119 | # Generate report for user | ||
| 120 | cat <<EOM | ||
| 121 | The following patches have been prepared: | ||
| 122 | $(for PATCH in $(ls $ODIR/*); do echo " $PATCH"; done) | ||
| 123 | |||
| 124 | Review their content, especially the summary mail: | ||
| 125 | $CL | ||
| 126 | |||
| 127 | When you are satisfied, you can send them with: | ||
| 128 | send-pull-request -a -p $ODIR | ||
| 129 | EOM | ||
