Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index bd65e12b02e4b30162e46c54f72bd25ecbb453b6..05d4f7178c98d478f4f49c9337b91b9bb64f156a 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -785,6 +785,9 @@ or verify this branch is set up to track another (via the --track argument to |
| def GetApprovingReviewers(self): |
| return get_approving_reviewers(self.GetIssueProperties()) |
| + def AddComment(self, message): |
| + return self.RpcServer().add_comment(self.GetIssue(), message) |
| + |
| def SetIssue(self, issue): |
| """Set this branch's issue. If issue=0, clears the issue.""" |
| if issue: |
| @@ -1436,28 +1439,41 @@ def CMDissue(parser, args): |
| def CMDcomments(parser, args): |
| - """Shows review comments of the current changelist.""" |
| - (_, args) = parser.parse_args(args) |
| - if args: |
| - parser.error('Unsupported argument: %s' % args) |
| + """Shows or posts review comments for any changelist.""" |
| + parser.add_option('-a', '--add-comment', dest='comment', |
| + help='comment to add to an issue') |
| + parser.add_option('-i', dest='issue', |
| + help="review issue id (defaults to current issue)") |
|
iannucci
2014/10/31 23:29:12
I think this should actually default to cl.GetIssu
apavlov
2014/11/01 06:59:21
Actually, that's what I meant. What is the right w
|
| + options, args = parser.parse_args(args) |
| - cl = Changelist() |
| - if cl.GetIssue(): |
| - data = cl.GetIssueProperties() |
| - for message in sorted(data['messages'], key=lambda x: x['date']): |
| - if message['disapproval']: |
| - color = Fore.RED |
| - elif message['approval']: |
| - color = Fore.GREEN |
| - elif message['sender'] == data['owner_email']: |
| - color = Fore.MAGENTA |
| - else: |
| - color = Fore.BLUE |
| - print '\n%s%s %s%s' % ( |
| - color, message['date'].split('.', 1)[0], message['sender'], |
| - Fore.RESET) |
| - if message['text'].strip(): |
| - print '\n'.join(' ' + l for l in message['text'].splitlines()) |
| + issue = None |
| + if options.issue: |
| + try: |
| + issue = int(options.issue) |
| + except ValueError: |
| + DieWithError('A review issue id is expected to be a number') |
| + |
| + cl = Changelist(issue=issue) |
|
apavlov
2014/11/01 20:06:22
If -i is not specified, the default value of None
|
| + |
| + if options.comment: |
| + cl.AddComment(options.comment) |
| + return 0 |
| + |
| + data = cl.GetIssueProperties() |
| + for message in sorted(data['messages'], key=lambda x: x['date']): |
| + if message['disapproval']: |
| + color = Fore.RED |
| + elif message['approval']: |
| + color = Fore.GREEN |
| + elif message['sender'] == data['owner_email']: |
| + color = Fore.MAGENTA |
| + else: |
| + color = Fore.BLUE |
| + print '\n%s%s %s%s' % ( |
| + color, message['date'].split('.', 1)[0], message['sender'], |
| + Fore.RESET) |
| + if message['text'].strip(): |
| + print '\n'.join(' ' + l for l in message['text'].splitlines()) |
| return 0 |