Commit df86e301 authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

Clean up gerrit_util's handling of unknown reviewer/cc

This is still important, but at least now it won't result
in a stacktrace.

Change-Id: If6e7e15a98b0a03df7e978201762fea670312ede
Reviewed-on: https://chromium-review.googlesource.com/408660Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
parent 600d9dfd
......@@ -621,19 +621,28 @@ def GetReview(host, change, revision):
def AddReviewers(host, change, add=None, is_reviewer=True):
"""Add reviewers to a change."""
errors = None
if not add:
return
return None
if isinstance(add, basestring):
add = (add,)
path = 'changes/%s/reviewers' % change
for r in add:
state = 'REVIEWER' if is_reviewer else 'CC'
body = {
'reviewer': r,
'state': 'REVIEWER' if is_reviewer else 'CC',
'state': state,
}
conn = CreateHttpConn(host, path, reqtype='POST', body=body)
jmsg = ReadHttpJsonResponse(conn, ignore_404=False)
return jmsg
try:
conn = CreateHttpConn(host, path, reqtype='POST', body=body)
_ = ReadHttpJsonResponse(conn, ignore_404=False)
except GerritError as e:
if e.http_status == 422: # "Unprocessable Entity"
LOGGER.warn('Failed to add "%s" as a %s' % (r, state.lower()))
errors = True
else:
raise
return errors
def RemoveReviewers(host, change, remove=None):
......
......@@ -2842,8 +2842,10 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
if change_desc.get_cced():
cc.extend(change_desc.get_cced())
if cc:
gerrit_util.AddReviewers(
errors = gerrit_util.AddReviewers(
self._GetGerritHost(), self.GetIssue(), cc, is_reviewer=False)
if errors:
return 1
return 0
......
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