add_codereview_message.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/python2
  2. # Copyright 2014 Google Inc.
  3. #
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. """Add message to codereview issue.
  7. This script takes a codereview issue number as its argument and a (possibly
  8. multi-line) message on stdin. It appends the message to the given issue.
  9. Usage:
  10. echo MESSAGE | %prog CODEREVIEW_ISSUE
  11. or:
  12. %prog CODEREVIEW_ISSUE <<EOF
  13. MESSAGE
  14. EOF
  15. or:
  16. %prog --help
  17. """
  18. import optparse
  19. import sys
  20. import fix_pythonpath # pylint: disable=W0611
  21. from common.py.utils import find_depot_tools # pylint: disable=W0611
  22. import rietveld
  23. RIETVELD_URL = 'https://codereview.chromium.org'
  24. def add_codereview_message(issue, message):
  25. """Add a message to a given codereview.
  26. Args:
  27. codereview_url: (string) we will extract the issue number from
  28. this url, or this could simply be the issue number.
  29. message: (string) message to add.
  30. """
  31. # Passing None for the email and auth_config will result in a prompt or
  32. # reuse of existing cached credentials.
  33. my_rietveld = rietveld.Rietveld(RIETVELD_URL, email=None, auth_config=None)
  34. my_rietveld.add_comment(issue, message)
  35. def main(argv):
  36. """main function; see module-level docstring and GetOptionParser help.
  37. Args:
  38. argv: sys.argv[1:]-type argument list.
  39. """
  40. option_parser = optparse.OptionParser(usage=__doc__)
  41. _, arguments = option_parser.parse_args(argv)
  42. if len(arguments) > 1:
  43. option_parser.error('Extra arguments.')
  44. if len(arguments) != 1:
  45. option_parser.error('Missing issue number.')
  46. message = sys.stdin.read()
  47. add_codereview_message(int(arguments[0]), message)
  48. if __name__ == '__main__':
  49. main(sys.argv[1:])