| 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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 path = 'changes/%s/reviewers' % change | 606 path = 'changes/%s/reviewers' % change |
| 607 return ReadHttpJsonResponse(CreateHttpConn(host, path)) | 607 return ReadHttpJsonResponse(CreateHttpConn(host, path)) |
| 608 | 608 |
| 609 | 609 |
| 610 def GetReview(host, change, revision): | 610 def GetReview(host, change, revision): |
| 611 """Get review information about a specific revision of a change.""" | 611 """Get review information about a specific revision of a change.""" |
| 612 path = 'changes/%s/revisions/%s/review' % (change, revision) | 612 path = 'changes/%s/revisions/%s/review' % (change, revision) |
| 613 return ReadHttpJsonResponse(CreateHttpConn(host, path)) | 613 return ReadHttpJsonResponse(CreateHttpConn(host, path)) |
| 614 | 614 |
| 615 | 615 |
| 616 def AddReviewers(host, change, add=None): | 616 def AddReviewers(host, change, add=None, is_reviewer=True): |
| 617 """Add reviewers to a change.""" | 617 """Add reviewers to a change.""" |
| 618 if not add: | 618 if not add: |
| 619 return | 619 return |
| 620 if isinstance(add, basestring): | 620 if isinstance(add, basestring): |
| 621 add = (add,) | 621 add = (add,) |
| 622 path = 'changes/%s/reviewers' % change | 622 path = 'changes/%s/reviewers' % change |
| 623 for r in add: | 623 for r in add: |
| 624 body = {'reviewer': r} | 624 body = { |
| 625 'reviewer': r, |
| 626 'state': 'REVIEWER' if is_reviewer else 'CC', |
| 627 } |
| 625 conn = CreateHttpConn(host, path, reqtype='POST', body=body) | 628 conn = CreateHttpConn(host, path, reqtype='POST', body=body) |
| 626 jmsg = ReadHttpJsonResponse(conn, ignore_404=False) | 629 jmsg = ReadHttpJsonResponse(conn, ignore_404=False) |
| 627 return jmsg | 630 return jmsg |
| 628 | 631 |
| 629 | 632 |
| 630 def RemoveReviewers(host, change, remove=None): | 633 def RemoveReviewers(host, change, remove=None): |
| 631 """Remove reveiewers from a change.""" | 634 """Remove reveiewers from a change.""" |
| 632 if not remove: | 635 if not remove: |
| 633 return | 636 return |
| 634 if isinstance(remove, basestring): | 637 if isinstance(remove, basestring): |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 username = review.get('email', jmsg.get('name', '')) | 709 username = review.get('email', jmsg.get('name', '')) |
| 707 raise GerritError(200, 'Unable to set %s label for user "%s"' | 710 raise GerritError(200, 'Unable to set %s label for user "%s"' |
| 708 ' on change %s.' % (label, username, change)) | 711 ' on change %s.' % (label, username, change)) |
| 709 jmsg = GetChangeCurrentRevision(host, change) | 712 jmsg = GetChangeCurrentRevision(host, change) |
| 710 if not jmsg: | 713 if not jmsg: |
| 711 raise GerritError( | 714 raise GerritError( |
| 712 200, 'Could not get review information for change "%s"' % change) | 715 200, 'Could not get review information for change "%s"' % change) |
| 713 elif jmsg[0]['current_revision'] != revision: | 716 elif jmsg[0]['current_revision'] != revision: |
| 714 raise GerritError(200, 'While resetting labels on change "%s", ' | 717 raise GerritError(200, 'While resetting labels on change "%s", ' |
| 715 'a new patchset was uploaded.' % change) | 718 'a new patchset was uploaded.' % change) |
| OLD | NEW |