blob: a7c53a9a5e3ab11cd5c8fc3a8deb256506ab0bd3 [file] [log] [blame]
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +00001#!/usr/bin/python2
2
3# Copyright 2014 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8"""Add message to codereview issue.
9
Eric Borenbb0ef0a2014-06-25 11:13:27 -040010This script takes a codereview issue number as its argument and a (possibly
11multi-line) message on stdin. It appends the message to the given issue.
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000012
13Usage:
Eric Borenbb0ef0a2014-06-25 11:13:27 -040014 echo MESSAGE | %prog CODEREVIEW_ISSUE
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000015or:
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000016 %prog CODEREVIEW_ISSUE <<EOF
17 MESSAGE
18 EOF
19or:
20 %prog --help
21"""
22
23import optparse
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000024import sys
25
Eric Borenbb0ef0a2014-06-25 11:13:27 -040026import fix_pythonpath # pylint: disable=W0611
27from common.py.utils import find_depot_tools # pylint: disable=W0611
28import rietveld
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000029
30
Eric Borenbb0ef0a2014-06-25 11:13:27 -040031RIETVELD_URL = 'https://codereview.chromium.org'
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000032
33
Eric Borenbb0ef0a2014-06-25 11:13:27 -040034def add_codereview_message(issue, message):
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000035 """Add a message to a given codereview.
36
37 Args:
38 codereview_url: (string) we will extract the issue number from
39 this url, or this could simply be the issue number.
Eric Borenbb0ef0a2014-06-25 11:13:27 -040040 message: (string) message to add.
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000041 """
Eric Borenbb0ef0a2014-06-25 11:13:27 -040042 # 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)
45
46 my_rietveld.add_comment(issue, message)
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000047
48
49def main(argv):
50 """main function; see module-level docstring and GetOptionParser help.
51
52 Args:
53 argv: sys.argv[1:]-type argument list.
54 """
55 option_parser = optparse.OptionParser(usage=__doc__)
Eric Borenbb0ef0a2014-06-25 11:13:27 -040056 _, arguments = option_parser.parse_args(argv)
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000057
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000058 if len(arguments) > 1:
59 option_parser.error('Extra arguments.')
60 if len(arguments) != 1:
Eric Borenbb0ef0a2014-06-25 11:13:27 -040061 option_parser.error('Missing issue number.')
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000062
63 message = sys.stdin.read()
Eric Borenbb0ef0a2014-06-25 11:13:27 -040064 add_codereview_message(int(arguments[0]), message)
commit-bot@chromium.org0ed90022014-01-30 22:12:30 +000065
66
67if __name__ == '__main__':
68 main(sys.argv[1:])
69