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 import json | 10 import json |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 self.has_patchset = False | 640 self.has_patchset = False |
641 | 641 |
642 def GetMostRecentPatchset(self, issue): | 642 def GetMostRecentPatchset(self, issue): |
643 return self.RpcServer().get_issue_properties( | 643 return self.RpcServer().get_issue_properties( |
644 int(issue), False)['patchsets'][-1] | 644 int(issue), False)['patchsets'][-1] |
645 | 645 |
646 def GetPatchSetDiff(self, issue, patchset): | 646 def GetPatchSetDiff(self, issue, patchset): |
647 return self.RpcServer().get( | 647 return self.RpcServer().get( |
648 '/download/issue%s_%s.diff' % (issue, patchset)) | 648 '/download/issue%s_%s.diff' % (issue, patchset)) |
649 | 649 |
| 650 def GetApprovingReviewers(self, issue): |
| 651 return get_approving_reviewers( |
| 652 self.RpcServer().get_issue_properties(int(issue), True)) |
| 653 |
650 def SetIssue(self, issue): | 654 def SetIssue(self, issue): |
651 """Set this branch's issue. If issue=0, clears the issue.""" | 655 """Set this branch's issue. If issue=0, clears the issue.""" |
652 if issue: | 656 if issue: |
653 RunGit(['config', self._IssueSetting(), str(issue)]) | 657 RunGit(['config', self._IssueSetting(), str(issue)]) |
654 if self.rietveld_server: | 658 if self.rietveld_server: |
655 RunGit(['config', self._RietveldServer(), self.rietveld_server]) | 659 RunGit(['config', self._RietveldServer(), self.rietveld_server]) |
656 else: | 660 else: |
657 RunGit(['config', '--unset', self._IssueSetting()]) | 661 RunGit(['config', '--unset', self._IssueSetting()]) |
658 self.SetPatchset(0) | 662 self.SetPatchset(0) |
659 self.has_issue = False | 663 self.has_issue = False |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 self._description += '\n' | 870 self._description += '\n' |
867 self._description += '\n' + line | 871 self._description += '\n' + line |
868 | 872 |
869 def get_reviewers(self): | 873 def get_reviewers(self): |
870 """Retrieves the list of reviewers.""" | 874 """Retrieves the list of reviewers.""" |
871 regexp = re.compile(self.R_LINE, re.MULTILINE) | 875 regexp = re.compile(self.R_LINE, re.MULTILINE) |
872 reviewers = [i.group(2).strip() for i in regexp.finditer(self._description)] | 876 reviewers = [i.group(2).strip() for i in regexp.finditer(self._description)] |
873 return cleanup_list(reviewers) | 877 return cleanup_list(reviewers) |
874 | 878 |
875 | 879 |
| 880 def get_approving_reviewers(props): |
| 881 """Retrieves the reviewers that approved a CL from the issue properties with |
| 882 messages. |
| 883 |
| 884 Note that the list may contain reviewers that are not committer, thus are not |
| 885 considered by the CQ. |
| 886 """ |
| 887 return sorted( |
| 888 set( |
| 889 message['sender'] |
| 890 for message in props['messages'] |
| 891 if message['approval'] and message['sender'] in props['reviewers'] |
| 892 ) |
| 893 ) |
| 894 |
| 895 |
876 def FindCodereviewSettingsFile(filename='codereview.settings'): | 896 def FindCodereviewSettingsFile(filename='codereview.settings'): |
877 """Finds the given file starting in the cwd and going up. | 897 """Finds the given file starting in the cwd and going up. |
878 | 898 |
879 Only looks up to the top of the repository unless an | 899 Only looks up to the top of the repository unless an |
880 'inherit-review-settings-ok' file exists in the root of the repository. | 900 'inherit-review-settings-ok' file exists in the root of the repository. |
881 """ | 901 """ |
882 inherit_ok_file = 'inherit-review-settings-ok' | 902 inherit_ok_file = 'inherit-review-settings-ok' |
883 cwd = os.getcwd() | 903 cwd = os.getcwd() |
884 root = os.path.abspath(RunGit(['rev-parse', '--show-cdup']).strip()) | 904 root = os.path.abspath(RunGit(['rev-parse', '--show-cdup']).strip()) |
885 if os.path.isfile(os.path.join(root, inherit_ok_file)): | 905 if os.path.isfile(os.path.join(root, inherit_ok_file)): |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 if not cl.GetIssue() and options.bypass_hooks: | 1499 if not cl.GetIssue() and options.bypass_hooks: |
1480 change_desc = ChangeDescription(CreateDescriptionFromLog([base_branch])) | 1500 change_desc = ChangeDescription(CreateDescriptionFromLog([base_branch])) |
1481 else: | 1501 else: |
1482 print 'No description set.' | 1502 print 'No description set.' |
1483 print 'Visit %s/edit to set it.' % (cl.GetIssueURL()) | 1503 print 'Visit %s/edit to set it.' % (cl.GetIssueURL()) |
1484 return 1 | 1504 return 1 |
1485 | 1505 |
1486 # Keep a separate copy for the commit message, because the commit message | 1506 # Keep a separate copy for the commit message, because the commit message |
1487 # contains the link to the Rietveld issue, while the Rietveld message contains | 1507 # contains the link to the Rietveld issue, while the Rietveld message contains |
1488 # the commit viewvc url. | 1508 # the commit viewvc url. |
| 1509 # Keep a separate copy for the commit message. |
| 1510 if cl.GetIssue(): |
| 1511 change_desc.update_reviewers(cl.GetApprovingReviewers(cl.GetIssue())) |
| 1512 |
1489 commit_desc = ChangeDescription(change_desc.description) | 1513 commit_desc = ChangeDescription(change_desc.description) |
1490 if cl.GetIssue(): | 1514 if cl.GetIssue(): |
1491 commit_desc.append_footer('Review URL: %s' % cl.GetIssueURL()) | 1515 commit_desc.append_footer('Review URL: %s' % cl.GetIssueURL()) |
1492 if options.contributor: | 1516 if options.contributor: |
1493 commit_desc.append_footer('Patch from %s.' % options.contributor) | 1517 commit_desc.append_footer('Patch from %s.' % options.contributor) |
1494 | 1518 |
1495 print 'Description:', repr(commit_desc.description) | 1519 print 'Description:', repr(commit_desc.description) |
1496 | 1520 |
1497 branches = [base_branch, cl.GetBranchRef()] | 1521 branches = [base_branch, cl.GetBranchRef()] |
1498 if not options.force: | 1522 if not options.force: |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1968 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1992 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1969 | 1993 |
1970 # Not a known command. Default to help. | 1994 # Not a known command. Default to help. |
1971 GenUsage(parser, 'help') | 1995 GenUsage(parser, 'help') |
1972 return CMDhelp(parser, argv) | 1996 return CMDhelp(parser, argv) |
1973 | 1997 |
1974 | 1998 |
1975 if __name__ == '__main__': | 1999 if __name__ == '__main__': |
1976 fix_encoding.fix_encoding() | 2000 fix_encoding.fix_encoding() |
1977 sys.exit(main(sys.argv[1:])) | 2001 sys.exit(main(sys.argv[1:])) |
OLD | NEW |