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

Side by Side Diff: presubmit_canned_checks.py

Issue 3107038: Adding json based tree open check. (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 10 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 | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 ### Description checks 7 ### Description checks
8 8
9 def CheckChangeHasTestField(input_api, output_api): 9 def CheckChangeHasTestField(input_api, output_api):
10 """Requires that the changelist have a TEST= field.""" 10 """Requires that the changelist have a TEST= field."""
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 ### Other checks 343 ### Other checks
344 344
345 def CheckDoNotSubmit(input_api, output_api): 345 def CheckDoNotSubmit(input_api, output_api):
346 return ( 346 return (
347 CheckDoNotSubmitInDescription(input_api, output_api) + 347 CheckDoNotSubmitInDescription(input_api, output_api) +
348 CheckDoNotSubmitInFiles(input_api, output_api) 348 CheckDoNotSubmitInFiles(input_api, output_api)
349 ) 349 )
350 350
351 351
352 def CheckTreeIsOpen(input_api, output_api, url, closed): 352 def CheckTreeIsOpen(input_api, output_api,
353 """Checks that an url's content doesn't match a regexp that would mean that 353 url=None, closed=None, json_url=None):
354 the tree is closed.""" 354 """Check whether to allow commit without prompt.
355
356 Supports two styles:
357 1. Checks that an url's content doesn't match a regexp that would mean that
358 the tree is closed. (old)
359 2. Check the json_url to decide whether to allow commit without prompt.
360 Args:
361 input_api: input related apis.
362 output_api: output related apis.
363 url: url to use for regex based tree status.
364 closed: regex to match for closed status.
365 json_url: url to download json style status.
366 """
355 if not input_api.is_committing: 367 if not input_api.is_committing:
356 return [] 368 return []
357 try: 369 try:
358 connection = input_api.urllib2.urlopen(url) 370 if json_url:
359 status = connection.read() 371 connection = input_api.urllib2.urlopen(json_url)
360 connection.close() 372 status = input_api.json.loads(connection.read())
361 if input_api.re.match(closed, status, input_api.re.IGNORECASE): 373 connection.close()
362 long_text = status + '\n' + url 374 if not status['can_commit_freely']:
363 return [output_api.PresubmitError('The tree is closed dude!', 375 short_text = 'Tree state is: ' + status['general_state']
364 long_text=long_text)] 376 long_text = status['message'] + '\n' + json_url
377 return [output_api.PresubmitError(short_text, long_text=long_text)]
378 else:
379 # TODO(bradnelson): drop this once all users are gone.
380 connection = input_api.urllib2.urlopen(url)
381 status = connection.read()
382 connection.close()
383 if input_api.re.match(closed, status):
384 long_text = status + '\n' + url
385 return [output_api.PresubmitError('The tree is closed.',
386 long_text=long_text)]
365 except IOError: 387 except IOError:
366 pass 388 pass
367 return [] 389 return []
368 390
369 391
370 def RunPythonUnitTests(input_api, output_api, unit_tests): 392 def RunPythonUnitTests(input_api, output_api, unit_tests):
371 """Run the unit tests out of process, capture the output and use the result 393 """Run the unit tests out of process, capture the output and use the result
372 code to determine success. 394 code to determine success.
373 """ 395 """
374 # We don't want to hinder users from uploading incomplete patches. 396 # We don't want to hinder users from uploading incomplete patches.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 pending_builds_len = len(builder.get('pending_builds', [])) 518 pending_builds_len = len(builder.get('pending_builds', []))
497 if pending_builds_len > max_pendings: 519 if pending_builds_len > max_pendings:
498 out.append('%s has %d build(s) pending' % 520 out.append('%s has %d build(s) pending' %
499 (builder_name, pending_builds_len)) 521 (builder_name, pending_builds_len))
500 if out: 522 if out:
501 return [output_api.PresubmitPromptWarning( 523 return [output_api.PresubmitPromptWarning(
502 'Build(s) pending. It is suggested to wait that no more than %d ' 524 'Build(s) pending. It is suggested to wait that no more than %d '
503 'builds are pending.' % max_pendings, 525 'builds are pending.' % max_pendings,
504 long_text='\n'.join(out))] 526 long_text='\n'.join(out))]
505 return [] 527 return []
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698