send-pull-request 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2010-2011, Intel Corporation.
  4. # All Rights Reserved
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  14. # the GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. #
  21. # This script is intended to be used to send a patch series prepared by the
  22. # create-pull-request script to Open Embedded and The Yocto Project, as well
  23. # as to related projects and layers.
  24. #
  25. AUTO=0
  26. AUTO_CL=0
  27. GITSOBCC="--suppress-cc=all"
  28. # Prevent environment leakage to these vars.
  29. unset TO
  30. unset CC
  31. unset AUTO_CC
  32. unset EXTRA_CC
  33. usage()
  34. {
  35. cat <<EOM
  36. Usage: $(basename $0) [-h] [-a] [-c] [[-t email]...] -p pull-dir
  37. -a Send the cover letter to every recipient listed in Cc and
  38. Signed-off-by lines found in the cover letter and the patches.
  39. This option implies -c.
  40. -c Expand the Cc list for the individual patches using the Cc and
  41. Signed-off-by lines from the same patch.
  42. -C Add extra CC to each email sent.
  43. -p pull-dir Directory containing summary and patch files
  44. -t email Explicitly add email to the recipients
  45. EOM
  46. }
  47. # Collect addresses from a patch into AUTO_CC
  48. # $1: a patch file
  49. harvest_recipients()
  50. {
  51. PATCH=$1
  52. export IFS=$',\n'
  53. for REGX in "^[Cc][Cc]: *" "^[Ss]igned-[Oo]ff-[Bb]y: *"; do
  54. for EMAIL in $(sed '/^---$/q' $PATCH | grep -e "$REGX" | sed "s/$REGX//"); do
  55. if [ "${AUTO_CC/$EMAIL/}" == "$AUTO_CC" ] && [ -n "$EMAIL" ]; then
  56. if [ -z "$AUTO_CC" ]; then
  57. AUTO_CC=$EMAIL;
  58. else
  59. AUTO_CC="$AUTO_CC,$EMAIL";
  60. fi
  61. fi
  62. done
  63. done
  64. unset IFS
  65. }
  66. # Parse and verify arguments
  67. while getopts "acC:hp:t:" OPT; do
  68. case $OPT in
  69. a)
  70. AUTO=1
  71. GITSOBCC="--signed-off-by-cc"
  72. AUTO_CL=1
  73. ;;
  74. c)
  75. AUTO=1
  76. GITSOBCC="--signed-off-by-cc"
  77. ;;
  78. C)
  79. EXTRA_CC="$OPTARG"
  80. ;;
  81. h)
  82. usage
  83. exit 0
  84. ;;
  85. p)
  86. PDIR=${OPTARG%/}
  87. if [ ! -d $PDIR ]; then
  88. echo "ERROR: pull-dir \"$PDIR\" does not exist."
  89. usage
  90. exit 1
  91. fi
  92. ;;
  93. t)
  94. if [ -n "$TO" ]; then
  95. TO="$TO,$OPTARG"
  96. else
  97. TO="$OPTARG"
  98. fi
  99. ;;
  100. esac
  101. done
  102. if [ -z "$PDIR" ]; then
  103. echo "ERROR: you must specify a pull-dir."
  104. usage
  105. exit 1
  106. fi
  107. # Verify the cover letter is complete and free of tokens
  108. if [ -e $PDIR/0000-cover-letter.patch ]; then
  109. CL="$PDIR/0000-cover-letter.patch"
  110. for TOKEN in SUBJECT BLURB; do
  111. grep -q "*** $TOKEN HERE ***" "$CL"
  112. if [ $? -eq 0 ]; then
  113. echo "ERROR: Please edit $CL and try again (Look for '*** $TOKEN HERE ***')."
  114. exit 1
  115. fi
  116. done
  117. else
  118. echo "WARNING: No cover letter will be sent."
  119. fi
  120. # Harvest emails from the generated patches and populate AUTO_CC.
  121. if [ $AUTO_CL -eq 1 ]; then
  122. for PATCH in $PDIR/*.patch; do
  123. harvest_recipients $PATCH
  124. done
  125. fi
  126. AUTO_TO="$(git config sendemail.to)"
  127. if [ -n "$AUTO_TO" ]; then
  128. if [ -n "$TO" ]; then
  129. TO="$TO,$AUTO_TO"
  130. else
  131. TO="$AUTO_TO"
  132. fi
  133. fi
  134. if [ -z "$TO" ] && [ -z "$AUTO_CC" ]; then
  135. echo "ERROR: you have not specified any recipients."
  136. usage
  137. exit 1
  138. fi
  139. # Convert the collected addresses into git-send-email argument strings
  140. export IFS=$','
  141. GIT_TO=$(for R in $TO; do echo -n "--to='$R' "; done)
  142. GIT_CC=$(for R in $AUTO_CC; do echo -n "--cc='$R' "; done)
  143. GIT_EXTRA_CC=$(for R in $EXTRA_CC; do echo -n "--cc='$R' "; done)
  144. unset IFS
  145. # Handoff to git-send-email. It will perform the send confirmation.
  146. PATCHES=$(echo $PDIR/*.patch)
  147. if [ $AUTO_CL -eq 1 ]; then
  148. # Send the cover letter to every recipient, both specified as well as
  149. # harvested. Then remove it from the patches list.
  150. eval "git send-email $GIT_TO $GIT_CC $GIT_EXTRA_CC --confirm=always --no-chain-reply-to --suppress-cc=all $CL"
  151. if [ $? -eq 1 ]; then
  152. echo "ERROR: failed to send cover-letter with automatic recipients."
  153. exit 1
  154. fi
  155. PATCHES=${PATCHES/"$CL"/}
  156. fi
  157. # Send the patch to the specified recipients and, if -c was specified, those git
  158. # finds in this specific patch.
  159. eval "git send-email $GIT_TO $GIT_EXTRA_CC --confirm=always --no-chain-reply-to $GITSOBCC $PATCHES"
  160. if [ $? -eq 1 ]; then
  161. echo "ERROR: failed to send patches."
  162. exit 1
  163. fi