OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 """Utility functions to communicate with Rietveld.""" | 5 """Utility functions to communicate with Rietveld.""" |
6 | 6 |
7 import collections | 7 import collections |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import urllib2 | 10 import urllib2 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 def _get_json(url, web): | 58 def _get_json(url, web): |
59 """Fetches JSON from a URL, and logs errors if the request was unsuccessful. | 59 """Fetches JSON from a URL, and logs errors if the request was unsuccessful. |
60 | 60 |
61 Raises: | 61 Raises: |
62 urllib2.URLError: Something went wrong with the request. | 62 urllib2.URLError: Something went wrong with the request. |
63 ValueError: The response wasn't valid JSON. | 63 ValueError: The response wasn't valid JSON. |
64 """ | 64 """ |
65 try: | 65 try: |
66 contents = web.get_binary(url) | 66 contents = web.get_binary(url) |
67 except urllib2.URLError: | 67 except urllib2.URLError: |
68 _log.error('Request failed to URL: %s' % url) | 68 _log.error('Request failed to URL: %s', url) |
69 raise | 69 raise |
70 try: | 70 try: |
71 return json.loads(contents) | 71 return json.loads(contents) |
72 except ValueError: | 72 except ValueError: |
73 _log.error('Invalid JSON: %s' % contents) | 73 _log.error('Invalid JSON: %s', contents) |
74 raise | 74 raise |
75 | 75 |
76 | 76 |
77 def _issue_url(issue_number): | 77 def _issue_url(issue_number): |
78 return '%s/%s' % (BASE_CODEREVIEW_URL, issue_number) | 78 return '%s/%s' % (BASE_CODEREVIEW_URL, issue_number) |
79 | 79 |
80 | 80 |
81 def _patchset_url(issue_number, patchset_number): | 81 def _patchset_url(issue_number, patchset_number): |
82 return '%s/%s' % (_issue_url(issue_number), patchset_number) | 82 return '%s/%s' % (_issue_url(issue_number), patchset_number) |
83 | 83 |
(...skipping 15 matching lines...) Expand all Loading... |
99 return [j for j in jobs if builder_to_highest_number[j.builder_name] == j.bu
ild_number] | 99 return [j for j in jobs if builder_to_highest_number[j.builder_name] == j.bu
ild_number] |
100 | 100 |
101 | 101 |
102 def get_latest_try_job_results(issue_number, web): | 102 def get_latest_try_job_results(issue_number, web): |
103 url = _latest_patchset_url(issue_number, web) | 103 url = _latest_patchset_url(issue_number, web) |
104 patchset_data = _get_json(url, web) | 104 patchset_data = _get_json(url, web) |
105 results = {} | 105 results = {} |
106 for job in patchset_data['try_job_results']: | 106 for job in patchset_data['try_job_results']: |
107 results[job['builder']] = job['result'] | 107 results[job['builder']] = job['result'] |
108 return results | 108 return results |
OLD | NEW |