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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 476 |
477 | 477 |
478 def GetChangeDetail(host, change, o_params=None): | 478 def GetChangeDetail(host, change, o_params=None): |
479 """Query a gerrit server for extended information about a single change.""" | 479 """Query a gerrit server for extended information about a single change.""" |
480 path = 'changes/%s/detail' % change | 480 path = 'changes/%s/detail' % change |
481 if o_params: | 481 if o_params: |
482 path += '?%s' % '&'.join(['o=%s' % p for p in o_params]) | 482 path += '?%s' % '&'.join(['o=%s' % p for p in o_params]) |
483 return ReadHttpJsonResponse(CreateHttpConn(host, path)) | 483 return ReadHttpJsonResponse(CreateHttpConn(host, path)) |
484 | 484 |
485 | 485 |
| 486 def GetChangeCommit(host, change, revision='current'): |
| 487 """Query a gerrit server for a revision associated with a change.""" |
| 488 path = 'changes/%s/revisions/%s/commit?links' % (change, revision) |
| 489 return ReadHttpJsonResponse(CreateHttpConn(host, path)) |
| 490 |
| 491 |
486 def GetChangeDescriptionFromGitiles(url, revision): | 492 def GetChangeDescriptionFromGitiles(url, revision): |
487 """Query Gitiles for actual commit message for a given url and ref. | 493 """Query Gitiles for actual commit message for a given url and ref. |
488 | 494 |
489 url must be obtained from call to GetChangeDetail for a specific | 495 url must be obtained from call to GetChangeDetail for a specific |
490 revision (patchset) under 'fetch' key. | 496 revision (patchset) under 'fetch' key. |
491 """ | 497 """ |
492 parsed = urlparse.urlparse(url) | 498 parsed = urlparse.urlparse(url) |
493 path = '%s/+/%s?format=json' % (parsed.path, revision) | 499 path = '%s/+/%s?format=json' % (parsed.path, revision) |
494 # Note: Gerrit instances that Chrome infrastructure uses thus far have all | 500 # Note: Gerrit instances that Chrome infrastructure uses thus far have all |
495 # enabled Gitiles, which allowes us to execute this call. This isn't true for | 501 # enabled Gitiles, which allowes us to execute this call. This isn't true for |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 username = review.get('email', jmsg.get('name', '')) | 715 username = review.get('email', jmsg.get('name', '')) |
710 raise GerritError(200, 'Unable to set %s label for user "%s"' | 716 raise GerritError(200, 'Unable to set %s label for user "%s"' |
711 ' on change %s.' % (label, username, change)) | 717 ' on change %s.' % (label, username, change)) |
712 jmsg = GetChangeCurrentRevision(host, change) | 718 jmsg = GetChangeCurrentRevision(host, change) |
713 if not jmsg: | 719 if not jmsg: |
714 raise GerritError( | 720 raise GerritError( |
715 200, 'Could not get review information for change "%s"' % change) | 721 200, 'Could not get review information for change "%s"' % change) |
716 elif jmsg[0]['current_revision'] != revision: | 722 elif jmsg[0]['current_revision'] != revision: |
717 raise GerritError(200, 'While resetting labels on change "%s", ' | 723 raise GerritError(200, 'While resetting labels on change "%s", ' |
718 'a new patchset was uploaded.' % change) | 724 'a new patchset was uploaded.' % change) |
OLD | NEW |