mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
[gerrit] Add more gerrit API wrappers
Add helpers to gerrit_util for: * Setting the commit message on a ChangeEdit, * Creating a cherry-pick, * Getting the contents of a file in a change. Bug: v8:12849 Change-Id: I1a5de3054a366d480def32942fd42be179ffb749 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3683383 Auto-Submit: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com> Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
This commit is contained in:
@@ -782,6 +782,14 @@ def ChangeEdit(host, change, path, data):
|
||||
return ReadHttpJsonResponse(conn, accept_statuses=(204, 409))
|
||||
|
||||
|
||||
def SetChangeEditMessage(host, change, message):
|
||||
"""Sets the commit message of a change edit."""
|
||||
path = 'changes/%s/edit:message' % change
|
||||
body = {'message': message}
|
||||
conn = CreateHttpConn(host, path, reqtype='PUT', body=body)
|
||||
return ReadHttpJsonResponse(conn, accept_statuses=(204, 409))
|
||||
|
||||
|
||||
def HasPendingChangeEdit(host, change):
|
||||
conn = CreateHttpConn(host, 'changes/%s/edit' % change)
|
||||
try:
|
||||
@@ -801,6 +809,28 @@ def DeletePendingChangeEdit(host, change):
|
||||
ReadHttpResponse(conn, accept_statuses=[204, 404])
|
||||
|
||||
|
||||
def CherryPick(host, change, destination, revision='current'):
|
||||
"""Create a cherry-pick commit from the given change, onto the given
|
||||
destination.
|
||||
"""
|
||||
path = 'changes/%s/revisions/%s/cherrypick' % (change, revision)
|
||||
body = {'destination': destination}
|
||||
conn = CreateHttpConn(host, path, reqtype='POST', body=body)
|
||||
return ReadHttpJsonResponse(conn)
|
||||
|
||||
|
||||
def GetFileContents(host, change, path):
|
||||
"""Get the contents of a file with the given path in the given revision.
|
||||
|
||||
Returns:
|
||||
A bytes object with the file's contents.
|
||||
"""
|
||||
path = 'changes/%s/revisions/current/files/%s/content' % (
|
||||
change, urllib.parse.quote(path, ''))
|
||||
conn = CreateHttpConn(host, path, reqtype='GET')
|
||||
return base64.b64decode(ReadHttpResponse(conn).read())
|
||||
|
||||
|
||||
def SetCommitMessage(host, change, description, notify='ALL'):
|
||||
"""Updates a commit message."""
|
||||
assert notify in ('ALL', 'NONE')
|
||||
|
||||
Reference in New Issue
Block a user