Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Yet another wrapper around Gerrit REST API.""" | 5 """Yet another wrapper around Gerrit REST API.""" |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import cookielib | 8 import cookielib |
| 9 import functools | 9 import functools |
| 10 import json | 10 import json |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 code, body = self._request(method='GET', request_path=request_path, | 422 code, body = self._request(method='GET', request_path=request_path, |
| 423 params=params) | 423 params=params) |
| 424 if code == 404: | 424 if code == 404: |
| 425 return None | 425 return None |
| 426 if code != 200: | 426 if code != 200: |
| 427 raise UnexpectedResponseException(code, body) | 427 raise UnexpectedResponseException(code, body) |
| 428 return body | 428 return body |
| 429 | 429 |
| 430 @_not_read_only | 430 @_not_read_only |
| 431 def set_review(self, change_id, revision_id, message=None, labels=None, | 431 def set_review(self, change_id, revision_id, message=None, labels=None, |
| 432 notify=NOTIFY_NONE, max_message=300): | 432 notify=NOTIFY_NONE, max_message=300, tag=None): |
| 433 """Uses the Set Review endpoint of the Gerrit API to add messages and/or set | 433 """Uses the Set Review endpoint of the Gerrit API to add messages and/or set |
| 434 labels for a patchset. | 434 labels for a patchset. |
| 435 Documentation: | 435 Documentation: |
| 436 https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#s et-review | 436 https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#s et-review |
| 437 | 437 |
| 438 Args: | 438 Args: |
| 439 change_id: (str) The id of the change list. | 439 change_id: (str) The id of the change list. |
| 440 revision_id: (str) The id of the affected revision. | 440 revision_id: (str) The id of the affected revision. |
| 441 message: (str) The message to add to the patchset. | 441 message: (str) The message to add to the patchset. |
| 442 labels: (dict) The dictionary which maps label names to their new value. | 442 labels: (dict) The dictionary which maps label names to their new value. |
| 443 notify: (str) Who should get a notification. | 443 notify: (str) Who should get a notification. |
| 444 tag: (str) Apply this tag to the review comment message and labels(votes): | |
|
Michael Achenbach
2016/07/26 13:59:44
nit: space before (
tandrii(chromium)
2016/07/26 14:06:35
fix in follow up CL https://codereview.chromium.or
| |
| 445 https://gerrit-review.googlesource.com/Documentation/rest-api-changes.ht ml#review-input | |
| 444 """ | 446 """ |
| 445 if message: | 447 if message: |
| 446 tail = u'\n(message too large)' | 448 tail = u'\n(message too large)' |
| 447 if len(message) > max_message: | 449 if len(message) > max_message: |
| 448 message = message[:max_message-len(tail)] + tail # pragma: no cover | 450 message = message[:max_message-len(tail)] + tail # pragma: no cover |
| 449 logging.info('change_id: %s; comment: %s' % (change_id, message.strip())) | 451 logging.info('change_id: %s; comment: %s' % (change_id, message.strip())) |
| 450 payload = {} | 452 payload = {} |
| 451 for var, attr in [(message, 'message'), (notify, 'notify'), | 453 for var, attr in [(message, 'message'), (notify, 'notify'), |
| 452 (labels, 'labels')]: | 454 (labels, 'labels'), (tag, 'tag')]: |
| 453 if var is not None: | 455 if var is not None: |
| 454 payload[attr] = var | 456 payload[attr] = var |
| 455 code, body = self._request( | 457 code, body = self._request( |
| 456 method='POST', | 458 method='POST', |
| 457 request_path='/changes/%s/revisions/%s/review' % ( | 459 request_path='/changes/%s/revisions/%s/review' % ( |
| 458 urllib.quote(change_id, safe='~'), | 460 urllib.quote(change_id, safe='~'), |
| 459 urllib.quote(revision_id, safe='')), | 461 urllib.quote(revision_id, safe='')), |
| 460 body=payload) | 462 body=payload) |
| 461 if code != 200: | 463 if code != 200: |
| 462 raise UnexpectedResponseException(code, body) | 464 raise UnexpectedResponseException(code, body) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 Returns: | 496 Returns: |
| 495 is_cached (bool): | 497 is_cached (bool): |
| 496 """ | 498 """ |
| 497 if method != 'GET': | 499 if method != 'GET': |
| 498 return False # pragma: no cover | 500 return False # pragma: no cover |
| 499 try: | 501 try: |
| 500 cache = requests_cache.get_cache() | 502 cache = requests_cache.get_cache() |
| 501 except AttributeError: # pragma: no cover | 503 except AttributeError: # pragma: no cover |
| 502 cache = None | 504 cache = None |
| 503 return cache.has_url(full_url) if cache else False | 505 return cache.has_url(full_url) if cache else False |
| OLD | NEW |