| 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, tag=None): | 432 notify=NOTIFY_NONE, max_message=300, tag=None, |
| 433 on_behalf_of=None): |
| 433 """Uses the Set Review endpoint of the Gerrit API to add messages and/or set | 434 """Uses the Set Review endpoint of the Gerrit API to add messages and/or set |
| 434 labels for a patchset. | 435 labels for a patchset. |
| 436 |
| 435 Documentation: | 437 Documentation: |
| 436 https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#s
et-review | 438 https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#s
et-review |
| 437 | 439 |
| 438 Args: | 440 Args: |
| 439 change_id: (str) The id of the change list. | 441 change_id: (str) The id of the change list. |
| 440 revision_id: (str) The id of the affected revision. | 442 revision_id: (str) The id of the affected revision. |
| 441 message: (str) The message to add to the patchset. | 443 message: (str) The message to add to the patchset. |
| 442 labels: (dict) The dictionary which maps label names to their new value. | 444 labels: (dict) The dictionary which maps label names to their new value. |
| 443 notify: (str) Who should get a notification. | 445 notify: (str) Who should get a notification. |
| 444 tag: (str) Apply this tag to the review comment message and labels(votes): | 446 tag: (str) Apply this tag to the review comment message and labels (votes) |
| 445 https://gerrit-review.googlesource.com/Documentation/rest-api-changes.ht
ml#review-input | 447 https://gerrit-review.googlesource.com/Documentation/rest-api-changes.ht
ml#review-input |
| 448 on_behalf_of: (str) The account_id of the user on whose behalf to set |
| 449 labels. |
| 446 """ | 450 """ |
| 447 if message: | 451 if message: |
| 448 tail = u'\n(message too large)' | 452 tail = u'\n(message too large)' |
| 449 if len(message) > max_message: | 453 if len(message) > max_message: |
| 450 message = message[:max_message-len(tail)] + tail # pragma: no cover | 454 message = message[:max_message-len(tail)] + tail # pragma: no cover |
| 451 logging.info('change_id: %s; comment: %s' % (change_id, message.strip())) | 455 logging.info('change_id: %s; comment: %s' % (change_id, message.strip())) |
| 452 payload = {} | 456 payload = {} |
| 453 for var, attr in [(message, 'message'), (notify, 'notify'), | 457 for var, attr in [(message, 'message'), (notify, 'notify'), |
| 454 (labels, 'labels'), (tag, 'tag')]: | 458 (labels, 'labels'), (tag, 'tag'), |
| 459 (on_behalf_of, 'on_behalf_of')]: |
| 455 if var is not None: | 460 if var is not None: |
| 456 payload[attr] = var | 461 payload[attr] = var |
| 457 code, body = self._request( | 462 code, body = self._request( |
| 458 method='POST', | 463 method='POST', |
| 459 request_path='/changes/%s/revisions/%s/review' % ( | 464 request_path='/changes/%s/revisions/%s/review' % ( |
| 460 urllib.quote(change_id, safe='~'), | 465 urllib.quote(change_id, safe='~'), |
| 461 urllib.quote(revision_id, safe='')), | 466 urllib.quote(revision_id, safe='')), |
| 462 body=payload) | 467 body=payload) |
| 463 if code != 200: | 468 if code != 200: |
| 464 raise UnexpectedResponseException(code, body) | 469 raise UnexpectedResponseException(code, body) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 Returns: | 501 Returns: |
| 497 is_cached (bool): | 502 is_cached (bool): |
| 498 """ | 503 """ |
| 499 if method != 'GET': | 504 if method != 'GET': |
| 500 return False # pragma: no cover | 505 return False # pragma: no cover |
| 501 try: | 506 try: |
| 502 cache = requests_cache.get_cache() | 507 cache = requests_cache.get_cache() |
| 503 except AttributeError: # pragma: no cover | 508 except AttributeError: # pragma: no cover |
| 504 cache = None | 509 cache = None |
| 505 return cache.has_url(full_url) if cache else False | 510 return cache.has_url(full_url) if cache else False |
| OLD | NEW |