| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 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 | 7 |
| 8 ### Description checks | 8 ### Description checks |
| 9 | 9 |
| 10 def CheckChangeHasTestField(input_api, output_api): | 10 def CheckChangeHasTestField(input_api, output_api): |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 elif result: | 671 elif result: |
| 672 return [error_type('Fix pylint errors first.')] | 672 return [error_type('Fix pylint errors first.')] |
| 673 return [] | 673 return [] |
| 674 finally: | 674 finally: |
| 675 warnings.filterwarnings('default', category=DeprecationWarning) | 675 warnings.filterwarnings('default', category=DeprecationWarning) |
| 676 | 676 |
| 677 | 677 |
| 678 # TODO(dpranke): Get the host_url from the input_api instead | 678 # TODO(dpranke): Get the host_url from the input_api instead |
| 679 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, | 679 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, |
| 680 owner): | 680 owner): |
| 681 if not input_api.is_committing: | 681 # Temporarily 'fix' the check while the Rietveld API is being upgraded to |
| 682 return [] | 682 # something sensible. |
| 683 if not input_api.change.issue or not input_api.change.patchset: | |
| 684 return [] | |
| 685 url = '%s/%d/get_build_results/%d' % ( | |
| 686 host_url, input_api.change.issue, input_api.change.patchset) | |
| 687 try: | |
| 688 connection = input_api.urllib2.urlopen(url) | |
| 689 # platform|status|url | |
| 690 values = [item.split('|', 2) for item in connection.read().splitlines()] | |
| 691 connection.close() | |
| 692 except input_api.urllib2.HTTPError, e: | |
| 693 if e.code == 404: | |
| 694 # Fallback to no try job. | |
| 695 return [output_api.PresubmitPromptWarning( | |
| 696 'You should try the patch first.')] | |
| 697 else: | |
| 698 # Another HTTP error happened, warn the user. | |
| 699 return [output_api.PresubmitPromptWarning( | |
| 700 'Got %s while looking for try job status.' % str(e))] | |
| 701 | |
| 702 if not values: | |
| 703 # It returned an empty list. Probably a private review. | |
| 704 return [] | |
| 705 # Reformat as an dict of platform: [status, url] | |
| 706 values = dict([[v[0], [v[1], v[2]]] for v in values if len(v) == 3]) | |
| 707 if not values: | |
| 708 # It returned useless data. | |
| 709 return [output_api.PresubmitNotifyResult('Failed to parse try job results')] | |
| 710 | |
| 711 for platform in platforms: | |
| 712 values.setdefault(platform, ['not started', '']) | |
| 713 message = None | |
| 714 non_success = [k.upper() for k, v in values.iteritems() if v[0] != 'success'] | |
| 715 if 'failure' in [v[0] for v in values.itervalues()]: | |
| 716 message = 'Try job failures on %s!\n' % ', '.join(non_success) | |
| 717 elif non_success: | |
| 718 message = ('Unfinished (or not even started) try jobs on ' | |
| 719 '%s.\n') % ', '.join(non_success) | |
| 720 if message: | |
| 721 message += ( | |
| 722 'Is try server wrong or broken? Please notify %s. ' | |
| 723 'Thanks.\n' % owner) | |
| 724 return [output_api.PresubmitPromptWarning(message=message)] | |
| 725 return [] | 683 return [] |
| 726 | 684 |
| 727 | 685 |
| 728 def CheckBuildbotPendingBuilds(input_api, output_api, url, max_pendings, | 686 def CheckBuildbotPendingBuilds(input_api, output_api, url, max_pendings, |
| 729 ignored): | 687 ignored): |
| 730 if not input_api.json: | 688 if not input_api.json: |
| 731 return [output_api.PresubmitPromptWarning( | 689 return [output_api.PresubmitPromptWarning( |
| 732 'Please install simplejson or upgrade to python 2.6+')] | 690 'Please install simplejson or upgrade to python 2.6+')] |
| 733 try: | 691 try: |
| 734 connection = input_api.urllib2.urlopen(url) | 692 connection = input_api.urllib2.urlopen(url) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 913 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
| 956 input_api, output_api)) | 914 input_api, output_api)) |
| 957 snapshot("checking license") | 915 snapshot("checking license") |
| 958 results.extend(input_api.canned_checks.CheckLicense( | 916 results.extend(input_api.canned_checks.CheckLicense( |
| 959 input_api, output_api, license_header, source_file_filter=sources)) | 917 input_api, output_api, license_header, source_file_filter=sources)) |
| 960 snapshot("checking was uploaded") | 918 snapshot("checking was uploaded") |
| 961 results.extend(input_api.canned_checks.CheckChangeWasUploaded( | 919 results.extend(input_api.canned_checks.CheckChangeWasUploaded( |
| 962 input_api, output_api)) | 920 input_api, output_api)) |
| 963 snapshot("done") | 921 snapshot("done") |
| 964 return results | 922 return results |
| OLD | NEW |