Allow uploader to control who should be notified on upload

A new 'notify' option is added that can be specified on push:

  git push ssh://bot@gerrit:29418/foo HEAD:refs/for/master%notify=NONE

It supports the same values as the notify option in ReviewInput:

  NONE, OWNER, OWNER_REVIEWERS, ALL

This is useful to reduce email noise when bot users are automatically
uploading changes and patch sets. E.g. a bot that is able to forge
committer and author may want to upload a commit without cc-ing the
author and the committer of that commit.

Change-Id: I473703a439018c3097f5c3de8f47d3f8371551ab
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-01-29 10:56:07 +01:00
parent 33543b7ed8
commit 9e078d805b
6 changed files with 103 additions and 14 deletions

View File

@@ -22,6 +22,7 @@ import com.google.common.base.MoreObjects;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.common.data.LabelTypes;
import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Branch;
@@ -102,6 +103,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
private Iterable<String> groups;
private CommitValidators.Policy validatePolicy =
CommitValidators.Policy.GERRIT;
private NotifyHandling notify = NotifyHandling.ALL;
private Set<Account.Id> reviewers;
private Set<Account.Id> extraCC;
private Map<String, Short> approvals;
@@ -206,6 +208,11 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
return this;
}
public ChangeInserter setNotify(NotifyHandling notify) {
this.notify = notify;
return this;
}
public ChangeInserter setReviewers(Set<Account.Id> reviewers) {
this.reviewers = reviewers;
return this;
@@ -347,6 +354,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
createChangeSenderFactory.create(change.getId());
cm.setFrom(change.getOwner());
cm.setPatchSet(patchSet, patchSetInfo);
cm.setNotify(notify);
cm.addReviewers(reviewers);
cm.addExtraCC(extraCC);
cm.send();