Index: git_cl.py |
diff --git a/git_cl.py b/git_cl.py |
index 69af5455bc09891be134452a2206c0a87b66fde6..8ddaa0db4586513998a9df2d74c3c5fb4c7d4b27 100755 |
--- a/git_cl.py |
+++ b/git_cl.py |
@@ -839,6 +839,46 @@ or verify this branch is set up to track another (via the --track argument to |
author, |
upstream=upstream_branch) |
+ def GetStatus(self): |
+ """Returns None or a string describing the issue's review or CQ status: |
+ * None - no issue |
+ * 'error' - error from review tool (including deleted issues) |
+ * 'unsent' - not sent for review |
+ * 'waiting' - waiting for review |
+ * 'reply' - waiting for owner to reply to review |
+ * 'lgtm' - LGTM'ed |
+ * 'commit' - in the commit queue |
+ * 'closed' - closed |
+ """ |
+ if not self.GetIssue(): |
+ return None |
+ |
+ try: |
+ props = self.GetIssueProperties() |
+ reviewers = self.GetApprovingReviewers() |
iannucci
2014/09/10 19:10:57
since this makes a second HTTP request (I think),
jsbell
2014/09/10 22:00:27
Done.
|
+ except urllib2.HTTPError: |
+ return 'error' |
+ |
+ if props.get('closed'): |
+ # Issue is closed. |
+ return 'closed' |
+ if props.get('commit'): |
+ # Issue is in the commit queue. |
+ return 'commit' |
+ if reviewers: |
+ # Was LGTM'ed. |
+ return 'lgtm' |
+ |
+ messages = props.get('messages') or [] |
+ |
+ if not messages: |
+ # No message was sent. |
+ return 'unsent' |
+ if messages[-1]['sender'] != props.get('owner_email'): |
+ # Non-LGTM reply from non-owner |
+ return 'reply' |
+ return 'waiting' |
+ |
def RunHook(self, committing, may_prompt, verbose, change): |
"""Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" |
@@ -1276,37 +1316,22 @@ def CMDstatus(parser, args): |
def fetch(b): |
"""Fetches information for an issue and returns (branch, issue, color).""" |
c = Changelist(branchref=b) |
+ status = c.GetStatus() |
i = c.GetIssueURL() |
- props = {} |
- r = None |
- if i: |
- try: |
- props = c.GetIssueProperties() |
- r = c.GetApprovingReviewers() if i else None |
- except urllib2.HTTPError: |
- # The issue probably doesn't exist anymore. |
- i += ' (broken)' |
- msgs = props.get('messages') or [] |
- |
- if not i: |
+ if not status or status == 'error': |
+ # The issue probably doesn't exist anymore. |
+ i += ' (broken)' |
color = Fore.WHITE |
- elif props.get('closed'): |
- # Issue is closed. |
- color = Fore.CYAN |
- elif props.get('commit'): |
- # Issue is in the commit queue. |
- color = Fore.MAGENTA |
- elif r: |
- # Was LGTM'ed. |
- color = Fore.GREEN |
- elif not msgs: |
- # No message was sent. |
- color = Fore.RED |
- elif msgs[-1]['sender'] != props.get('owner_email'): |
- color = Fore.YELLOW |
else: |
- color = Fore.BLUE |
+ color = { |
+ 'unsent': Fore.RED, |
+ 'waiting': Fore.BLUE, |
+ 'reply': Fore.YELLOW, |
+ 'lgtm': Fore.GREEN, |
+ 'commit': Fore.MAGENTA, |
+ 'closed': Fore.CYAN, |
+ }[status] |
iannucci
2014/09/10 19:10:57
let's factor this list out too so that git-map-bra
jsbell
2014/09/10 22:00:27
Done.
|
output.put((b, i, color)) |
# Process one branch synchronously to work through authentication, then |