Commit e113dfd7 authored by tandrii's avatar tandrii Committed by Commit bot

git cl try: refactor to add Gerrit support in the future.

R=nodir@chromium.org,sergiyb@chromium.org
BUG=599931

Review-Url: https://codereview.chromium.org/2400713003
parent 568043bd
...@@ -1548,6 +1548,10 @@ class Changelist(object): ...@@ -1548,6 +1548,10 @@ class Changelist(object):
assert self.GetIssue() assert self.GetIssue()
return self._codereview_impl.SetCQState(new_state) return self._codereview_impl.SetCQState(new_state)
def CannotTriggerTryJobReason(self):
"""Returns reason (str) if unable trigger tryjobs on this CL or None."""
return self._codereview_impl.CannotTriggerTryJobReason()
# Forward methods to codereview specific implementation. # Forward methods to codereview specific implementation.
def CloseIssue(self): def CloseIssue(self):
...@@ -1690,6 +1694,10 @@ class _ChangelistCodereviewBase(object): ...@@ -1690,6 +1694,10 @@ class _ChangelistCodereviewBase(object):
""" """
raise NotImplementedError() raise NotImplementedError()
def CannotTriggerTryJobReason(self):
"""Returns reason (str) if unable trigger tryjobs on this CL or None."""
raise NotImplementedError()
class _RietveldChangelistImpl(_ChangelistCodereviewBase): class _RietveldChangelistImpl(_ChangelistCodereviewBase):
def __init__(self, changelist, auth_config=None, rietveld_server=None): def __init__(self, changelist, auth_config=None, rietveld_server=None):
...@@ -1762,6 +1770,16 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase): ...@@ -1762,6 +1770,16 @@ class _RietveldChangelistImpl(_ChangelistCodereviewBase):
self._props = self.RpcServer().get_issue_properties(issue, True) self._props = self.RpcServer().get_issue_properties(issue, True)
return self._props return self._props
def CannotTriggerTryJobReason(self):
props = self.GetIssueProperties()
if not props:
return 'Rietveld doesn\'t know about your issue %s' % self.GetIssue()
if props.get('closed'):
return 'CL %s is closed' % self.GetIssue()
if props.get('private'):
return 'CL %s is private' % self.GetIssue()
return None
def GetApprovingReviewers(self): def GetApprovingReviewers(self):
return get_approving_reviewers(self.GetIssueProperties()) return get_approving_reviewers(self.GetIssueProperties())
...@@ -2716,6 +2734,10 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase): ...@@ -2716,6 +2734,10 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
gerrit_util.SetReview(self._GetGerritHost(), self.GetIssue(), gerrit_util.SetReview(self._GetGerritHost(), self.GetIssue(),
labels={'Commit-Queue': vote_map[new_state]}) labels={'Commit-Queue': vote_map[new_state]})
def CannotTriggerTryJobReason(self):
# TODO(tandrii): implement for Gerrit.
raise NotImplementedError()
_CODEREVIEW_IMPLEMENTATIONS = { _CODEREVIEW_IMPLEMENTATIONS = {
'rietveld': _RietveldChangelistImpl, 'rietveld': _RietveldChangelistImpl,
...@@ -4698,12 +4720,9 @@ def CMDtry(parser, args): ...@@ -4698,12 +4720,9 @@ def CMDtry(parser, args):
# Code below assumes Rietveld issue. # Code below assumes Rietveld issue.
# TODO(tandrii): actually implement for Gerrit http://crbug.com/599931. # TODO(tandrii): actually implement for Gerrit http://crbug.com/599931.
props = cl.GetIssueProperties() error_message = cl.CannotTriggerTryJobReason()
if props.get('closed'): if error_message:
parser.error('Cannot send try jobs for a closed CL') parser.error('Can\'t trigger try jobs: %s')
if props.get('private'):
parser.error('Cannot use try bots with private issue')
if not options.name: if not options.name:
options.name = cl.GetBranch() options.name = cl.GetBranch()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment