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