pull_requests_interval.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # Copyright 2017 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. if [ "x$1" = "x" ] ; then
  16. echo "Usage: $0 <first ref> [second ref]"
  17. exit 1
  18. else
  19. first=$1
  20. fi
  21. if [ -n $2 ] ; then
  22. second=HEAD
  23. fi
  24. if [ -e ~/github-credentials.vars ] ; then
  25. . ~/github-credentials.vars
  26. fi
  27. if [ "x$github_client_id" = "x" ] || [ "x$github_client_secret" = "x" ] ; then
  28. echo "Warning: you don't have github credentials set."
  29. echo
  30. echo "You may end up exceeding guest quota quickly."
  31. echo "You can create an application for yourself,"
  32. echo "and get its credentials. Go to"
  33. echo
  34. echo " https://github.com/settings/developers"
  35. echo
  36. echo "and click 'Register a new application'."
  37. echo
  38. echo "From the application's information, copy/paste"
  39. echo "its Client ID and Client Secret, into the file"
  40. echo
  41. echo " ~/github-credentials.vars"
  42. echo
  43. echo "with the following format:"
  44. echo
  45. echo "github_client_id=0123456789abcdef0123"
  46. echo "github_client_secret=0123456789abcdef0123456789abcdef"
  47. echo
  48. echo
  49. addendum=""
  50. else
  51. addendum="?client_id=$github_client_id&client_secret=$github_client_secret"
  52. fi
  53. unset notfirst
  54. echo "["
  55. git log --pretty=oneline $1..$2 |
  56. grep '[^ ]\+ Merge pull request #[0-9]\{4,6\} ' |
  57. cut -f 2 -d# |
  58. cut -f 1 -d\ |
  59. sort -u |
  60. while read id ; do
  61. if [ "x$notfirst" = "x" ] ; then
  62. notfirst=true
  63. else
  64. echo ","
  65. fi
  66. echo -n " {\"url\": \"https://github.com/grpc/grpc/pull/$id\","
  67. out=`mktemp`
  68. curl -s "https://api.github.com/repos/grpc/grpc/pulls/$id$addendum" > $out
  69. echo -n " "`grep '"title"' $out`
  70. echo -n " "`grep '"login"' $out | head -1`
  71. echo -n " \"pr\": $id }"
  72. rm $out
  73. done
  74. echo
  75. echo "]"