Commit c1c45f8a authored by Leszek Swirski's avatar Leszek Swirski Committed by LUCI CQ

[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: 's avatarAravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
parent b3579d42
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment