3 # Copyright 2014 Google Inc.
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
8 """Add message to codereview issue.
10 This script takes a codereview issue number as its argument and a (possibly
11 multi-line) message on stdin. It appends the message to the given issue.
14 echo MESSAGE | %prog CODEREVIEW_ISSUE
16 %prog CODEREVIEW_ISSUE <<EOF
26 import fix_pythonpath # pylint: disable=W0611
27 from common.py.utils import find_depot_tools # pylint: disable=W0611
31 RIETVELD_URL = 'https://codereview.chromium.org'
34 def add_codereview_message(issue, message):
35 """Add a message to a given codereview.
38 codereview_url: (string) we will extract the issue number from
39 this url, or this could simply be the issue number.
40 message: (string) message to add.
42 # Passing None for the email and password will result in a prompt or
43 # reuse of existing cached credentials.
44 my_rietveld = rietveld.Rietveld(RIETVELD_URL, email=None, password=None)
46 my_rietveld.add_comment(issue, message)
50 """main function; see module-level docstring and GetOptionParser help.
53 argv: sys.argv[1:]-type argument list.
55 option_parser = optparse.OptionParser(usage=__doc__)
56 _, arguments = option_parser.parse_args(argv)
58 if len(arguments) > 1:
59 option_parser.error('Extra arguments.')
60 if len(arguments) != 1:
61 option_parser.error('Missing issue number.')
63 message = sys.stdin.read()
64 add_codereview_message(int(arguments[0]), message)
67 if __name__ == '__main__':