diff --git a/gerrit_util.py b/gerrit_util.py index f2020bedd..bd3043d48 100755 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -612,41 +612,17 @@ def DeletePendingChangeEdit(host, change): def SetCommitMessage(host, change, description, notify='ALL'): """Updates a commit message.""" + assert notify in ('ALL', 'NONE') + path = 'changes/%s/message' % change + body = {'message': description} + conn = CreateHttpConn(host, path, reqtype='PUT', body=body) try: - assert notify in ('ALL', 'NONE') - # First, edit the commit message in a draft. - path = 'changes/%s/edit:message' % change - body = {'message': description} - conn = CreateHttpConn(host, path, reqtype='PUT', body=body) - try: - ReadHttpResponse(conn, accept_statuses=[204]) - except GerritError as e: - raise GerritError( - e.http_status, - 'Received unexpected http status while editing message ' - 'in change %s' % change) - - # And then publish it. - path = 'changes/%s/edit:publish' % change - conn = CreateHttpConn(host, path, reqtype='POST', body={'notify': notify}) - try: - ReadHttpResponse(conn, accept_statuses=[204]) - except GerritError as e: - raise GerritError( - e.http_status, - 'Received unexpected http status while publishing message ' - 'in change %s' % change) - - except (GerritError, KeyboardInterrupt) as e: - # Something went wrong with one of the two calls, so we want to clean up - # after ourselves before returning. - try: - DeletePendingChangeEdit(host, change) - except GerritError: - LOGGER.error('Encountered error while cleaning up after failed attempt ' - 'to set the CL description. You may have to delete the ' - 'pending change edit yourself in the web UI.') - raise e + ReadHttpResponse(conn, accept_statuses=[200, 204]) + except GerritError as e: + raise GerritError( + e.http_status, + 'Received unexpected http status while editing message ' + 'in change %s' % change) def GetReviewers(host, change):