Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: gerrit_util.py

Issue 2318903002: Prompt to delete pending edits before changing the Gerrit CL description. (Closed)
Patch Set: CL comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | git_cl.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """ 5 """
6 Utilities for requesting information for a gerrit server via https. 6 Utilities for requesting information for a gerrit server via https.
7 7
8 https://gerrit-review.googlesource.com/Documentation/rest-api.html 8 https://gerrit-review.googlesource.com/Documentation/rest-api.html
9 """ 9 """
10 10
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 538
539 539
540 def SubmitChange(host, change, wait_for_merge=True): 540 def SubmitChange(host, change, wait_for_merge=True):
541 """Submits a gerrit change via Gerrit.""" 541 """Submits a gerrit change via Gerrit."""
542 path = 'changes/%s/submit' % change 542 path = 'changes/%s/submit' % change
543 body = {'wait_for_merge': wait_for_merge} 543 body = {'wait_for_merge': wait_for_merge}
544 conn = CreateHttpConn(host, path, reqtype='POST', body=body) 544 conn = CreateHttpConn(host, path, reqtype='POST', body=body)
545 return ReadHttpJsonResponse(conn, ignore_404=False) 545 return ReadHttpJsonResponse(conn, ignore_404=False)
546 546
547 547
548 def HasPendingChangeEdit(host, change):
549 conn = CreateHttpConn(host, 'changes/%s/edit' % change)
550 try:
551 ReadHttpResponse(conn, ignore_404=False)
552 except GerritError as e:
553 # On success, gerrit returns status 204; anything else is an error.
554 if e.http_status != 204:
555 raise
556 return False
557 else:
558 return True
559
560
561 def DeletePendingChangeEdit(host, change):
562 conn = CreateHttpConn(host, 'changes/%s/edit' % change, reqtype='DELETE')
563 try:
564 ReadHttpResponse(conn, ignore_404=False)
565 except GerritError as e:
566 # On success, gerrit returns status 204; if the edit was already deleted it
567 # returns 404. Anything else is an error.
568 if e.http_status not in (204, 404):
569 raise
570
571
548 def SetCommitMessage(host, change, description): 572 def SetCommitMessage(host, change, description):
549 """Updates a commit message.""" 573 """Updates a commit message."""
550 # First, edit the commit message in a draft. 574 # First, edit the commit message in a draft.
551 path = 'changes/%s/edit:message' % change 575 path = 'changes/%s/edit:message' % change
552 body = {'message': description} 576 body = {'message': description}
553 conn = CreateHttpConn(host, path, reqtype='PUT', body=body) 577 conn = CreateHttpConn(host, path, reqtype='PUT', body=body)
554 try: 578 try:
555 ReadHttpResponse(conn, ignore_404=False) 579 ReadHttpResponse(conn, ignore_404=False)
556 except GerritError as e: 580 except GerritError as e:
557 # On success, gerrit returns status 204; anything else is an error. 581 # On success, gerrit returns status 204; anything else is an error.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 username = review.get('email', jmsg.get('name', '')) 706 username = review.get('email', jmsg.get('name', ''))
683 raise GerritError(200, 'Unable to set %s label for user "%s"' 707 raise GerritError(200, 'Unable to set %s label for user "%s"'
684 ' on change %s.' % (label, username, change)) 708 ' on change %s.' % (label, username, change))
685 jmsg = GetChangeCurrentRevision(host, change) 709 jmsg = GetChangeCurrentRevision(host, change)
686 if not jmsg: 710 if not jmsg:
687 raise GerritError( 711 raise GerritError(
688 200, 'Could not get review information for change "%s"' % change) 712 200, 'Could not get review information for change "%s"' % change)
689 elif jmsg[0]['current_revision'] != revision: 713 elif jmsg[0]['current_revision'] != revision:
690 raise GerritError(200, 'While resetting labels on change "%s", ' 714 raise GerritError(200, 'While resetting labels on change "%s", '
691 'a new patchset was uploaded.' % change) 715 'a new patchset was uploaded.' % change)
OLDNEW
« no previous file with comments | « no previous file | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698