Chromium Code Reviews

Unified Diff: git_cl.py

Issue 1834133002: git cl status for Gerrit. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@H100
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index a6435824a82f0bcc9f8428981002512f5d6c3b43..760a46b9e6d2a835a6c9beb1be9de4ea60069a07 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -1582,17 +1582,63 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
return ThisIsNotRietveldIssue()
def GetStatus(self):
- # TODO(tandrii)
- raise NotImplementedError()
+ """Apply a rough heuristic to give a simple summary of an issue's review
+ or CQ status, assuming adherence to a common workflow.
+
+ Returns None if no issue for this branch, or one of the following keywords:
+ * 'error' - error from review tool (including deleted issues)
+ * 'unsent' - no reviewers added
+ * 'waiting' - waiting for review
+ * 'reply' - waiting for owner to reply to review
+ * 'lgtm' - Code-Review +2 from at least one approved reviewer
+ * 'commit' - in the commit queue
+ * 'closed' - abandoned
+ """
+ if not self.GetIssue():
+ return None
+
+ try:
+ data = self._GetChangeDetail(['DETAILED_LABELS', 'CURRENT_REVISION'])
+ except httplib.HTTPException:
+ return 'error'
+
+ if data['status'] == 'ABANDONED':
+ return 'abandoned'
ukai 2016/03/28 02:19:51 'closed' ? (or add 'abondoned' in docstring above?
tandrii(chromium) 2016/03/28 18:57:21 Done.
+
+ cq_label = data['labels'].get('Commit-Queue', {})
+ if cq_label:
+ # Vote value is a stringified integer, which we expect from 0 to 2.
+ vote_value = cq_label.get('value', '0')
+ vote_text = cq_label.get('values', {}).get(vote_value, '')
+ if vote_text.lower() == 'Commit'.lower():
ukai 2016/03/28 02:19:51 if vote.text.lower() == 'commit': ?
tandrii(chromium) 2016/03/28 18:57:21 Done.
+ return 'commit'
+
+ lgtm_label = data['labels'].get('Code-Review', {})
+ if lgtm_label:
+ if 'rejected' in lgtm_label:
+ return 'not lgtm'
ukai 2016/03/28 02:19:51 'waiting' ? (or add 'not lgtm' in docstring above?
tandrii(chromium) 2016/03/28 18:57:21 Done.
+ if 'approved' in lgtm_label:
+ return 'lgtm'
+
+ if not data.get('reviewers', {}).get('REVIEWER', []):
+ return 'unsent'
+
+ messages = data.get('messages', [])
+ if messages:
+ owner = data['owner'].get('_account_id')
+ last_message_author = messages[-1].get('author', {}).get('_account_id')
+ if owner != last_message_author:
+ # Some reply from non-owner.
+ return 'reply'
+
+ return 'waiting'
def GetMostRecentPatchset(self):
- data = gerrit_util.GetChangeDetail(self._GetGerritHost(), self.GetIssue(),
- ['CURRENT_REVISION'])
+ data = self._GetChangeDetail(['CURRENT_REVISION'])
return data['revisions'][data['current_revision']]['_number']
def FetchDescription(self):
- data = gerrit_util.GetChangeDetail(self._GetGerritHost(), self.GetIssue(),
- ['COMMIT_FOOTERS', 'CURRENT_REVISION'])
+ data = self._GetChangeDetail(['COMMIT_FOOTERS', 'CURRENT_REVISION'])
return data['revisions'][data['current_revision']]['commit_with_footers']
def UpdateDescriptionRemote(self, description):
@@ -1603,6 +1649,11 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
gerrit_util.AbandonChange(self._GetGerritHost(), self.GetIssue(), msg='')
+ def _GetChangeDetail(self, options):
+ return gerrit_util.GetChangeDetail(self._GetGerritHost(), self.GetIssue(),
+ options)
+
+
class ChangeDescription(object):
"""Contains a parsed form of the change description."""
R_LINE = r'^[ \t]*(TBR|R)[ \t]*=[ \t]*(.*?)[ \t]*$'
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine