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 GetActualReviewers(self, issue): | |
Dirk Pranke
2013/04/09 00:15:51
should this be GetRealReviewers to match?
M-A Ruel
2013/04/11 01:11:28
GetApprovingReviewers()
| |
651 return get_real_reviewers( | |
652 self.RpcServer().get_issue_properties(int(issue), False)) | |
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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 def get_reviewers(self): | 872 def get_reviewers(self): |
869 """Retrieves the list of reviewers.""" | 873 """Retrieves the list of reviewers.""" |
870 regexp = re.compile(self.R_LINE, re.MULTILINE) | 874 regexp = re.compile(self.R_LINE, re.MULTILINE) |
871 reviewers = sum( | 875 reviewers = sum( |
872 (i.group(2).split(',') for i in regexp.finditer(self.description)), | 876 (i.group(2).split(',') for i in regexp.finditer(self.description)), |
873 []) | 877 []) |
874 reviewers = (i.strip() for i in reviewers) | 878 reviewers = (i.strip() for i in reviewers) |
875 return sorted(i for i in reviewers if i) | 879 return sorted(i for i in reviewers if i) |
876 | 880 |
877 | 881 |
882 def get_real_reviewers(props): | |
883 """Retrieves the reviewers that approved a cL from the issue properties with | |
Dirk Pranke
2013/04/09 00:15:51
nit: "CL", not "cL".
I wonder if this should be "
M-A Ruel
2013/04/11 01:11:28
Done.
| |
884 messages. | |
885 | |
886 Note that the list may contain reviewers that are not committer, thus are not | |
887 considered by the CQ. | |
888 """ | |
889 return sorted( | |
890 set( | |
891 message['sender'] | |
892 for message in props['messages'] | |
893 if message['approval'] and message['sender'] in props['reviewers'] | |
894 ) | |
895 ) | |
896 | |
897 | |
878 def FindCodereviewSettingsFile(filename='codereview.settings'): | 898 def FindCodereviewSettingsFile(filename='codereview.settings'): |
879 """Finds the given file starting in the cwd and going up. | 899 """Finds the given file starting in the cwd and going up. |
880 | 900 |
881 Only looks up to the top of the repository unless an | 901 Only looks up to the top of the repository unless an |
882 'inherit-review-settings-ok' file exists in the root of the repository. | 902 'inherit-review-settings-ok' file exists in the root of the repository. |
883 """ | 903 """ |
884 inherit_ok_file = 'inherit-review-settings-ok' | 904 inherit_ok_file = 'inherit-review-settings-ok' |
885 cwd = os.getcwd() | 905 cwd = os.getcwd() |
886 root = os.path.abspath(RunGit(['rev-parse', '--show-cdup']).strip()) | 906 root = os.path.abspath(RunGit(['rev-parse', '--show-cdup']).strip()) |
887 if os.path.isfile(os.path.join(root, inherit_ok_file)): | 907 if os.path.isfile(os.path.join(root, inherit_ok_file)): |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1458 change_desc = ChangeDescription(cl.GetDescription()) | 1478 change_desc = ChangeDescription(cl.GetDescription()) |
1459 | 1479 |
1460 if not change_desc.description: | 1480 if not change_desc.description: |
1461 if not cl.GetIssue() and options.bypass_hooks: | 1481 if not cl.GetIssue() and options.bypass_hooks: |
1462 change_desc = ChangeDescription(CreateDescriptionFromLog([base_branch])) | 1482 change_desc = ChangeDescription(CreateDescriptionFromLog([base_branch])) |
1463 else: | 1483 else: |
1464 print 'No description set.' | 1484 print 'No description set.' |
1465 print 'Visit %s/edit to set it.' % (cl.GetIssueURL()) | 1485 print 'Visit %s/edit to set it.' % (cl.GetIssueURL()) |
1466 return 1 | 1486 return 1 |
1467 | 1487 |
1488 if cl.GetIssue(): | |
1489 actual_reviewers = ','.join(cl.GetActualReviewers(cl.GetIssue())) | |
1490 change_desc.update_reviewers(actual_reviewers) | |
1491 | |
1468 # Keep a separate copy for the commit message. | 1492 # Keep a separate copy for the commit message. |
1469 commit_desc = ChangeDescription(change_desc.description) | 1493 commit_desc = ChangeDescription(change_desc.description) |
1470 if cl.GetIssue(): | 1494 if cl.GetIssue(): |
1471 commit_desc.append_line('Review URL: %s' % cl.GetIssueURL()) | 1495 commit_desc.append_line('Review URL: %s' % cl.GetIssueURL()) |
1472 if options.contributor: | 1496 if options.contributor: |
1473 commit_desc.append_line('Patch from %s.' % options.contributor) | 1497 commit_desc.append_line('Patch from %s.' % options.contributor) |
1474 | 1498 |
1475 print 'Description:', repr(commit_desc.description) | 1499 print 'Description:', repr(commit_desc.description) |
1476 | 1500 |
1477 branches = [base_branch, cl.GetBranchRef()] | 1501 branches = [base_branch, cl.GetBranchRef()] |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1948 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1972 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1949 | 1973 |
1950 # Not a known command. Default to help. | 1974 # Not a known command. Default to help. |
1951 GenUsage(parser, 'help') | 1975 GenUsage(parser, 'help') |
1952 return CMDhelp(parser, argv) | 1976 return CMDhelp(parser, argv) |
1953 | 1977 |
1954 | 1978 |
1955 if __name__ == '__main__': | 1979 if __name__ == '__main__': |
1956 fix_encoding.fix_encoding() | 1980 fix_encoding.fix_encoding() |
1957 sys.exit(main(sys.argv[1:])) | 1981 sys.exit(main(sys.argv[1:])) |
OLD | NEW |