| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """"Serves as a client for selected APIs in Buildbucket.""" | 5 """"Serves as a client for selected APIs in Buildbucket.""" |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 SCHEDULED = 'SCHEDULED' | 75 SCHEDULED = 'SCHEDULED' |
| 76 STARTED = 'STARTED' | 76 STARTED = 'STARTED' |
| 77 COMPLETED = 'COMPLETED' | 77 COMPLETED = 'COMPLETED' |
| 78 | 78 |
| 79 def __init__(self, raw_json_data): | 79 def __init__(self, raw_json_data): |
| 80 self.id = raw_json_data.get('id') | 80 self.id = raw_json_data.get('id') |
| 81 self.url = raw_json_data.get('url') | 81 self.url = raw_json_data.get('url') |
| 82 self.status = raw_json_data.get('status') | 82 self.status = raw_json_data.get('status') |
| 83 result_details_json = json.loads( | 83 result_details_json = json.loads( |
| 84 raw_json_data.get('result_details_json', '{}')) or {} | 84 raw_json_data.get('result_details_json', '{}')) or {} |
| 85 self.result = result_details_json.get('properties', {}).get('result', []) | 85 self.report = (result_details_json.get('properties', {}).get('result') or |
| 86 result_details_json.get('properties', {}).get('report', {})) |
| 86 | 87 |
| 87 | 88 |
| 88 class BuildbucketError(object): | 89 class BuildbucketError(object): |
| 89 """Represents an error returned by Buildbucket.""" | 90 """Represents an error returned by Buildbucket.""" |
| 90 | 91 |
| 91 # Error reasons. | 92 # Error reasons. |
| 92 BUILD_NOT_FOUND = 'BUILD_NOT_FOUND' | 93 BUILD_NOT_FOUND = 'BUILD_NOT_FOUND' |
| 93 INVALID_INPUT = 'INVALID_INPUT' | 94 INVALID_INPUT = 'INVALID_INPUT' |
| 94 | 95 |
| 95 def __init__(self, raw_json_data): | 96 def __init__(self, raw_json_data): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 139 } |
| 139 | 140 |
| 140 for try_job in try_jobs: | 141 for try_job in try_jobs: |
| 141 status_code, content = HttpClient().Put( | 142 status_code, content = HttpClient().Put( |
| 142 _BUILDBUCKET_PUT_GET_ENDPOINT, | 143 _BUILDBUCKET_PUT_GET_ENDPOINT, |
| 143 json.dumps(try_job.ToBuildbucketRequest()), headers=headers) | 144 json.dumps(try_job.ToBuildbucketRequest()), headers=headers) |
| 144 if status_code == 200: # pragma: no cover | 145 if status_code == 200: # pragma: no cover |
| 145 json_results.append(json.loads(content)) | 146 json_results.append(json.loads(content)) |
| 146 else: | 147 else: |
| 147 error_content = { | 148 error_content = { |
| 148 'error': { | 149 'error': { |
| 149 'reason': status_code, | 150 'reason': status_code, |
| 150 'message': content | 151 'message': content |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 json_results.append(error_content) | 154 json_results.append(error_content) |
| 154 | 155 |
| 155 return _ConvertFuturesToResults(json_results) | 156 return _ConvertFuturesToResults(json_results) |
| 156 | 157 |
| 157 | 158 |
| 158 def GetTryJobs(build_ids): | 159 def GetTryJobs(build_ids): |
| 159 """Returns the try-job builds for the given build ids. | 160 """Returns the try-job builds for the given build ids. |
| 160 | 161 |
| 161 Args: | 162 Args: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 'Content-Type': 'application/json; charset=UTF-8' | 173 'Content-Type': 'application/json; charset=UTF-8' |
| 173 } | 174 } |
| 174 | 175 |
| 175 for build_id in build_ids: | 176 for build_id in build_ids: |
| 176 status_code, content = HttpClient().Get( | 177 status_code, content = HttpClient().Get( |
| 177 _BUILDBUCKET_PUT_GET_ENDPOINT + '/' + build_id, headers=headers) | 178 _BUILDBUCKET_PUT_GET_ENDPOINT + '/' + build_id, headers=headers) |
| 178 if status_code == 200: # pragma: no cover | 179 if status_code == 200: # pragma: no cover |
| 179 json_results.append(json.loads(content)) | 180 json_results.append(json.loads(content)) |
| 180 else: | 181 else: |
| 181 error_content = { | 182 error_content = { |
| 182 'error': { | 183 'error': { |
| 183 'reason': status_code, | 184 'reason': status_code, |
| 184 'message': content | 185 'message': content |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 json_results.append(error_content) | 188 json_results.append(error_content) |
| 188 | 189 |
| 189 return _ConvertFuturesToResults(json_results) | 190 return _ConvertFuturesToResults(json_results) |
| OLD | NEW |