Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: git_cl.py

Issue 555973005: Factor out Changelist GetStatus() for eventual use by other tools (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Tweak order in docs; handle 'error' case Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 return presubmit_support.GitChange( 832 return presubmit_support.GitChange(
833 name, 833 name,
834 description, 834 description,
835 absroot, 835 absroot,
836 files, 836 files,
837 issue, 837 issue,
838 patchset, 838 patchset,
839 author, 839 author,
840 upstream=upstream_branch) 840 upstream=upstream_branch)
841 841
842 def GetStatus(self):
843 """Returns None or a string describing the issue's review or CQ status:
844 * None - no issue
845 * 'error' - error from review tool (including deleted issues)
846 * 'unsent' - not sent for review
847 * 'waiting' - waiting for review
848 * 'reply' - waiting for owner to reply to review
849 * 'lgtm' - LGTM'ed
850 * 'commit' - in the commit queue
851 * 'closed' - closed
852 """
853 if not self.GetIssue():
854 return None
855
856 try:
857 props = self.GetIssueProperties()
858 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.
859 except urllib2.HTTPError:
860 return 'error'
861
862 if props.get('closed'):
863 # Issue is closed.
864 return 'closed'
865 if props.get('commit'):
866 # Issue is in the commit queue.
867 return 'commit'
868 if reviewers:
869 # Was LGTM'ed.
870 return 'lgtm'
871
872 messages = props.get('messages') or []
873
874 if not messages:
875 # No message was sent.
876 return 'unsent'
877 if messages[-1]['sender'] != props.get('owner_email'):
878 # Non-LGTM reply from non-owner
879 return 'reply'
880 return 'waiting'
881
842 def RunHook(self, committing, may_prompt, verbose, change): 882 def RunHook(self, committing, may_prompt, verbose, change):
843 """Calls sys.exit() if the hook fails; returns a HookResults otherwise.""" 883 """Calls sys.exit() if the hook fails; returns a HookResults otherwise."""
844 884
845 try: 885 try:
846 return presubmit_support.DoPresubmitChecks(change, committing, 886 return presubmit_support.DoPresubmitChecks(change, committing,
847 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin, 887 verbose=verbose, output_stream=sys.stdout, input_stream=sys.stdin,
848 default_presubmit=None, may_prompt=may_prompt, 888 default_presubmit=None, may_prompt=may_prompt,
849 rietveld_obj=self.RpcServer()) 889 rietveld_obj=self.RpcServer())
850 except presubmit_support.PresubmitFailure, e: 890 except presubmit_support.PresubmitFailure, e:
851 DieWithError( 891 DieWithError(
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 # Adhoc thread pool to request data concurrently. 1309 # Adhoc thread pool to request data concurrently.
1270 output = Queue.Queue() 1310 output = Queue.Queue()
1271 1311
1272 # Silence upload.py otherwise it becomes unweldly. 1312 # Silence upload.py otherwise it becomes unweldly.
1273 upload.verbosity = 0 1313 upload.verbosity = 0
1274 1314
1275 if not options.fast: 1315 if not options.fast:
1276 def fetch(b): 1316 def fetch(b):
1277 """Fetches information for an issue and returns (branch, issue, color).""" 1317 """Fetches information for an issue and returns (branch, issue, color)."""
1278 c = Changelist(branchref=b) 1318 c = Changelist(branchref=b)
1319 status = c.GetStatus()
1279 i = c.GetIssueURL() 1320 i = c.GetIssueURL()
1280 props = {}
1281 r = None
1282 if i:
1283 try:
1284 props = c.GetIssueProperties()
1285 r = c.GetApprovingReviewers() if i else None
1286 except urllib2.HTTPError:
1287 # The issue probably doesn't exist anymore.
1288 i += ' (broken)'
1289 1321
1290 msgs = props.get('messages') or [] 1322 if not status or status == 'error':
1291 1323 # The issue probably doesn't exist anymore.
1292 if not i: 1324 i += ' (broken)'
1293 color = Fore.WHITE 1325 color = Fore.WHITE
1294 elif props.get('closed'):
1295 # Issue is closed.
1296 color = Fore.CYAN
1297 elif props.get('commit'):
1298 # Issue is in the commit queue.
1299 color = Fore.MAGENTA
1300 elif r:
1301 # Was LGTM'ed.
1302 color = Fore.GREEN
1303 elif not msgs:
1304 # No message was sent.
1305 color = Fore.RED
1306 elif msgs[-1]['sender'] != props.get('owner_email'):
1307 color = Fore.YELLOW
1308 else: 1326 else:
1309 color = Fore.BLUE 1327 color = {
1328 'unsent': Fore.RED,
1329 'waiting': Fore.BLUE,
1330 'reply': Fore.YELLOW,
1331 'lgtm': Fore.GREEN,
1332 'commit': Fore.MAGENTA,
1333 'closed': Fore.CYAN,
1334 }[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.
1310 output.put((b, i, color)) 1335 output.put((b, i, color))
1311 1336
1312 # Process one branch synchronously to work through authentication, then 1337 # Process one branch synchronously to work through authentication, then
1313 # spawn threads to process all the other branches in parallel. 1338 # spawn threads to process all the other branches in parallel.
1314 if branches: 1339 if branches:
1315 fetch(branches[0]) 1340 fetch(branches[0])
1316 threads = [ 1341 threads = [
1317 threading.Thread(target=fetch, args=(b,)) for b in branches[1:]] 1342 threading.Thread(target=fetch, args=(b,)) for b in branches[1:]]
1318 for t in threads: 1343 for t in threads:
1319 t.daemon = True 1344 t.daemon = True
(...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2837 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2862 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2838 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2863 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2839 2864
2840 2865
2841 if __name__ == '__main__': 2866 if __name__ == '__main__':
2842 # These affect sys.stdout so do it outside of main() to simplify mocks in 2867 # These affect sys.stdout so do it outside of main() to simplify mocks in
2843 # unit testing. 2868 # unit testing.
2844 fix_encoding.fix_encoding() 2869 fix_encoding.fix_encoding()
2845 colorama.init() 2870 colorama.init()
2846 sys.exit(main(sys.argv[1:])) 2871 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698