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 GetChangeDescriptionFromGitiles(url, revision): |
| 487 """Query Gitiles for actual commit message for a given url and ref. |
| 488 |
| 489 url must be obtained from call to GetChangeDetail for a specific |
| 490 revision (patchset) under 'fetch' key. |
| 491 """ |
| 492 parsed = urlparse.urlparse(url) |
| 493 path = '%s/+/%s?format=json' % (parsed.path, revision) |
| 494 return ReadHttpJsonResponse(CreateHttpConn(parsed.netloc, path))['message'] |
| 495 |
| 496 |
486 def GetChangeCurrentRevision(host, change): | 497 def GetChangeCurrentRevision(host, change): |
487 """Get information about the latest revision for a given change.""" | 498 """Get information about the latest revision for a given change.""" |
488 return QueryChanges(host, {}, change, o_params=('CURRENT_REVISION',)) | 499 return QueryChanges(host, {}, change, o_params=('CURRENT_REVISION',)) |
489 | 500 |
490 | 501 |
491 def GetChangeRevisions(host, change): | 502 def GetChangeRevisions(host, change): |
492 """Get information about all revisions associated with a change.""" | 503 """Get information about all revisions associated with a change.""" |
493 return QueryChanges(host, {}, change, o_params=('ALL_REVISIONS',)) | 504 return QueryChanges(host, {}, change, o_params=('ALL_REVISIONS',)) |
494 | 505 |
495 | 506 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 username = review.get('email', jmsg.get('name', '')) | 646 username = review.get('email', jmsg.get('name', '')) |
636 raise GerritError(200, 'Unable to set %s label for user "%s"' | 647 raise GerritError(200, 'Unable to set %s label for user "%s"' |
637 ' on change %s.' % (label, username, change)) | 648 ' on change %s.' % (label, username, change)) |
638 jmsg = GetChangeCurrentRevision(host, change) | 649 jmsg = GetChangeCurrentRevision(host, change) |
639 if not jmsg: | 650 if not jmsg: |
640 raise GerritError( | 651 raise GerritError( |
641 200, 'Could not get review information for change "%s"' % change) | 652 200, 'Could not get review information for change "%s"' % change) |
642 elif jmsg[0]['current_revision'] != revision: | 653 elif jmsg[0]['current_revision'] != revision: |
643 raise GerritError(200, 'While resetting labels on change "%s", ' | 654 raise GerritError(200, 'While resetting labels on change "%s", ' |
644 'a new patchset was uploaded.' % change) | 655 'a new patchset was uploaded.' % change) |
OLD | NEW |