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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 484 |
485 | 485 |
486 def GetChangeDescriptionFromGitiles(url, revision): | 486 def GetChangeDescriptionFromGitiles(url, revision): |
487 """Query Gitiles for actual commit message for a given url and ref. | 487 """Query Gitiles for actual commit message for a given url and ref. |
488 | 488 |
489 url must be obtained from call to GetChangeDetail for a specific | 489 url must be obtained from call to GetChangeDetail for a specific |
490 revision (patchset) under 'fetch' key. | 490 revision (patchset) under 'fetch' key. |
491 """ | 491 """ |
492 parsed = urlparse.urlparse(url) | 492 parsed = urlparse.urlparse(url) |
493 path = '%s/+/%s?format=json' % (parsed.path, revision) | 493 path = '%s/+/%s?format=json' % (parsed.path, revision) |
| 494 # 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 |
| 496 # all Gerrit instances out there. Thus, if line below fails, consider adding a |
| 497 # fallback onto actually fetching ref from remote using pure git. |
494 return ReadHttpJsonResponse(CreateHttpConn(parsed.netloc, path))['message'] | 498 return ReadHttpJsonResponse(CreateHttpConn(parsed.netloc, path))['message'] |
495 | 499 |
496 | 500 |
497 def GetChangeCurrentRevision(host, change): | 501 def GetChangeCurrentRevision(host, change): |
498 """Get information about the latest revision for a given change.""" | 502 """Get information about the latest revision for a given change.""" |
499 return QueryChanges(host, {}, change, o_params=('CURRENT_REVISION',)) | 503 return QueryChanges(host, {}, change, o_params=('CURRENT_REVISION',)) |
500 | 504 |
501 | 505 |
502 def GetChangeRevisions(host, change): | 506 def GetChangeRevisions(host, change): |
503 """Get information about all revisions associated with a change.""" | 507 """Get information about all revisions associated with a change.""" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 username = review.get('email', jmsg.get('name', '')) | 650 username = review.get('email', jmsg.get('name', '')) |
647 raise GerritError(200, 'Unable to set %s label for user "%s"' | 651 raise GerritError(200, 'Unable to set %s label for user "%s"' |
648 ' on change %s.' % (label, username, change)) | 652 ' on change %s.' % (label, username, change)) |
649 jmsg = GetChangeCurrentRevision(host, change) | 653 jmsg = GetChangeCurrentRevision(host, change) |
650 if not jmsg: | 654 if not jmsg: |
651 raise GerritError( | 655 raise GerritError( |
652 200, 'Could not get review information for change "%s"' % change) | 656 200, 'Could not get review information for change "%s"' % change) |
653 elif jmsg[0]['current_revision'] != revision: | 657 elif jmsg[0]['current_revision'] != revision: |
654 raise GerritError(200, 'While resetting labels on change "%s", ' | 658 raise GerritError(200, 'While resetting labels on change "%s", ' |
655 'a new patchset was uploaded.' % change) | 659 'a new patchset was uploaded.' % change) |
OLD | NEW |