OLD | NEW |
1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium OS 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 """ | 5 """ |
6 Utilities for requesting information for a gerrit server via https. | 6 Utilities for requesting information for a gerrit server via https. |
7 | 7 |
8 https://gerrit-review.googlesource.com/Documentation/rest-api.html | 8 https://gerrit-review.googlesource.com/Documentation/rest-api.html |
9 """ | 9 """ |
10 | 10 |
(...skipping 122 matching lines...) Loading... |
133 req_host = conn.req_host | 133 req_host = conn.req_host |
134 req_params = conn.req_params | 134 req_params = conn.req_params |
135 conn = GetConnectionClass()(req_host) | 135 conn = GetConnectionClass()(req_host) |
136 conn.req_host = req_host | 136 conn.req_host = req_host |
137 conn.req_params = req_params | 137 conn.req_params = req_params |
138 conn.request(**req_params) | 138 conn.request(**req_params) |
139 LOGGER.warn(msg) | 139 LOGGER.warn(msg) |
140 if ignore_404 and response.status == 404: | 140 if ignore_404 and response.status == 404: |
141 return StringIO() | 141 return StringIO() |
142 if response.status != expect_status: | 142 if response.status != expect_status: |
143 raise GerritError(response.status, response.reason) | 143 reason = '%s: %s' % (response.reason, response.read()) |
| 144 raise GerritError(response.status, reason) |
144 return StringIO(response.read()) | 145 return StringIO(response.read()) |
145 | 146 |
146 | 147 |
147 def ReadHttpJsonResponse(conn, expect_status=200, ignore_404=True): | 148 def ReadHttpJsonResponse(conn, expect_status=200, ignore_404=True): |
148 """Parses an https response as json.""" | 149 """Parses an https response as json.""" |
149 fh = ReadHttpResponse( | 150 fh = ReadHttpResponse( |
150 conn, expect_status=expect_status, ignore_404=ignore_404) | 151 conn, expect_status=expect_status, ignore_404=ignore_404) |
151 # The first line of the response should always be: )]}' | 152 # The first line of the response should always be: )]}' |
152 s = fh.readline() | 153 s = fh.readline() |
153 if s and s.rstrip() != ")]}'": | 154 if s and s.rstrip() != ")]}'": |
(...skipping 275 matching lines...) Loading... |
429 username = review.get('email', jmsg.get('name', '')) | 430 username = review.get('email', jmsg.get('name', '')) |
430 raise GerritError(200, 'Unable to set %s label for user "%s"' | 431 raise GerritError(200, 'Unable to set %s label for user "%s"' |
431 ' on change %s.' % (label, username, change)) | 432 ' on change %s.' % (label, username, change)) |
432 jmsg = GetChangeCurrentRevision(host, change) | 433 jmsg = GetChangeCurrentRevision(host, change) |
433 if not jmsg: | 434 if not jmsg: |
434 raise GerritError( | 435 raise GerritError( |
435 200, 'Could not get review information for change "%s"' % change) | 436 200, 'Could not get review information for change "%s"' % change) |
436 elif jmsg[0]['current_revision'] != revision: | 437 elif jmsg[0]['current_revision'] != revision: |
437 raise GerritError(200, 'While resetting labels on change "%s", ' | 438 raise GerritError(200, 'While resetting labels on change "%s", ' |
438 'a new patchset was uploaded.' % change) | 439 'a new patchset was uploaded.' % change) |
OLD | NEW |