| 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 538 |
| 539 | 539 |
| 540 def SubmitChange(host, change, wait_for_merge=True): | 540 def SubmitChange(host, change, wait_for_merge=True): |
| 541 """Submits a gerrit change via Gerrit.""" | 541 """Submits a gerrit change via Gerrit.""" |
| 542 path = 'changes/%s/submit' % change | 542 path = 'changes/%s/submit' % change |
| 543 body = {'wait_for_merge': wait_for_merge} | 543 body = {'wait_for_merge': wait_for_merge} |
| 544 conn = CreateHttpConn(host, path, reqtype='POST', body=body) | 544 conn = CreateHttpConn(host, path, reqtype='POST', body=body) |
| 545 return ReadHttpJsonResponse(conn, ignore_404=False) | 545 return ReadHttpJsonResponse(conn, ignore_404=False) |
| 546 | 546 |
| 547 | 547 |
| 548 def HasPendingChangeEdit(host, change): |
| 549 conn = CreateHttpConn(host, 'changes/%s/edit' % change) |
| 550 try: |
| 551 ReadHttpResponse(conn, ignore_404=False) |
| 552 except GerritError as e: |
| 553 # On success, gerrit returns status 204; anything else is an error. |
| 554 if e.http_status != 204: |
| 555 raise |
| 556 return False |
| 557 else: |
| 558 return True |
| 559 |
| 560 |
| 561 def DeletePendingChangeEdit(host, change): |
| 562 conn = CreateHttpConn(host, 'changes/%s/edit' % change, reqtype='DELETE') |
| 563 try: |
| 564 ReadHttpResponse(conn, ignore_404=False) |
| 565 except GerritError as e: |
| 566 # On success, gerrit returns status 204; if the edit was already deleted it |
| 567 # returns 404. Anything else is an error. |
| 568 if e.http_status not in (204, 404): |
| 569 raise |
| 570 |
| 571 |
| 548 def SetCommitMessage(host, change, description): | 572 def SetCommitMessage(host, change, description): |
| 549 """Updates a commit message.""" | 573 """Updates a commit message.""" |
| 550 # First, edit the commit message in a draft. | 574 # First, edit the commit message in a draft. |
| 551 path = 'changes/%s/edit:message' % change | 575 path = 'changes/%s/edit:message' % change |
| 552 body = {'message': description} | 576 body = {'message': description} |
| 553 conn = CreateHttpConn(host, path, reqtype='PUT', body=body) | 577 conn = CreateHttpConn(host, path, reqtype='PUT', body=body) |
| 554 try: | 578 try: |
| 555 ReadHttpResponse(conn, ignore_404=False) | 579 ReadHttpResponse(conn, ignore_404=False) |
| 556 except GerritError as e: | 580 except GerritError as e: |
| 557 # On success, gerrit returns status 204; anything else is an error. | 581 # On success, gerrit returns status 204; anything else is an error. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 username = review.get('email', jmsg.get('name', '')) | 706 username = review.get('email', jmsg.get('name', '')) |
| 683 raise GerritError(200, 'Unable to set %s label for user "%s"' | 707 raise GerritError(200, 'Unable to set %s label for user "%s"' |
| 684 ' on change %s.' % (label, username, change)) | 708 ' on change %s.' % (label, username, change)) |
| 685 jmsg = GetChangeCurrentRevision(host, change) | 709 jmsg = GetChangeCurrentRevision(host, change) |
| 686 if not jmsg: | 710 if not jmsg: |
| 687 raise GerritError( | 711 raise GerritError( |
| 688 200, 'Could not get review information for change "%s"' % change) | 712 200, 'Could not get review information for change "%s"' % change) |
| 689 elif jmsg[0]['current_revision'] != revision: | 713 elif jmsg[0]['current_revision'] != revision: |
| 690 raise GerritError(200, 'While resetting labels on change "%s", ' | 714 raise GerritError(200, 'While resetting labels on change "%s", ' |
| 691 'a new patchset was uploaded.' % change) | 715 'a new patchset was uploaded.' % change) |
| OLD | NEW |