| 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 and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
| 9 | 9 |
| 10 from __future__ import print_function | 10 from __future__ import print_function |
| (...skipping 1530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 | 1541 |
| 1542 def SetCQState(self, new_state): | 1542 def SetCQState(self, new_state): |
| 1543 """Update the CQ state for latest patchset. | 1543 """Update the CQ state for latest patchset. |
| 1544 | 1544 |
| 1545 Issue must have been already uploaded and known. | 1545 Issue must have been already uploaded and known. |
| 1546 """ | 1546 """ |
| 1547 assert new_state in _CQState.ALL_STATES | 1547 assert new_state in _CQState.ALL_STATES |
| 1548 assert self.GetIssue() | 1548 assert self.GetIssue() |
| 1549 return self._codereview_impl.SetCQState(new_state) | 1549 return self._codereview_impl.SetCQState(new_state) |
| 1550 | 1550 |
| 1551 def CannotTriggerTryJobReason(self): |
| 1552 """Returns reason (str) if unable trigger tryjobs on this CL or None.""" |
| 1553 return self._codereview_impl.CannotTriggerTryJobReason() |
| 1554 |
| 1551 # Forward methods to codereview specific implementation. | 1555 # Forward methods to codereview specific implementation. |
| 1552 | 1556 |
| 1553 def CloseIssue(self): | 1557 def CloseIssue(self): |
| 1554 return self._codereview_impl.CloseIssue() | 1558 return self._codereview_impl.CloseIssue() |
| 1555 | 1559 |
| 1556 def GetStatus(self): | 1560 def GetStatus(self): |
| 1557 return self._codereview_impl.GetStatus() | 1561 return self._codereview_impl.GetStatus() |
| 1558 | 1562 |
| 1559 def GetCodereviewServer(self): | 1563 def GetCodereviewServer(self): |
| 1560 return self._codereview_impl.GetCodereviewServer() | 1564 return self._codereview_impl.GetCodereviewServer() |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 """Uploads a change to codereview.""" | 1687 """Uploads a change to codereview.""" |
| 1684 raise NotImplementedError() | 1688 raise NotImplementedError() |
| 1685 | 1689 |
| 1686 def SetCQState(self, new_state): | 1690 def SetCQState(self, new_state): |
| 1687 """Update the CQ state for latest patchset. | 1691 """Update the CQ state for latest patchset. |
| 1688 | 1692 |
| 1689 Issue must have been already uploaded and known. | 1693 Issue must have been already uploaded and known. |
| 1690 """ | 1694 """ |
| 1691 raise NotImplementedError() | 1695 raise NotImplementedError() |
| 1692 | 1696 |
| 1697 def CannotTriggerTryJobReason(self): |
| 1698 """Returns reason (str) if unable trigger tryjobs on this CL or None.""" |
| 1699 raise NotImplementedError() |
| 1700 |
| 1693 | 1701 |
| 1694 class _RietveldChangelistImpl(_ChangelistCodereviewBase): | 1702 class _RietveldChangelistImpl(_ChangelistCodereviewBase): |
| 1695 def __init__(self, changelist, auth_config=None, rietveld_server=None): | 1703 def __init__(self, changelist, auth_config=None, rietveld_server=None): |
| 1696 super(_RietveldChangelistImpl, self).__init__(changelist) | 1704 super(_RietveldChangelistImpl, self).__init__(changelist) |
| 1697 assert settings, 'must be initialized in _ChangelistCodereviewBase' | 1705 assert settings, 'must be initialized in _ChangelistCodereviewBase' |
| 1698 if not rietveld_server: | 1706 if not rietveld_server: |
| 1699 settings.GetDefaultServerUrl() | 1707 settings.GetDefaultServerUrl() |
| 1700 | 1708 |
| 1701 self._rietveld_server = rietveld_server | 1709 self._rietveld_server = rietveld_server |
| 1702 self._auth_config = auth_config | 1710 self._auth_config = auth_config |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1755 | 1763 |
| 1756 def GetIssueProperties(self): | 1764 def GetIssueProperties(self): |
| 1757 if self._props is None: | 1765 if self._props is None: |
| 1758 issue = self.GetIssue() | 1766 issue = self.GetIssue() |
| 1759 if not issue: | 1767 if not issue: |
| 1760 self._props = {} | 1768 self._props = {} |
| 1761 else: | 1769 else: |
| 1762 self._props = self.RpcServer().get_issue_properties(issue, True) | 1770 self._props = self.RpcServer().get_issue_properties(issue, True) |
| 1763 return self._props | 1771 return self._props |
| 1764 | 1772 |
| 1773 def CannotTriggerTryJobReason(self): |
| 1774 props = self.GetIssueProperties() |
| 1775 if not props: |
| 1776 return 'Rietveld doesn\'t know about your issue %s' % self.GetIssue() |
| 1777 if props.get('closed'): |
| 1778 return 'CL %s is closed' % self.GetIssue() |
| 1779 if props.get('private'): |
| 1780 return 'CL %s is private' % self.GetIssue() |
| 1781 return None |
| 1782 |
| 1765 def GetApprovingReviewers(self): | 1783 def GetApprovingReviewers(self): |
| 1766 return get_approving_reviewers(self.GetIssueProperties()) | 1784 return get_approving_reviewers(self.GetIssueProperties()) |
| 1767 | 1785 |
| 1768 def AddComment(self, message): | 1786 def AddComment(self, message): |
| 1769 return self.RpcServer().add_comment(self.GetIssue(), message) | 1787 return self.RpcServer().add_comment(self.GetIssue(), message) |
| 1770 | 1788 |
| 1771 def GetStatus(self): | 1789 def GetStatus(self): |
| 1772 """Apply a rough heuristic to give a simple summary of an issue's review | 1790 """Apply a rough heuristic to give a simple summary of an issue's review |
| 1773 or CQ status, assuming adherence to a common workflow. | 1791 or CQ status, assuming adherence to a common workflow. |
| 1774 | 1792 |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2709 def SetCQState(self, new_state): | 2727 def SetCQState(self, new_state): |
| 2710 """Sets the Commit-Queue label assuming canonical CQ config for Gerrit.""" | 2728 """Sets the Commit-Queue label assuming canonical CQ config for Gerrit.""" |
| 2711 vote_map = { | 2729 vote_map = { |
| 2712 _CQState.NONE: 0, | 2730 _CQState.NONE: 0, |
| 2713 _CQState.DRY_RUN: 1, | 2731 _CQState.DRY_RUN: 1, |
| 2714 _CQState.COMMIT : 2, | 2732 _CQState.COMMIT : 2, |
| 2715 } | 2733 } |
| 2716 gerrit_util.SetReview(self._GetGerritHost(), self.GetIssue(), | 2734 gerrit_util.SetReview(self._GetGerritHost(), self.GetIssue(), |
| 2717 labels={'Commit-Queue': vote_map[new_state]}) | 2735 labels={'Commit-Queue': vote_map[new_state]}) |
| 2718 | 2736 |
| 2737 def CannotTriggerTryJobReason(self): |
| 2738 # TODO(tandrii): implement for Gerrit. |
| 2739 raise NotImplementedError() |
| 2740 |
| 2719 | 2741 |
| 2720 _CODEREVIEW_IMPLEMENTATIONS = { | 2742 _CODEREVIEW_IMPLEMENTATIONS = { |
| 2721 'rietveld': _RietveldChangelistImpl, | 2743 'rietveld': _RietveldChangelistImpl, |
| 2722 'gerrit': _GerritChangelistImpl, | 2744 'gerrit': _GerritChangelistImpl, |
| 2723 } | 2745 } |
| 2724 | 2746 |
| 2725 | 2747 |
| 2726 def _add_codereview_issue_select_options(parser, extra=""): | 2748 def _add_codereview_issue_select_options(parser, extra=""): |
| 2727 _add_codereview_select_options(parser) | 2749 _add_codereview_select_options(parser) |
| 2728 | 2750 |
| (...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4691 parser.error('Need to upload first') | 4713 parser.error('Need to upload first') |
| 4692 | 4714 |
| 4693 if cl.IsGerrit(): | 4715 if cl.IsGerrit(): |
| 4694 parser.error( | 4716 parser.error( |
| 4695 'Not yet supported for Gerrit (http://crbug.com/599931).\n' | 4717 'Not yet supported for Gerrit (http://crbug.com/599931).\n' |
| 4696 'If your project has Commit Queue, dry run is a workaround:\n' | 4718 'If your project has Commit Queue, dry run is a workaround:\n' |
| 4697 ' git cl set-commit --dry-run') | 4719 ' git cl set-commit --dry-run') |
| 4698 # Code below assumes Rietveld issue. | 4720 # Code below assumes Rietveld issue. |
| 4699 # TODO(tandrii): actually implement for Gerrit http://crbug.com/599931. | 4721 # TODO(tandrii): actually implement for Gerrit http://crbug.com/599931. |
| 4700 | 4722 |
| 4701 props = cl.GetIssueProperties() | 4723 error_message = cl.CannotTriggerTryJobReason() |
| 4702 if props.get('closed'): | 4724 if error_message: |
| 4703 parser.error('Cannot send try jobs for a closed CL') | 4725 parser.error('Can\'t trigger try jobs: %s') |
| 4704 | |
| 4705 if props.get('private'): | |
| 4706 parser.error('Cannot use try bots with private issue') | |
| 4707 | 4726 |
| 4708 if not options.name: | 4727 if not options.name: |
| 4709 options.name = cl.GetBranch() | 4728 options.name = cl.GetBranch() |
| 4710 | 4729 |
| 4711 if options.bot and not options.master: | 4730 if options.bot and not options.master: |
| 4712 options.master, err_msg = GetBuilderMaster(options.bot) | 4731 options.master, err_msg = GetBuilderMaster(options.bot) |
| 4713 if err_msg: | 4732 if err_msg: |
| 4714 parser.error('Tryserver master cannot be found because: %s\n' | 4733 parser.error('Tryserver master cannot be found because: %s\n' |
| 4715 'Please manually specify the tryserver master' | 4734 'Please manually specify the tryserver master' |
| 4716 ', e.g. "-m tryserver.chromium.linux".' % err_msg) | 4735 ', e.g. "-m tryserver.chromium.linux".' % err_msg) |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5310 if __name__ == '__main__': | 5329 if __name__ == '__main__': |
| 5311 # These affect sys.stdout so do it outside of main() to simplify mocks in | 5330 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 5312 # unit testing. | 5331 # unit testing. |
| 5313 fix_encoding.fix_encoding() | 5332 fix_encoding.fix_encoding() |
| 5314 setup_color.init() | 5333 setup_color.init() |
| 5315 try: | 5334 try: |
| 5316 sys.exit(main(sys.argv[1:])) | 5335 sys.exit(main(sys.argv[1:])) |
| 5317 except KeyboardInterrupt: | 5336 except KeyboardInterrupt: |
| 5318 sys.stderr.write('interrupted\n') | 5337 sys.stderr.write('interrupted\n') |
| 5319 sys.exit(1) | 5338 sys.exit(1) |
| OLD | NEW |