Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
| 7 | 7 |
| 8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
| 9 | 9 |
| 10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 issue = self.GetIssue() | 778 issue = self.GetIssue() |
| 779 if not issue: | 779 if not issue: |
| 780 self._props = {} | 780 self._props = {} |
| 781 else: | 781 else: |
| 782 self._props = self.RpcServer().get_issue_properties(issue, True) | 782 self._props = self.RpcServer().get_issue_properties(issue, True) |
| 783 return self._props | 783 return self._props |
| 784 | 784 |
| 785 def GetApprovingReviewers(self): | 785 def GetApprovingReviewers(self): |
| 786 return get_approving_reviewers(self.GetIssueProperties()) | 786 return get_approving_reviewers(self.GetIssueProperties()) |
| 787 | 787 |
| 788 def AddComment(self, message): | |
| 789 return self.RpcServer().add_comment(self.GetIssue(), message) | |
| 790 | |
| 788 def SetIssue(self, issue): | 791 def SetIssue(self, issue): |
| 789 """Set this branch's issue. If issue=0, clears the issue.""" | 792 """Set this branch's issue. If issue=0, clears the issue.""" |
| 790 if issue: | 793 if issue: |
| 791 self.issue = issue | 794 self.issue = issue |
| 792 RunGit(['config', self._IssueSetting(), str(issue)]) | 795 RunGit(['config', self._IssueSetting(), str(issue)]) |
| 793 if self.rietveld_server: | 796 if self.rietveld_server: |
| 794 RunGit(['config', self._RietveldServer(), self.rietveld_server]) | 797 RunGit(['config', self._RietveldServer(), self.rietveld_server]) |
| 795 else: | 798 else: |
| 796 current_issue = self.GetIssue() | 799 current_issue = self.GetIssue() |
| 797 if current_issue: | 800 if current_issue: |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1429 issue = int(args[0]) | 1432 issue = int(args[0]) |
| 1430 except ValueError: | 1433 except ValueError: |
| 1431 DieWithError('Pass a number to set the issue or none to list it.\n' | 1434 DieWithError('Pass a number to set the issue or none to list it.\n' |
| 1432 'Maybe you want to run git cl status?') | 1435 'Maybe you want to run git cl status?') |
| 1433 cl.SetIssue(issue) | 1436 cl.SetIssue(issue) |
| 1434 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) | 1437 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) |
| 1435 return 0 | 1438 return 0 |
| 1436 | 1439 |
| 1437 | 1440 |
| 1438 def CMDcomments(parser, args): | 1441 def CMDcomments(parser, args): |
| 1439 """Shows review comments of the current changelist.""" | 1442 """Shows or posts review comments for any changelist.""" |
| 1440 (_, args) = parser.parse_args(args) | 1443 parser.add_option('-a', '--add-comment', dest='comment', |
| 1441 if args: | 1444 help='comment to add to an issue') |
| 1442 parser.error('Unsupported argument: %s' % args) | 1445 parser.add_option('-i', dest='issue', |
| 1446 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
| |
| 1447 options, args = parser.parse_args(args) | |
| 1443 | 1448 |
| 1444 cl = Changelist() | 1449 issue = None |
| 1445 if cl.GetIssue(): | 1450 if options.issue: |
| 1446 data = cl.GetIssueProperties() | 1451 try: |
| 1447 for message in sorted(data['messages'], key=lambda x: x['date']): | 1452 issue = int(options.issue) |
| 1448 if message['disapproval']: | 1453 except ValueError: |
| 1449 color = Fore.RED | 1454 DieWithError('A review issue id is expected to be a number') |
| 1450 elif message['approval']: | 1455 |
| 1451 color = Fore.GREEN | 1456 cl = Changelist(issue=issue) |
|
apavlov
2014/11/01 20:06:22
If -i is not specified, the default value of None
| |
| 1452 elif message['sender'] == data['owner_email']: | 1457 |
| 1453 color = Fore.MAGENTA | 1458 if options.comment: |
| 1454 else: | 1459 cl.AddComment(options.comment) |
| 1455 color = Fore.BLUE | 1460 return 0 |
| 1456 print '\n%s%s %s%s' % ( | 1461 |
| 1457 color, message['date'].split('.', 1)[0], message['sender'], | 1462 data = cl.GetIssueProperties() |
| 1458 Fore.RESET) | 1463 for message in sorted(data['messages'], key=lambda x: x['date']): |
| 1459 if message['text'].strip(): | 1464 if message['disapproval']: |
| 1460 print '\n'.join(' ' + l for l in message['text'].splitlines()) | 1465 color = Fore.RED |
| 1466 elif message['approval']: | |
| 1467 color = Fore.GREEN | |
| 1468 elif message['sender'] == data['owner_email']: | |
| 1469 color = Fore.MAGENTA | |
| 1470 else: | |
| 1471 color = Fore.BLUE | |
| 1472 print '\n%s%s %s%s' % ( | |
| 1473 color, message['date'].split('.', 1)[0], message['sender'], | |
| 1474 Fore.RESET) | |
| 1475 if message['text'].strip(): | |
| 1476 print '\n'.join(' ' + l for l in message['text'].splitlines()) | |
| 1461 return 0 | 1477 return 0 |
| 1462 | 1478 |
| 1463 | 1479 |
| 1464 def CMDdescription(parser, args): | 1480 def CMDdescription(parser, args): |
| 1465 """Brings up the editor for the current CL's description.""" | 1481 """Brings up the editor for the current CL's description.""" |
| 1466 cl = Changelist() | 1482 cl = Changelist() |
| 1467 if not cl.GetIssue(): | 1483 if not cl.GetIssue(): |
| 1468 DieWithError('This branch has no associated changelist.') | 1484 DieWithError('This branch has no associated changelist.') |
| 1469 description = ChangeDescription(cl.GetDescription()) | 1485 description = ChangeDescription(cl.GetDescription()) |
| 1470 description.prompt() | 1486 description.prompt() |
| (...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2883 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2899 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 2884 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2900 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 2885 | 2901 |
| 2886 | 2902 |
| 2887 if __name__ == '__main__': | 2903 if __name__ == '__main__': |
| 2888 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2904 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2889 # unit testing. | 2905 # unit testing. |
| 2890 fix_encoding.fix_encoding() | 2906 fix_encoding.fix_encoding() |
| 2891 colorama.init() | 2907 colorama.init() |
| 2892 sys.exit(main(sys.argv[1:])) | 2908 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |