commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 1 | #!/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 Boren | bb0ef0a | 2014-06-25 11:13:27 -0400 | [diff] [blame] | 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. |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 12 | |
| 13 | Usage: |
Eric Boren | bb0ef0a | 2014-06-25 11:13:27 -0400 | [diff] [blame] | 14 | echo MESSAGE | %prog CODEREVIEW_ISSUE |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 15 | or: |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 16 | %prog CODEREVIEW_ISSUE <<EOF |
| 17 | MESSAGE |
| 18 | EOF |
| 19 | or: |
| 20 | %prog --help |
| 21 | """ |
| 22 | |
| 23 | import optparse |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 24 | import sys |
| 25 | |
Eric Boren | bb0ef0a | 2014-06-25 11:13:27 -0400 | [diff] [blame] | 26 | import fix_pythonpath # pylint: disable=W0611 |
| 27 | from common.py.utils import find_depot_tools # pylint: disable=W0611 |
| 28 | import rietveld |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 29 | |
| 30 | |
Eric Boren | bb0ef0a | 2014-06-25 11:13:27 -0400 | [diff] [blame] | 31 | RIETVELD_URL = 'https://codereview.chromium.org' |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 32 | |
| 33 | |
Eric Boren | bb0ef0a | 2014-06-25 11:13:27 -0400 | [diff] [blame] | 34 | def add_codereview_message(issue, message): |
borenet | 3da21d2 | 2014-06-25 08:40:58 -0700 | [diff] [blame] | 35 | """Add a message to a given codereview. |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 36 | |
borenet | 3da21d2 | 2014-06-25 08:40:58 -0700 | [diff] [blame] | 37 | Args: |
| 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. |
| 41 | """ |
| 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) |
| 45 | |
| 46 | my_rietveld.add_comment(issue, message) |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 47 | |
| 48 | |
| 49 | def main(argv): |
borenet | 3da21d2 | 2014-06-25 08:40:58 -0700 | [diff] [blame] | 50 | """main function; see module-level docstring and GetOptionParser help. |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 51 | |
borenet | 3da21d2 | 2014-06-25 08:40:58 -0700 | [diff] [blame] | 52 | Args: |
| 53 | argv: sys.argv[1:]-type argument list. |
| 54 | """ |
| 55 | option_parser = optparse.OptionParser(usage=__doc__) |
| 56 | _, arguments = option_parser.parse_args(argv) |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 57 | |
borenet | 3da21d2 | 2014-06-25 08:40:58 -0700 | [diff] [blame] | 58 | if len(arguments) > 1: |
| 59 | option_parser.error('Extra arguments.') |
| 60 | if len(arguments) != 1: |
| 61 | option_parser.error('Missing issue number.') |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 62 | |
borenet | 3da21d2 | 2014-06-25 08:40:58 -0700 | [diff] [blame] | 63 | message = sys.stdin.read() |
| 64 | add_codereview_message(int(arguments[0]), message) |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 65 | |
| 66 | |
| 67 | if __name__ == '__main__': |
borenet | 3da21d2 | 2014-06-25 08:40:58 -0700 | [diff] [blame] | 68 | main(sys.argv[1:]) |
commit-bot@chromium.org | 0ed9002 | 2014-01-30 22:12:30 +0000 | [diff] [blame] | 69 | |