git-cl-description: use atomic edit API

https://gerrit-review.googlesource.com/c/110057/ has been deployed,
so this change can now take advantage of that new API to make
git-cl-description more reliable.

Both the API to add content to a change edit and to publish a
change edit return '204 No Content' on a successful call, but this
API returns 200. It seems likely to me that one or the other will
change, so this calling code accepts both codes for future-proofness.

Bug: gerrit:5099
Change-Id: I14d5323f92c807036f8aa11b314d10706c51dbf5
Reviewed-on: https://chromium-review.googlesource.com/544118
Commit-Queue: Aaron Gable <agable@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
changes/18/544118/5
Aaron Gable 8 years ago committed by Commit Bot
parent 1306bd03c9
commit 7625d880d7

@ -612,42 +612,18 @@ def DeletePendingChangeEdit(host, change):
def SetCommitMessage(host, change, description, notify='ALL'):
"""Updates a commit message."""
try:
assert notify in ('ALL', 'NONE')
# First, edit the commit message in a draft.
path = 'changes/%s/edit:message' % change
path = 'changes/%s/message' % change
body = {'message': description}
conn = CreateHttpConn(host, path, reqtype='PUT', body=body)
try:
ReadHttpResponse(conn, accept_statuses=[204])
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)
# 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
def GetReviewers(host, change):
"""Get information about all reviewers attached to a change."""

Loading…
Cancel
Save