git-cl-upload: Set all reviewers and ccs in a single batch api call
The old system had two faults:
* It set reviewers and ccs via different mechanisms, which is confusing
* It set CCs with a single call for each, resulting in N separate emails,
with each email going to the uploader and all reviewers and all previous
CCs.
This new system just collects all reviewers and CCs, and sets them
in a single call. That call will fail if *any* of the individual
reviewers or ccs fail, so it also parses the response and retries with
only the ones which would have succeeded on their own. If that second
call fails, or the first fails in an unexpected way, it raises an
exception like normal
Bug: 710028
Change-Id: I1be508487a41f0b68f9c41908229b8f5342830a3
Reviewed-on: https://chromium-review.googlesource.com/479712
Commit-Queue: Aaron Gable <agable@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/git_cl.py b/git_cl.py
index 69c23a7..9dff895 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2937,6 +2937,14 @@
'single commit.')
confirm_or_exit(action='upload')
+ if options.reviewers or options.tbrs or options.add_owners_to:
+ change_desc.update_reviewers(options.reviewers, options.tbrs,
+ options.add_owners_to, change)
+
+ if options.send_mail:
+ if not change_desc.get_reviewers():
+ DieWithError('Must specify reviewers to send email.', change_desc)
+
# Extra options that can be specified at push time. Doc:
# https://gerrit-review.googlesource.com/Documentation/user-upload.html
refspec_opts = []
@@ -2960,16 +2968,9 @@
# reverse on its side.
refspec_opts.append('m=' + title.replace(' ', '_'))
- if options.send_mail:
- if not change_desc.get_reviewers():
- DieWithError('Must specify reviewers to send email.', change_desc)
- refspec_opts.append('notify=ALL')
- else:
- refspec_opts.append('notify=NONE')
-
- reviewers = change_desc.get_reviewers()
- if reviewers:
- refspec_opts.extend('r=' + email.strip() for email in reviewers)
+ # Never notify now because no one is on the review. Notify when we add
+ # reviewers and CCs below.
+ refspec_opts.append('notify=NONE')
if options.private:
refspec_opts.append('draft')
@@ -3013,6 +3014,8 @@
self.SetIssue(change_numbers[0])
self._GitSetBranchConfigValue('gerritsquashhash', ref_to_push)
+ reviewers = sorted(change_desc.get_reviewers())
+
# Add cc's from the CC_LIST and --cc flag (if any).
cc = self.GetCCList().split(',')
if options.cc:
@@ -3020,10 +3023,11 @@
cc = filter(None, [email.strip() for email in cc])
if change_desc.get_cced():
cc.extend(change_desc.get_cced())
- if cc:
- gerrit_util.AddReviewers(
- self._GetGerritHost(), self.GetIssue(), cc,
- is_reviewer=False, notify=bool(options.send_mail))
+
+ gerrit_util.AddReviewers(
+ self._GetGerritHost(), self.GetIssue(), reviewers, cc,
+ notify=bool(options.send_mail))
+
return 0
def _ComputeParent(self, remote, upstream_branch, custom_cl_base, force,