diff --git a/gerrit_util.py b/gerrit_util.py index d4ce8953c..fea3862b3 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -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')