| 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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 elif len(jmsg) > 1: | 472 elif len(jmsg) > 1: |
| 473 raise GerritError(200, 'Multiple changes found for ChangeId %s.' % change) | 473 raise GerritError(200, 'Multiple changes found for ChangeId %s.' % change) |
| 474 revision = jmsg[0]['current_revision'] | 474 revision = jmsg[0]['current_revision'] |
| 475 path = 'changes/%s/revisions/%s/review' | 475 path = 'changes/%s/revisions/%s/review' |
| 476 return ReadHttpJsonResponse(CreateHttpConn(host, path)) | 476 return ReadHttpJsonResponse(CreateHttpConn(host, path)) |
| 477 | 477 |
| 478 | 478 |
| 479 def AbandonChange(host, change, msg=''): | 479 def AbandonChange(host, change, msg=''): |
| 480 """Abandon a gerrit change.""" | 480 """Abandon a gerrit change.""" |
| 481 path = 'changes/%s/abandon' % change | 481 path = 'changes/%s/abandon' % change |
| 482 body = {'message': msg} if msg else None | 482 body = {'message': msg} if msg else {} |
| 483 conn = CreateHttpConn(host, path, reqtype='POST', body=body) | 483 conn = CreateHttpConn(host, path, reqtype='POST', body=body) |
| 484 return ReadHttpJsonResponse(conn, ignore_404=False) | 484 return ReadHttpJsonResponse(conn, ignore_404=False) |
| 485 | 485 |
| 486 | 486 |
| 487 def RestoreChange(host, change, msg=''): | 487 def RestoreChange(host, change, msg=''): |
| 488 """Restore a previously abandoned change.""" | 488 """Restore a previously abandoned change.""" |
| 489 path = 'changes/%s/restore' % change | 489 path = 'changes/%s/restore' % change |
| 490 body = {'message': msg} if msg else None | 490 body = {'message': msg} if msg else {} |
| 491 conn = CreateHttpConn(host, path, reqtype='POST', body=body) | 491 conn = CreateHttpConn(host, path, reqtype='POST', body=body) |
| 492 return ReadHttpJsonResponse(conn, ignore_404=False) | 492 return ReadHttpJsonResponse(conn, ignore_404=False) |
| 493 | 493 |
| 494 | 494 |
| 495 def SubmitChange(host, change, wait_for_merge=True): | 495 def SubmitChange(host, change, wait_for_merge=True): |
| 496 """Submits a gerrit change via Gerrit.""" | 496 """Submits a gerrit change via Gerrit.""" |
| 497 path = 'changes/%s/submit' % change | 497 path = 'changes/%s/submit' % change |
| 498 body = {'wait_for_merge': wait_for_merge} | 498 body = {'wait_for_merge': wait_for_merge} |
| 499 conn = CreateHttpConn(host, path, reqtype='POST', body=body) | 499 conn = CreateHttpConn(host, path, reqtype='POST', body=body) |
| 500 return ReadHttpJsonResponse(conn, ignore_404=False) | 500 return ReadHttpJsonResponse(conn, ignore_404=False) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 username = review.get('email', jmsg.get('name', '')) | 605 username = review.get('email', jmsg.get('name', '')) |
| 606 raise GerritError(200, 'Unable to set %s label for user "%s"' | 606 raise GerritError(200, 'Unable to set %s label for user "%s"' |
| 607 ' on change %s.' % (label, username, change)) | 607 ' on change %s.' % (label, username, change)) |
| 608 jmsg = GetChangeCurrentRevision(host, change) | 608 jmsg = GetChangeCurrentRevision(host, change) |
| 609 if not jmsg: | 609 if not jmsg: |
| 610 raise GerritError( | 610 raise GerritError( |
| 611 200, 'Could not get review information for change "%s"' % change) | 611 200, 'Could not get review information for change "%s"' % change) |
| 612 elif jmsg[0]['current_revision'] != revision: | 612 elif jmsg[0]['current_revision'] != revision: |
| 613 raise GerritError(200, 'While resetting labels on change "%s", ' | 613 raise GerritError(200, 'While resetting labels on change "%s", ' |
| 614 'a new patchset was uploaded.' % change) | 614 'a new patchset was uploaded.' % change) |
| OLD | NEW |