Consistently pass NotifyResolver.Result instead of separate args
Change-Id: I457fa6cc45002a88440e33adf609b52f8610b9eb
This commit is contained in:
@@ -120,8 +120,7 @@ public class AbandonOp implements BatchUpdateOp {
|
|||||||
cm.setFrom(accountState.getAccount().getId());
|
cm.setFrom(accountState.getAccount().getId());
|
||||||
}
|
}
|
||||||
cm.setChangeMessage(message.getMessage(), ctx.getWhen());
|
cm.setChangeMessage(message.getMessage(), ctx.getWhen());
|
||||||
cm.setNotify(notify.handling());
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(notify.accounts());
|
|
||||||
cm.send();
|
cm.send();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.atSevere().withCause(e).log("Cannot email update for change %s", change.getId());
|
logger.atSevere().withCause(e).log("Cannot email update for change %s", change.getId());
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ public class AddReviewersEmail {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
AddReviewerSender cm = addReviewerSenderFactory.create(change.getProject(), change.getId());
|
AddReviewerSender cm = addReviewerSenderFactory.create(change.getProject(), change.getId());
|
||||||
cm.setNotify(notify.handling());
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(notify.accounts());
|
|
||||||
cm.setFrom(userId);
|
cm.setFrom(userId);
|
||||||
cm.addReviewers(toMail);
|
cm.addReviewers(toMail);
|
||||||
cm.addReviewersByEmail(addedByEmail);
|
cm.addReviewersByEmail(addedByEmail);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.change;
|
package com.google.gerrit.server.change;
|
||||||
|
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
@@ -77,13 +76,7 @@ public class BatchAbandon {
|
|||||||
Collection<ChangeData> changes,
|
Collection<ChangeData> changes,
|
||||||
String msgTxt)
|
String msgTxt)
|
||||||
throws RestApiException, UpdateException {
|
throws RestApiException, UpdateException {
|
||||||
batchAbandon(
|
batchAbandon(updateFactory, project, user, changes, msgTxt, NotifyResolver.Result.all());
|
||||||
updateFactory,
|
|
||||||
project,
|
|
||||||
user,
|
|
||||||
changes,
|
|
||||||
msgTxt,
|
|
||||||
NotifyResolver.Result.create(NotifyHandling.ALL));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchAbandon(
|
public void batchAbandon(
|
||||||
@@ -92,12 +85,6 @@ public class BatchAbandon {
|
|||||||
CurrentUser user,
|
CurrentUser user,
|
||||||
Collection<ChangeData> changes)
|
Collection<ChangeData> changes)
|
||||||
throws RestApiException, UpdateException {
|
throws RestApiException, UpdateException {
|
||||||
batchAbandon(
|
batchAbandon(updateFactory, project, user, changes, "", NotifyResolver.Result.all());
|
||||||
updateFactory,
|
|
||||||
project,
|
|
||||||
user,
|
|
||||||
changes,
|
|
||||||
"",
|
|
||||||
NotifyResolver.Result.create(NotifyHandling.ALL));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,16 +24,13 @@ import static java.util.Objects.requireNonNull;
|
|||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import com.google.common.collect.Streams;
|
import com.google.common.collect.Streams;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.FooterConstants;
|
import com.google.gerrit.common.FooterConstants;
|
||||||
import com.google.gerrit.common.data.LabelType;
|
import com.google.gerrit.common.data.LabelType;
|
||||||
import com.google.gerrit.common.data.LabelTypes;
|
import com.google.gerrit.common.data.LabelTypes;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
|
||||||
import com.google.gerrit.extensions.client.ReviewerState;
|
import com.google.gerrit.extensions.client.ReviewerState;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
@@ -123,8 +120,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
private boolean workInProgress;
|
private boolean workInProgress;
|
||||||
private List<String> groups = Collections.emptyList();
|
private List<String> groups = Collections.emptyList();
|
||||||
private boolean validate = true;
|
private boolean validate = true;
|
||||||
private NotifyHandling notify = NotifyHandling.ALL;
|
private NotifyResolver.Result notify = NotifyResolver.Result.all();
|
||||||
private ListMultimap<RecipientType, Account.Id> accountsToNotify = ImmutableListMultimap.of();
|
|
||||||
private Map<String, Short> approvals;
|
private Map<String, Short> approvals;
|
||||||
private RequestScopePropagator requestScopePropagator;
|
private RequestScopePropagator requestScopePropagator;
|
||||||
private boolean fireRevisionCreated;
|
private boolean fireRevisionCreated;
|
||||||
@@ -255,17 +251,11 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeInserter setNotify(NotifyHandling notify) {
|
public ChangeInserter setNotify(NotifyResolver.Result notify) {
|
||||||
this.notify = notify;
|
this.notify = notify;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeInserter setAccountsToNotify(
|
|
||||||
ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
|
||||||
this.accountsToNotify = requireNonNull(accountsToNotify);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChangeInserter setReviewersAndCcs(
|
public ChangeInserter setReviewersAndCcs(
|
||||||
Iterable<Account.Id> reviewers, Iterable<Account.Id> ccs) {
|
Iterable<Account.Id> reviewers, Iterable<Account.Id> ccs) {
|
||||||
return setReviewersAndCcsAsStrings(
|
return setReviewersAndCcsAsStrings(
|
||||||
@@ -457,7 +447,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
@Override
|
@Override
|
||||||
public void postUpdate(Context ctx) throws Exception {
|
public void postUpdate(Context ctx) throws Exception {
|
||||||
reviewerAdditions.postUpdate(ctx);
|
reviewerAdditions.postUpdate(ctx);
|
||||||
if (sendMail && (notify != NotifyHandling.NONE || !accountsToNotify.isEmpty())) {
|
if (sendMail && notify.shouldNotify()) {
|
||||||
Runnable sender =
|
Runnable sender =
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -468,7 +458,6 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
cm.setFrom(change.getOwner());
|
cm.setFrom(change.getOwner());
|
||||||
cm.setPatchSet(patchSet, patchSetInfo);
|
cm.setPatchSet(patchSet, patchSetInfo);
|
||||||
cm.setNotify(notify);
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(accountsToNotify);
|
|
||||||
cm.addReviewers(
|
cm.addReviewers(
|
||||||
reviewerAdditions
|
reviewerAdditions
|
||||||
.flattenResults(AddReviewersOp.Result::addedReviewers)
|
.flattenResults(AddReviewersOp.Result::addedReviewers)
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import com.google.common.flogger.FluentLogger;
|
|||||||
import com.google.gerrit.common.FooterConstants;
|
import com.google.gerrit.common.FooterConstants;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.extensions.api.changes.FixInput;
|
import com.google.gerrit.extensions.api.changes.FixInput;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.common.ProblemInfo;
|
import com.google.gerrit.extensions.common.ProblemInfo;
|
||||||
import com.google.gerrit.extensions.common.ProblemInfo.Status;
|
import com.google.gerrit.extensions.common.ProblemInfo.Status;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
@@ -537,7 +536,7 @@ public class ConsistencyChecker {
|
|||||||
inserter
|
inserter
|
||||||
.setValidate(false)
|
.setValidate(false)
|
||||||
.setFireRevisionCreated(false)
|
.setFireRevisionCreated(false)
|
||||||
.setNotify(NotifyHandling.NONE)
|
.setNotify(NotifyResolver.Result.none())
|
||||||
.setAllowClosed(true)
|
.setAllowClosed(true)
|
||||||
.setMessage("Patch set for merged commit inserted by consistency checker"));
|
.setMessage("Patch set for merged commit inserted by consistency checker"));
|
||||||
bu.addOp(notes.getChangeId(), new FixMergedOp(notFound));
|
bu.addOp(notes.getChangeId(), new FixMergedOp(notFound));
|
||||||
|
|||||||
@@ -16,12 +16,8 @@ package com.google.gerrit.server.change;
|
|||||||
|
|
||||||
import static com.google.gerrit.server.CommentsUtil.COMMENT_ORDER;
|
import static com.google.gerrit.server.CommentsUtil.COMMENT_ORDER;
|
||||||
|
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
|
||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
import com.google.gerrit.reviewdb.client.Comment;
|
import com.google.gerrit.reviewdb.client.Comment;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
@@ -48,7 +44,6 @@ public class EmailReviewComments implements Runnable, RequestContext {
|
|||||||
// on the same set of inputs.
|
// on the same set of inputs.
|
||||||
/**
|
/**
|
||||||
* @param notify setting for handling notification.
|
* @param notify setting for handling notification.
|
||||||
* @param accountsToNotify detailed map of accounts to notify.
|
|
||||||
* @param notes change notes.
|
* @param notes change notes.
|
||||||
* @param patchSet patch set corresponding to the top-level op
|
* @param patchSet patch set corresponding to the top-level op
|
||||||
* @param user user the email should come from.
|
* @param user user the email should come from.
|
||||||
@@ -63,8 +58,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
|
|||||||
* @return handle for sending email.
|
* @return handle for sending email.
|
||||||
*/
|
*/
|
||||||
EmailReviewComments create(
|
EmailReviewComments create(
|
||||||
NotifyHandling notify,
|
NotifyResolver.Result notify,
|
||||||
ListMultimap<RecipientType, Account.Id> accountsToNotify,
|
|
||||||
ChangeNotes notes,
|
ChangeNotes notes,
|
||||||
PatchSet patchSet,
|
PatchSet patchSet,
|
||||||
IdentifiedUser user,
|
IdentifiedUser user,
|
||||||
@@ -79,8 +73,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
|
|||||||
private final CommentSender.Factory commentSenderFactory;
|
private final CommentSender.Factory commentSenderFactory;
|
||||||
private final ThreadLocalRequestContext requestContext;
|
private final ThreadLocalRequestContext requestContext;
|
||||||
|
|
||||||
private final NotifyHandling notify;
|
private final NotifyResolver.Result notify;
|
||||||
private final ListMultimap<RecipientType, Account.Id> accountsToNotify;
|
|
||||||
private final ChangeNotes notes;
|
private final ChangeNotes notes;
|
||||||
private final PatchSet patchSet;
|
private final PatchSet patchSet;
|
||||||
private final IdentifiedUser user;
|
private final IdentifiedUser user;
|
||||||
@@ -95,8 +88,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
|
|||||||
PatchSetInfoFactory patchSetInfoFactory,
|
PatchSetInfoFactory patchSetInfoFactory,
|
||||||
CommentSender.Factory commentSenderFactory,
|
CommentSender.Factory commentSenderFactory,
|
||||||
ThreadLocalRequestContext requestContext,
|
ThreadLocalRequestContext requestContext,
|
||||||
@Assisted NotifyHandling notify,
|
@Assisted NotifyResolver.Result notify,
|
||||||
@Assisted ListMultimap<RecipientType, Account.Id> accountsToNotify,
|
|
||||||
@Assisted ChangeNotes notes,
|
@Assisted ChangeNotes notes,
|
||||||
@Assisted PatchSet patchSet,
|
@Assisted PatchSet patchSet,
|
||||||
@Assisted IdentifiedUser user,
|
@Assisted IdentifiedUser user,
|
||||||
@@ -109,7 +101,6 @@ public class EmailReviewComments implements Runnable, RequestContext {
|
|||||||
this.commentSenderFactory = commentSenderFactory;
|
this.commentSenderFactory = commentSenderFactory;
|
||||||
this.requestContext = requestContext;
|
this.requestContext = requestContext;
|
||||||
this.notify = notify;
|
this.notify = notify;
|
||||||
this.accountsToNotify = accountsToNotify;
|
|
||||||
this.notes = notes;
|
this.notes = notes;
|
||||||
this.patchSet = patchSet;
|
this.patchSet = patchSet;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
@@ -136,7 +127,6 @@ public class EmailReviewComments implements Runnable, RequestContext {
|
|||||||
cm.setPatchSetComment(patchSetComment);
|
cm.setPatchSetComment(patchSetComment);
|
||||||
cm.setLabels(labels);
|
cm.setLabels(labels);
|
||||||
cm.setNotify(notify);
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(accountsToNotify);
|
|
||||||
cm.send();
|
cm.send();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.atSevere().withCause(e).log("Cannot email comments for %s", patchSet.getId());
|
logger.atSevere().withCause(e).log("Cannot email comments for %s", patchSet.getId());
|
||||||
|
|||||||
@@ -41,15 +41,19 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
|||||||
public class NotifyResolver {
|
public class NotifyResolver {
|
||||||
@AutoValue
|
@AutoValue
|
||||||
public abstract static class Result {
|
public abstract static class Result {
|
||||||
static Result none() {
|
public static Result none() {
|
||||||
return create(NotifyHandling.NONE);
|
return create(NotifyHandling.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Result all() {
|
||||||
|
return create(NotifyHandling.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
public static Result create(NotifyHandling notifyHandling) {
|
public static Result create(NotifyHandling notifyHandling) {
|
||||||
return create(notifyHandling, ImmutableListMultimap.of());
|
return create(notifyHandling, ImmutableListMultimap.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Result create(
|
public static Result create(
|
||||||
NotifyHandling handling, ImmutableListMultimap<RecipientType, Account.Id> recipients) {
|
NotifyHandling handling, ImmutableListMultimap<RecipientType, Account.Id> recipients) {
|
||||||
return new AutoValue_NotifyResolver_Result(handling, recipients);
|
return new AutoValue_NotifyResolver_Result(handling, recipients);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,10 @@ import static com.google.gerrit.server.notedb.ReviewerStateInternal.CC;
|
|||||||
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
|
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
@@ -95,8 +91,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
|||||||
private boolean checkAddPatchSetPermission = true;
|
private boolean checkAddPatchSetPermission = true;
|
||||||
private List<String> groups = Collections.emptyList();
|
private List<String> groups = Collections.emptyList();
|
||||||
private boolean fireRevisionCreated = true;
|
private boolean fireRevisionCreated = true;
|
||||||
private NotifyHandling notify = NotifyHandling.ALL;
|
private NotifyResolver.Result notify = NotifyResolver.Result.all();
|
||||||
private ListMultimap<RecipientType, Account.Id> accountsToNotify = ImmutableListMultimap.of();
|
|
||||||
private boolean allowClosed;
|
private boolean allowClosed;
|
||||||
|
|
||||||
// Fields set during some phase of BatchUpdate.Op.
|
// Fields set during some phase of BatchUpdate.Op.
|
||||||
@@ -170,17 +165,11 @@ public class PatchSetInserter implements BatchUpdateOp {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PatchSetInserter setNotify(NotifyHandling notify) {
|
public PatchSetInserter setNotify(NotifyResolver.Result notify) {
|
||||||
this.notify = requireNonNull(notify);
|
this.notify = requireNonNull(notify);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PatchSetInserter setAccountsToNotify(
|
|
||||||
ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
|
||||||
this.accountsToNotify = requireNonNull(accountsToNotify);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PatchSetInserter setAllowClosed(boolean allowClosed) {
|
public PatchSetInserter setAllowClosed(boolean allowClosed) {
|
||||||
this.allowClosed = allowClosed;
|
this.allowClosed = allowClosed;
|
||||||
return this;
|
return this;
|
||||||
@@ -229,7 +218,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
|||||||
psUtil.insert(
|
psUtil.insert(
|
||||||
ctx.getRevWalk(), ctx.getUpdate(psId), psId, commitId, newGroups, null, description);
|
ctx.getRevWalk(), ctx.getUpdate(psId), psId, commitId, newGroups, null, description);
|
||||||
|
|
||||||
if (notify != NotifyHandling.NONE) {
|
if (notify.handling() != NotifyHandling.NONE) {
|
||||||
oldReviewers = approvalsUtil.getReviewers(ctx.getNotes());
|
oldReviewers = approvalsUtil.getReviewers(ctx.getNotes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +247,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postUpdate(Context ctx) throws OrmException {
|
public void postUpdate(Context ctx) throws OrmException {
|
||||||
if (notify != NotifyHandling.NONE || !accountsToNotify.isEmpty()) {
|
if (notify.shouldNotify()) {
|
||||||
try {
|
try {
|
||||||
ReplacePatchSetSender cm = replacePatchSetFactory.create(ctx.getProject(), change.getId());
|
ReplacePatchSetSender cm = replacePatchSetFactory.create(ctx.getProject(), change.getId());
|
||||||
cm.setFrom(ctx.getAccountId());
|
cm.setFrom(ctx.getAccountId());
|
||||||
@@ -267,7 +256,6 @@ public class PatchSetInserter implements BatchUpdateOp {
|
|||||||
cm.addReviewers(oldReviewers.byState(REVIEWER));
|
cm.addReviewers(oldReviewers.byState(REVIEWER));
|
||||||
cm.addExtraCC(oldReviewers.byState(CC));
|
cm.addExtraCC(oldReviewers.byState(CC));
|
||||||
cm.setNotify(notify);
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(accountsToNotify);
|
|
||||||
cm.send();
|
cm.send();
|
||||||
} catch (Exception err) {
|
} catch (Exception err) {
|
||||||
logger.atSevere().withCause(err).log(
|
logger.atSevere().withCause(err).log(
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ package com.google.gerrit.server.change;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.restapi.MergeConflictException;
|
import com.google.gerrit.extensions.restapi.MergeConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
@@ -183,7 +182,7 @@ public class RebaseChangeOp implements BatchUpdateOp {
|
|||||||
patchSetInserterFactory
|
patchSetInserterFactory
|
||||||
.create(notes, rebasedPatchSetId, rebasedCommit)
|
.create(notes, rebasedPatchSetId, rebasedCommit)
|
||||||
.setDescription("Rebase")
|
.setDescription("Rebase")
|
||||||
.setNotify(NotifyHandling.NONE)
|
.setNotify(NotifyResolver.Result.none())
|
||||||
.setFireRevisionCreated(fireRevisionCreated)
|
.setFireRevisionCreated(fireRevisionCreated)
|
||||||
.setCheckAddPatchSetPermission(checkAddPatchSetPermission)
|
.setCheckAddPatchSetPermission(checkAddPatchSetPermission)
|
||||||
.setValidate(validate);
|
.setValidate(validate);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.change;
|
|||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
@@ -92,7 +91,7 @@ public class WorkInProgressOp implements BatchUpdateOp {
|
|||||||
private final PatchSetUtil psUtil;
|
private final PatchSetUtil psUtil;
|
||||||
private final boolean workInProgress;
|
private final boolean workInProgress;
|
||||||
private final Input in;
|
private final Input in;
|
||||||
private final NotifyHandling notify;
|
private final NotifyResolver.Result notify;
|
||||||
private final WorkInProgressStateChanged stateChanged;
|
private final WorkInProgressStateChanged stateChanged;
|
||||||
|
|
||||||
private Change change;
|
private Change change;
|
||||||
@@ -115,8 +114,9 @@ public class WorkInProgressOp implements BatchUpdateOp {
|
|||||||
this.workInProgress = workInProgress;
|
this.workInProgress = workInProgress;
|
||||||
this.in = in;
|
this.in = in;
|
||||||
notify =
|
notify =
|
||||||
MoreObjects.firstNonNull(
|
NotifyResolver.Result.create(
|
||||||
in.notify, workInProgress ? NotifyHandling.NONE : NotifyHandling.ALL);
|
MoreObjects.firstNonNull(
|
||||||
|
in.notify, workInProgress ? NotifyHandling.NONE : NotifyHandling.ALL));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -160,13 +160,12 @@ public class WorkInProgressOp implements BatchUpdateOp {
|
|||||||
@Override
|
@Override
|
||||||
public void postUpdate(Context ctx) {
|
public void postUpdate(Context ctx) {
|
||||||
stateChanged.fire(change, ps, ctx.getAccount(), ctx.getWhen());
|
stateChanged.fire(change, ps, ctx.getAccount(), ctx.getWhen());
|
||||||
if (workInProgress || notify.ordinal() < NotifyHandling.OWNER_REVIEWERS.ordinal()) {
|
if (workInProgress || notify.handling().compareTo(NotifyHandling.OWNER_REVIEWERS) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
email
|
email
|
||||||
.create(
|
.create(
|
||||||
notify,
|
notify,
|
||||||
ImmutableListMultimap.of(),
|
|
||||||
notes,
|
notes,
|
||||||
ps,
|
ps,
|
||||||
ctx.getIdentifiedUser(),
|
ctx.getIdentifiedUser(),
|
||||||
|
|||||||
@@ -170,10 +170,7 @@ public class ChangeEditUtil {
|
|||||||
RevCommit squashed = squashEdit(rw, oi, edit.getEditCommit(), basePatchSet);
|
RevCommit squashed = squashEdit(rw, oi, edit.getEditCommit(), basePatchSet);
|
||||||
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
|
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repo, change.currentPatchSetId());
|
||||||
PatchSetInserter inserter =
|
PatchSetInserter inserter =
|
||||||
patchSetInserterFactory
|
patchSetInserterFactory.create(notes, psId, squashed).setNotify(notify);
|
||||||
.create(notes, psId, squashed)
|
|
||||||
.setNotify(notify.handling())
|
|
||||||
.setAccountsToNotify(notify.accounts());
|
|
||||||
|
|
||||||
StringBuilder message =
|
StringBuilder message =
|
||||||
new StringBuilder("Patch Set ").append(inserter.getPatchSetId().get()).append(": ");
|
new StringBuilder("Patch Set ").append(inserter.getPatchSetId().get()).append(": ");
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.server.GpgException;
|
import com.google.gerrit.server.GpgException;
|
||||||
import com.google.gerrit.server.account.AccountState;
|
import com.google.gerrit.server.account.AccountState;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||||
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
import com.google.gerrit.server.patch.PatchListObjectTooLargeException;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
@@ -46,7 +47,7 @@ public class RevisionCreated {
|
|||||||
PatchSet patchSet,
|
PatchSet patchSet,
|
||||||
AccountState uploader,
|
AccountState uploader,
|
||||||
Timestamp when,
|
Timestamp when,
|
||||||
NotifyHandling notify) {}
|
NotifyResolver.Result notify) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final PluginSetContext<RevisionCreatedListener> listeners;
|
private final PluginSetContext<RevisionCreatedListener> listeners;
|
||||||
@@ -68,7 +69,7 @@ public class RevisionCreated {
|
|||||||
PatchSet patchSet,
|
PatchSet patchSet,
|
||||||
AccountState uploader,
|
AccountState uploader,
|
||||||
Timestamp when,
|
Timestamp when,
|
||||||
NotifyHandling notify) {
|
NotifyResolver.Result notify) {
|
||||||
if (listeners.isEmpty()) {
|
if (listeners.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -79,7 +80,7 @@ public class RevisionCreated {
|
|||||||
util.revisionInfo(change.getProject(), patchSet),
|
util.revisionInfo(change.getProject(), patchSet),
|
||||||
util.accountInfo(uploader),
|
util.accountInfo(uploader),
|
||||||
when,
|
when,
|
||||||
notify);
|
notify.handling());
|
||||||
listeners.runEach(l -> l.onRevisionCreated(event));
|
listeners.runEach(l -> l.onRevisionCreated(event));
|
||||||
} catch (PatchListObjectTooLargeException e) {
|
} catch (PatchListObjectTooLargeException e) {
|
||||||
logger.atWarning().log("Couldn't fire event: %s", e.getMessage());
|
logger.atWarning().log("Couldn't fire event: %s", e.getMessage());
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import com.google.common.base.Throwables;
|
|||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableListMultimap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.LinkedListMultimap;
|
import com.google.common.collect.LinkedListMultimap;
|
||||||
@@ -94,6 +95,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
|||||||
import com.google.gerrit.server.PatchSetUtil;
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.account.AccountResolver;
|
import com.google.gerrit.server.account.AccountResolver;
|
||||||
import com.google.gerrit.server.change.ChangeInserter;
|
import com.google.gerrit.server.change.ChangeInserter;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.change.SetHashtagsOp;
|
import com.google.gerrit.server.change.SetHashtagsOp;
|
||||||
import com.google.gerrit.server.config.AllProjectsName;
|
import com.google.gerrit.server.config.AllProjectsName;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
@@ -1386,7 +1388,7 @@ class ReceiveCommits {
|
|||||||
"Notify handling that defines to whom email notifications "
|
"Notify handling that defines to whom email notifications "
|
||||||
+ "should be sent. Allowed values are NONE, OWNER, "
|
+ "should be sent. Allowed values are NONE, OWNER, "
|
||||||
+ "OWNER_REVIEWERS, ALL. If not set, the default is ALL.")
|
+ "OWNER_REVIEWERS, ALL. If not set, the default is ALL.")
|
||||||
private NotifyHandling notify;
|
private NotifyHandling notifyHandling;
|
||||||
|
|
||||||
@Option(
|
@Option(
|
||||||
name = "--notify-to",
|
name = "--notify-to",
|
||||||
@@ -1516,15 +1518,6 @@ class ReceiveCommits {
|
|||||||
.collect(toImmutableSet());
|
.collect(toImmutableSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
ListMultimap<RecipientType, Account.Id> getAccountsToNotify() {
|
|
||||||
ListMultimap<RecipientType, Account.Id> accountsToNotify =
|
|
||||||
MultimapBuilder.hashKeys().arrayListValues().build();
|
|
||||||
accountsToNotify.putAll(RecipientType.TO, notifyTo);
|
|
||||||
accountsToNotify.putAll(RecipientType.CC, notifyCc);
|
|
||||||
accountsToNotify.putAll(RecipientType.BCC, notifyBcc);
|
|
||||||
return accountsToNotify;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldPublishComments() {
|
boolean shouldPublishComments() {
|
||||||
if (publishComments) {
|
if (publishComments) {
|
||||||
return true;
|
return true;
|
||||||
@@ -1584,24 +1577,31 @@ class ReceiveCommits {
|
|||||||
return ref.substring(0, split);
|
return ref.substring(0, split);
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyHandling getNotify() {
|
NotifyResolver.Result getNotifyForNewChange() {
|
||||||
if (notify != null) {
|
return getNotifyImpl(null);
|
||||||
return notify;
|
|
||||||
}
|
|
||||||
if (workInProgress) {
|
|
||||||
return NotifyHandling.OWNER;
|
|
||||||
}
|
|
||||||
return NotifyHandling.ALL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyHandling getNotify(ChangeNotes notes) {
|
NotifyResolver.Result getNotify(ChangeNotes notes) {
|
||||||
if (notify != null) {
|
return getNotifyImpl(requireNonNull(notes));
|
||||||
return notify;
|
}
|
||||||
|
|
||||||
|
private NotifyResolver.Result getNotifyImpl(@Nullable ChangeNotes notes) {
|
||||||
|
NotifyHandling notifyHandling = this.notifyHandling;
|
||||||
|
if (notifyHandling == null) {
|
||||||
|
if (workInProgress || (notes != null && !ready && notes.getChange().isWorkInProgress())) {
|
||||||
|
notifyHandling = NotifyHandling.OWNER;
|
||||||
|
} else {
|
||||||
|
notifyHandling = NotifyHandling.ALL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (workInProgress || (!ready && notes.getChange().isWorkInProgress())) {
|
|
||||||
return NotifyHandling.OWNER;
|
return NotifyResolver.Result.create(
|
||||||
}
|
notifyHandling,
|
||||||
return NotifyHandling.ALL;
|
ImmutableListMultimap.<RecipientType, Account.Id>builder()
|
||||||
|
.putAll(RecipientType.TO, notifyTo)
|
||||||
|
.putAll(RecipientType.CC, notifyCc)
|
||||||
|
.putAll(RecipientType.BCC, notifyBcc)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2446,8 +2446,7 @@ class ReceiveCommits {
|
|||||||
magicBranch.getCombinedCcs(fromFooters))
|
magicBranch.getCombinedCcs(fromFooters))
|
||||||
.setApprovals(approvals)
|
.setApprovals(approvals)
|
||||||
.setMessage(msg.toString())
|
.setMessage(msg.toString())
|
||||||
.setNotify(magicBranch.getNotify())
|
.setNotify(magicBranch.getNotifyForNewChange())
|
||||||
.setAccountsToNotify(magicBranch.getAccountsToNotify())
|
|
||||||
.setRequestScopePropagator(requestScopePropagator)
|
.setRequestScopePropagator(requestScopePropagator)
|
||||||
.setSendMail(true)
|
.setSendMail(true)
|
||||||
.setPatchSetDescription(magicBranch.message));
|
.setPatchSetDescription(magicBranch.message));
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import static org.eclipse.jgit.lib.Constants.R_HEADS;
|
|||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
|
||||||
import com.google.common.collect.Streams;
|
import com.google.common.collect.Streams;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
@@ -52,6 +51,7 @@ import com.google.gerrit.server.account.AccountResolver;
|
|||||||
import com.google.gerrit.server.change.AddReviewersOp;
|
import com.google.gerrit.server.change.AddReviewersOp;
|
||||||
import com.google.gerrit.server.change.ChangeKindCache;
|
import com.google.gerrit.server.change.ChangeKindCache;
|
||||||
import com.google.gerrit.server.change.EmailReviewComments;
|
import com.google.gerrit.server.change.EmailReviewComments;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.change.ReviewerAdder;
|
import com.google.gerrit.server.change.ReviewerAdder;
|
||||||
import com.google.gerrit.server.change.ReviewerAdder.InternalAddReviewerInput;
|
import com.google.gerrit.server.change.ReviewerAdder.InternalAddReviewerInput;
|
||||||
import com.google.gerrit.server.change.ReviewerAdder.ReviewerAddition;
|
import com.google.gerrit.server.change.ReviewerAdder.ReviewerAddition;
|
||||||
@@ -512,13 +512,12 @@ public class ReplaceOp implements BatchUpdateOp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyHandling notify = magicBranch != null ? magicBranch.getNotify(notes) : NotifyHandling.ALL;
|
NotifyResolver.Result notify =
|
||||||
|
magicBranch != null ? magicBranch.getNotify(notes) : NotifyResolver.Result.all();
|
||||||
if (shouldPublishComments()) {
|
if (shouldPublishComments()) {
|
||||||
emailCommentsFactory
|
emailCommentsFactory
|
||||||
.create(
|
.create(
|
||||||
notify,
|
notify,
|
||||||
magicBranch != null ? magicBranch.getAccountsToNotify() : ImmutableListMultimap.of(),
|
|
||||||
notes,
|
notes,
|
||||||
newPatchSet,
|
newPatchSet,
|
||||||
ctx.getUser().asIdentifiedUser(),
|
ctx.getUser().asIdentifiedUser(),
|
||||||
@@ -557,7 +556,6 @@ public class ReplaceOp implements BatchUpdateOp {
|
|||||||
cm.setChangeMessage(msg.getMessage(), ctx.getWhen());
|
cm.setChangeMessage(msg.getMessage(), ctx.getWhen());
|
||||||
if (magicBranch != null) {
|
if (magicBranch != null) {
|
||||||
cm.setNotify(magicBranch.getNotify(notes));
|
cm.setNotify(magicBranch.getNotify(notes));
|
||||||
cm.setAccountsToNotify(magicBranch.getAccountsToNotify());
|
|
||||||
}
|
}
|
||||||
cm.addReviewers(
|
cm.addReviewers(
|
||||||
Streams.concat(
|
Streams.concat(
|
||||||
|
|||||||
@@ -17,10 +17,8 @@ package com.google.gerrit.server.mail.receive;
|
|||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.client.Side;
|
import com.google.gerrit.extensions.client.Side;
|
||||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||||
import com.google.gerrit.extensions.registration.Extension;
|
import com.google.gerrit.extensions.registration.Extension;
|
||||||
@@ -47,6 +45,7 @@ import com.google.gerrit.server.account.AccountCache;
|
|||||||
import com.google.gerrit.server.account.AccountState;
|
import com.google.gerrit.server.account.AccountState;
|
||||||
import com.google.gerrit.server.account.Emails;
|
import com.google.gerrit.server.account.Emails;
|
||||||
import com.google.gerrit.server.change.EmailReviewComments;
|
import com.google.gerrit.server.change.EmailReviewComments;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.config.UrlFormatter;
|
import com.google.gerrit.server.config.UrlFormatter;
|
||||||
import com.google.gerrit.server.extensions.events.CommentAdded;
|
import com.google.gerrit.server.extensions.events.CommentAdded;
|
||||||
import com.google.gerrit.server.mail.MailFilter;
|
import com.google.gerrit.server.mail.MailFilter;
|
||||||
@@ -315,8 +314,7 @@ public class MailProcessor {
|
|||||||
// Send email notifications
|
// Send email notifications
|
||||||
outgoingMailFactory
|
outgoingMailFactory
|
||||||
.create(
|
.create(
|
||||||
NotifyHandling.ALL,
|
NotifyResolver.Result.all(),
|
||||||
ArrayListMultimap.create(),
|
|
||||||
notes,
|
notes,
|
||||||
patchSet,
|
patchSet,
|
||||||
ctx.getUser().asIdentifiedUser(),
|
ctx.getUser().asIdentifiedUser(),
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ public abstract class ChangeEmail extends NotificationEmail {
|
|||||||
setChangeUrlHeader();
|
setChangeUrlHeader();
|
||||||
setCommitIdHeader();
|
setCommitIdHeader();
|
||||||
|
|
||||||
if (notify.ordinal() >= NotifyHandling.OWNER_REVIEWERS.ordinal()) {
|
if (notify.handling().compareTo(NotifyHandling.OWNER_REVIEWERS) >= 0) {
|
||||||
try {
|
try {
|
||||||
addByEmail(
|
addByEmail(
|
||||||
RecipientType.CC, changeData.reviewersByEmail().byState(ReviewerStateInternal.CC));
|
RecipientType.CC, changeData.reviewersByEmail().byState(ReviewerStateInternal.CC));
|
||||||
@@ -320,7 +320,7 @@ public abstract class ChangeEmail extends NotificationEmail {
|
|||||||
|
|
||||||
/** BCC any user who has starred this change. */
|
/** BCC any user who has starred this change. */
|
||||||
protected void bccStarredBy() {
|
protected void bccStarredBy() {
|
||||||
if (!NotifyHandling.ALL.equals(notify)) {
|
if (!NotifyHandling.ALL.equals(notify.handling())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,7 +342,7 @@ public abstract class ChangeEmail extends NotificationEmail {
|
|||||||
@Override
|
@Override
|
||||||
protected final Watchers getWatchers(NotifyType type, boolean includeWatchersFromNotifyConfig)
|
protected final Watchers getWatchers(NotifyType type, boolean includeWatchersFromNotifyConfig)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
if (!NotifyHandling.ALL.equals(notify)) {
|
if (!NotifyHandling.ALL.equals(notify.handling())) {
|
||||||
return new Watchers();
|
return new Watchers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +352,8 @@ public abstract class ChangeEmail extends NotificationEmail {
|
|||||||
|
|
||||||
/** Any user who has published comments on this change. */
|
/** Any user who has published comments on this change. */
|
||||||
protected void ccAllApprovals() {
|
protected void ccAllApprovals() {
|
||||||
if (!NotifyHandling.ALL.equals(notify) && !NotifyHandling.OWNER_REVIEWERS.equals(notify)) {
|
if (!NotifyHandling.ALL.equals(notify.handling())
|
||||||
|
&& !NotifyHandling.OWNER_REVIEWERS.equals(notify.handling())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +368,8 @@ public abstract class ChangeEmail extends NotificationEmail {
|
|||||||
|
|
||||||
/** Users who have non-zero approval codes on the change. */
|
/** Users who have non-zero approval codes on the change. */
|
||||||
protected void ccExistingReviewers() {
|
protected void ccExistingReviewers() {
|
||||||
if (!NotifyHandling.ALL.equals(notify) && !NotifyHandling.OWNER_REVIEWERS.equals(notify)) {
|
if (!NotifyHandling.ALL.equals(notify.handling())
|
||||||
|
&& !NotifyHandling.OWNER_REVIEWERS.equals(notify.handling())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,7 +406,7 @@ public abstract class ChangeEmail extends NotificationEmail {
|
|||||||
protected Set<Account.Id> getAuthors() {
|
protected Set<Account.Id> getAuthors() {
|
||||||
Set<Account.Id> authors = new HashSet<>();
|
Set<Account.Id> authors = new HashSet<>();
|
||||||
|
|
||||||
switch (notify) {
|
switch (notify.handling()) {
|
||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
case ALL:
|
case ALL:
|
||||||
|
|||||||
@@ -153,10 +153,10 @@ public class CommentSender extends ReplyToChangeSender {
|
|||||||
protected void init() throws EmailException {
|
protected void init() throws EmailException {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
if (notify.compareTo(NotifyHandling.OWNER_REVIEWERS) >= 0) {
|
if (notify.handling().compareTo(NotifyHandling.OWNER_REVIEWERS) >= 0) {
|
||||||
ccAllApprovals();
|
ccAllApprovals();
|
||||||
}
|
}
|
||||||
if (notify.compareTo(NotifyHandling.ALL) >= 0) {
|
if (notify.handling().compareTo(NotifyHandling.ALL) >= 0) {
|
||||||
bccStarredBy();
|
bccStarredBy();
|
||||||
includeWatchers(NotifyType.ALL_COMMENTS, !change.isWorkInProgress() && !change.isPrivate());
|
includeWatchers(NotifyType.ALL_COMMENTS, !change.isWorkInProgress() && !change.isPrivate());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public abstract class NewChangeSender extends ChangeEmail {
|
|||||||
|
|
||||||
setHeader("Message-ID", getChangeMessageThreadId());
|
setHeader("Message-ID", getChangeMessageThreadId());
|
||||||
|
|
||||||
switch (notify) {
|
switch (notify.handling()) {
|
||||||
case NONE:
|
case NONE:
|
||||||
case OWNER:
|
case OWNER:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -18,11 +18,8 @@ import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailSt
|
|||||||
import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailStrategy.DISABLED;
|
import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailStrategy.DISABLED;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableListMultimap;
|
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
import com.google.gerrit.extensions.api.changes.RecipientType;
|
||||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailFormat;
|
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailFormat;
|
||||||
@@ -33,6 +30,7 @@ import com.google.gerrit.mail.MailHeader;
|
|||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.UserIdentity;
|
import com.google.gerrit.reviewdb.client.UserIdentity;
|
||||||
import com.google.gerrit.server.account.AccountState;
|
import com.google.gerrit.server.account.AccountState;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
import com.google.gerrit.server.validators.OutgoingEmailValidationListener;
|
import com.google.gerrit.server.validators.OutgoingEmailValidationListener;
|
||||||
import com.google.gerrit.server.validators.ValidationException;
|
import com.google.gerrit.server.validators.ValidationException;
|
||||||
@@ -65,13 +63,12 @@ public abstract class OutgoingEmail {
|
|||||||
private Address smtpFromAddress;
|
private Address smtpFromAddress;
|
||||||
private StringBuilder textBody;
|
private StringBuilder textBody;
|
||||||
private StringBuilder htmlBody;
|
private StringBuilder htmlBody;
|
||||||
private ListMultimap<RecipientType, Account.Id> accountsToNotify = ImmutableListMultimap.of();
|
|
||||||
protected Map<String, Object> soyContext;
|
protected Map<String, Object> soyContext;
|
||||||
protected Map<String, Object> soyContextEmailData;
|
protected Map<String, Object> soyContextEmailData;
|
||||||
protected List<String> footers;
|
protected List<String> footers;
|
||||||
protected final EmailArguments args;
|
protected final EmailArguments args;
|
||||||
protected Account.Id fromId;
|
protected Account.Id fromId;
|
||||||
protected NotifyHandling notify = NotifyHandling.ALL;
|
protected NotifyResolver.Result notify = NotifyResolver.Result.all();
|
||||||
|
|
||||||
protected OutgoingEmail(EmailArguments ea, String mc) {
|
protected OutgoingEmail(EmailArguments ea, String mc) {
|
||||||
args = ea;
|
args = ea;
|
||||||
@@ -83,21 +80,17 @@ public abstract class OutgoingEmail {
|
|||||||
fromId = id;
|
fromId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotify(NotifyHandling notify) {
|
public void setNotify(NotifyResolver.Result notify) {
|
||||||
this.notify = requireNonNull(notify);
|
this.notify = requireNonNull(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccountsToNotify(ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
|
||||||
this.accountsToNotify = requireNonNull(accountsToNotify);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format and enqueue the message for delivery.
|
* Format and enqueue the message for delivery.
|
||||||
*
|
*
|
||||||
* @throws EmailException
|
* @throws EmailException
|
||||||
*/
|
*/
|
||||||
public void send() throws EmailException {
|
public void send() throws EmailException {
|
||||||
if (NotifyHandling.NONE.equals(notify) && accountsToNotify.isEmpty()) {
|
if (!notify.shouldNotify()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +122,7 @@ public abstract class OutgoingEmail {
|
|||||||
// on their behalf to others.
|
// on their behalf to others.
|
||||||
//
|
//
|
||||||
add(RecipientType.CC, fromId);
|
add(RecipientType.CC, fromId);
|
||||||
} else if (!accountsToNotify.containsValue(fromId) && rcptTo.remove(fromId)) {
|
} else if (!notify.accounts().containsValue(fromId) && rcptTo.remove(fromId)) {
|
||||||
// If they don't want a copy, but we queued one up anyway,
|
// If they don't want a copy, but we queued one up anyway,
|
||||||
// drop them from the recipient lists.
|
// drop them from the recipient lists.
|
||||||
//
|
//
|
||||||
@@ -238,8 +231,8 @@ public abstract class OutgoingEmail {
|
|||||||
setHeader(FieldName.MESSAGE_ID, "");
|
setHeader(FieldName.MESSAGE_ID, "");
|
||||||
setHeader(MailHeader.AUTO_SUBMITTED.fieldName(), "auto-generated");
|
setHeader(MailHeader.AUTO_SUBMITTED.fieldName(), "auto-generated");
|
||||||
|
|
||||||
for (RecipientType recipientType : accountsToNotify.keySet()) {
|
for (RecipientType recipientType : notify.accounts().keySet()) {
|
||||||
add(recipientType, accountsToNotify.get(recipientType));
|
add(recipientType, notify.accounts().get(recipientType));
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeader(MailHeader.MESSAGE_TYPE.fieldName(), messageClass);
|
setHeader(MailHeader.MESSAGE_TYPE.fieldName(), messageClass);
|
||||||
@@ -412,7 +405,7 @@ public abstract class OutgoingEmail {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((accountsToNotify == null || accountsToNotify.isEmpty())
|
if (notify.accounts().isEmpty()
|
||||||
&& smtpRcptTo.size() == 1
|
&& smtpRcptTo.size() == 1
|
||||||
&& rcptTo.size() == 1
|
&& rcptTo.size() == 1
|
||||||
&& rcptTo.contains(fromId)) {
|
&& rcptTo.contains(fromId)) {
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
|
|||||||
//
|
//
|
||||||
reviewers.remove(fromId);
|
reviewers.remove(fromId);
|
||||||
}
|
}
|
||||||
if (notify == NotifyHandling.ALL || notify == NotifyHandling.OWNER_REVIEWERS) {
|
if (notify.handling() == NotifyHandling.ALL
|
||||||
|
|| notify.handling() == NotifyHandling.OWNER_REVIEWERS) {
|
||||||
add(RecipientType.TO, reviewers);
|
add(RecipientType.TO, reviewers);
|
||||||
add(RecipientType.CC, extraCC);
|
add(RecipientType.CC, extraCC);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -330,8 +330,7 @@ public class CherryPickChange {
|
|||||||
NotifyResolver.Result notify = resolveNotify(input);
|
NotifyResolver.Result notify = resolveNotify(input);
|
||||||
inserter
|
inserter
|
||||||
.setMessage("Uploaded patch set " + inserter.getPatchSetId().get() + ".")
|
.setMessage("Uploaded patch set " + inserter.getPatchSetId().get() + ".")
|
||||||
.setNotify(notify.handling())
|
.setNotify(notify);
|
||||||
.setAccountsToNotify(notify.accounts());
|
|
||||||
bu.addOp(destChange.getId(), inserter);
|
bu.addOp(destChange.getId(), inserter);
|
||||||
return destChange.getId();
|
return destChange.getId();
|
||||||
}
|
}
|
||||||
@@ -356,8 +355,7 @@ public class CherryPickChange {
|
|||||||
.setWorkInProgress(
|
.setWorkInProgress(
|
||||||
(sourceChange != null && sourceChange.isWorkInProgress())
|
(sourceChange != null && sourceChange.isWorkInProgress())
|
||||||
|| !cherryPickCommit.getFilesWithGitConflicts().isEmpty())
|
|| !cherryPickCommit.getFilesWithGitConflicts().isEmpty())
|
||||||
.setNotify(notify.handling())
|
.setNotify(notify);
|
||||||
.setAccountsToNotify(notify.accounts());
|
|
||||||
if (input.keepReviewers && sourceChange != null) {
|
if (input.keepReviewers && sourceChange != null) {
|
||||||
ReviewerSet reviewerSet =
|
ReviewerSet reviewerSet =
|
||||||
approvalsUtil.getReviewers(changeNotesFactory.createChecked(sourceChange));
|
approvalsUtil.getReviewers(changeNotesFactory.createChecked(sourceChange));
|
||||||
|
|||||||
@@ -308,8 +308,7 @@ public class CreateChange
|
|||||||
NotifyResolver.Result notify =
|
NotifyResolver.Result notify =
|
||||||
notifyResolver.resolve(
|
notifyResolver.resolve(
|
||||||
firstNonNull(input.notify, NotifyHandling.ALL), input.notifyDetails);
|
firstNonNull(input.notify, NotifyHandling.ALL), input.notifyDetails);
|
||||||
ins.setNotify(notify.handling());
|
ins.setNotify(notify);
|
||||||
ins.setAccountsToNotify(notify.accounts());
|
|
||||||
try (BatchUpdate bu = updateFactory.create(projectState.getNameKey(), me, now)) {
|
try (BatchUpdate bu = updateFactory.create(projectState.getNameKey(), me, now)) {
|
||||||
bu.setRepository(git, rw, oi);
|
bu.setRepository(git, rw, oi);
|
||||||
bu.insertChange(ins);
|
bu.insertChange(ins);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package com.google.gerrit.server.restapi.change;
|
|||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.client.ListChangesOption;
|
import com.google.gerrit.extensions.client.ListChangesOption;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.MergeInput;
|
import com.google.gerrit.extensions.common.MergeInput;
|
||||||
@@ -41,6 +40,7 @@ import com.google.gerrit.server.PatchSetUtil;
|
|||||||
import com.google.gerrit.server.change.ChangeFinder;
|
import com.google.gerrit.server.change.ChangeFinder;
|
||||||
import com.google.gerrit.server.change.ChangeJson;
|
import com.google.gerrit.server.change.ChangeJson;
|
||||||
import com.google.gerrit.server.change.ChangeResource;
|
import com.google.gerrit.server.change.ChangeResource;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.change.PatchSetInserter;
|
import com.google.gerrit.server.change.PatchSetInserter;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.git.MergeUtil;
|
import com.google.gerrit.server.git.MergeUtil;
|
||||||
@@ -185,9 +185,8 @@ public class CreateMergePatchSet
|
|||||||
bu.setRepository(git, rw, oi);
|
bu.setRepository(git, rw, oi);
|
||||||
psInserter
|
psInserter
|
||||||
.setMessage("Uploaded patch set " + nextPsId.get() + ".")
|
.setMessage("Uploaded patch set " + nextPsId.get() + ".")
|
||||||
.setNotify(NotifyHandling.NONE)
|
.setNotify(NotifyResolver.Result.none())
|
||||||
.setCheckAddPatchSetPermission(false)
|
.setCheckAddPatchSetPermission(false);
|
||||||
.setNotify(NotifyHandling.NONE);
|
|
||||||
if (groups != null) {
|
if (groups != null) {
|
||||||
psInserter.setGroups(groups);
|
psInserter.setGroups(groups);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,8 +100,7 @@ public class DeleteReviewerByEmailOp implements BatchUpdateOp {
|
|||||||
cm.setFrom(ctx.getAccountId());
|
cm.setFrom(ctx.getAccountId());
|
||||||
cm.addReviewersByEmail(Collections.singleton(reviewer));
|
cm.addReviewersByEmail(Collections.singleton(reviewer));
|
||||||
cm.setChangeMessage(changeMessage.getMessage(), changeMessage.getWrittenOn());
|
cm.setChangeMessage(changeMessage.getMessage(), changeMessage.getWrittenOn());
|
||||||
cm.setNotify(notify.handling());
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(notify.accounts());
|
|
||||||
cm.send();
|
cm.send();
|
||||||
} catch (Exception err) {
|
} catch (Exception err) {
|
||||||
logger.atSevere().withCause(err).log("Cannot email update for change %s", change.getId());
|
logger.atSevere().withCause(err).log("Cannot email update for change %s", change.getId());
|
||||||
|
|||||||
@@ -223,8 +223,7 @@ public class DeleteReviewerOp implements BatchUpdateOp {
|
|||||||
cm.setFrom(userId);
|
cm.setFrom(userId);
|
||||||
cm.addReviewers(Collections.singleton(reviewer.getAccount().getId()));
|
cm.addReviewers(Collections.singleton(reviewer.getAccount().getId()));
|
||||||
cm.setChangeMessage(changeMessage.getMessage(), changeMessage.getWrittenOn());
|
cm.setChangeMessage(changeMessage.getMessage(), changeMessage.getWrittenOn());
|
||||||
cm.setNotify(notify.handling());
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(notify.accounts());
|
|
||||||
cm.send();
|
cm.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,8 +226,7 @@ public class DeleteVote extends RetryingRestModifyView<VoteResource, DeleteVoteI
|
|||||||
ReplyToChangeSender cm = deleteVoteSenderFactory.create(ctx.getProject(), change.getId());
|
ReplyToChangeSender cm = deleteVoteSenderFactory.create(ctx.getProject(), change.getId());
|
||||||
cm.setFrom(user.getAccountId());
|
cm.setFrom(user.getAccountId());
|
||||||
cm.setChangeMessage(changeMessage.getMessage(), ctx.getWhen());
|
cm.setChangeMessage(changeMessage.getMessage(), ctx.getWhen());
|
||||||
cm.setNotify(notify.handling());
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(notify.accounts());
|
|
||||||
cm.send();
|
cm.send();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
|||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
@@ -42,7 +41,6 @@ import com.google.gerrit.common.data.LabelTypes;
|
|||||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||||
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
|
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
||||||
@@ -367,7 +365,7 @@ public class PostReview
|
|||||||
// Add the review op.
|
// Add the review op.
|
||||||
bu.addOp(
|
bu.addOp(
|
||||||
revision.getChange().getId(),
|
revision.getChange().getId(),
|
||||||
new Op(projectState, revision.getPatchSet().getId(), input, notify.accounts()));
|
new Op(projectState, revision.getPatchSet().getId(), input, notify));
|
||||||
|
|
||||||
bu.execute();
|
bu.execute();
|
||||||
|
|
||||||
@@ -830,7 +828,7 @@ public class PostReview
|
|||||||
private final ProjectState projectState;
|
private final ProjectState projectState;
|
||||||
private final PatchSet.Id psId;
|
private final PatchSet.Id psId;
|
||||||
private final ReviewInput in;
|
private final ReviewInput in;
|
||||||
private final ListMultimap<RecipientType, Account.Id> accountsToNotify;
|
private final NotifyResolver.Result notify;
|
||||||
|
|
||||||
private IdentifiedUser user;
|
private IdentifiedUser user;
|
||||||
private ChangeNotes notes;
|
private ChangeNotes notes;
|
||||||
@@ -842,14 +840,11 @@ public class PostReview
|
|||||||
private Map<String, Short> oldApprovals = new HashMap<>();
|
private Map<String, Short> oldApprovals = new HashMap<>();
|
||||||
|
|
||||||
private Op(
|
private Op(
|
||||||
ProjectState projectState,
|
ProjectState projectState, PatchSet.Id psId, ReviewInput in, NotifyResolver.Result notify) {
|
||||||
PatchSet.Id psId,
|
|
||||||
ReviewInput in,
|
|
||||||
ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
|
||||||
this.projectState = projectState;
|
this.projectState = projectState;
|
||||||
this.psId = psId;
|
this.psId = psId;
|
||||||
this.in = in;
|
this.in = in;
|
||||||
this.accountsToNotify = requireNonNull(accountsToNotify);
|
this.notify = requireNonNull(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -872,18 +867,9 @@ public class PostReview
|
|||||||
if (message == null) {
|
if (message == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (in.notify.compareTo(NotifyHandling.NONE) > 0 || !accountsToNotify.isEmpty()) {
|
if (notify.shouldNotify()) {
|
||||||
email
|
email
|
||||||
.create(
|
.create(notify, notes, ps, user, message, comments, in.message, labelDelta)
|
||||||
in.notify,
|
|
||||||
accountsToNotify,
|
|
||||||
notes,
|
|
||||||
ps,
|
|
||||||
user,
|
|
||||||
message,
|
|
||||||
comments,
|
|
||||||
in.message,
|
|
||||||
labelDelta)
|
|
||||||
.sendAsync();
|
.sendAsync();
|
||||||
}
|
}
|
||||||
commentAdded.fire(
|
commentAdded.fire(
|
||||||
|
|||||||
@@ -141,8 +141,7 @@ public class PutMessage
|
|||||||
String.format("Patch Set %s: Commit message was updated.", psId.getId()));
|
String.format("Patch Set %s: Commit message was updated.", psId.getId()));
|
||||||
inserter.setDescription("Edit commit message");
|
inserter.setDescription("Edit commit message");
|
||||||
NotifyResolver.Result notify = resolveNotify(input, resource);
|
NotifyResolver.Result notify = resolveNotify(input, resource);
|
||||||
inserter.setNotify(notify.handling());
|
inserter.setNotify(notify);
|
||||||
inserter.setAccountsToNotify(notify.accounts());
|
|
||||||
bu.addOp(resource.getChange().getId(), inserter);
|
bu.addOp(resource.getChange().getId(), inserter);
|
||||||
bu.execute();
|
bu.execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,8 @@ import static com.google.gerrit.extensions.conditions.BooleanCondition.and;
|
|||||||
import static com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE;
|
import static com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
|
||||||
import com.google.gerrit.extensions.api.changes.RevertInput;
|
import com.google.gerrit.extensions.api.changes.RevertInput;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
@@ -226,8 +224,7 @@ public class Revert extends RetryingRestModifyView<ChangeResource, RevertInput,
|
|||||||
.create(changeId, revertCommit, notes.getChange().getDest().get())
|
.create(changeId, revertCommit, notes.getChange().getDest().get())
|
||||||
.setTopic(changeToRevert.getTopic());
|
.setTopic(changeToRevert.getTopic());
|
||||||
ins.setMessage("Uploaded patch set 1.");
|
ins.setMessage("Uploaded patch set 1.");
|
||||||
ins.setNotify(notify.handling());
|
ins.setNotify(notify);
|
||||||
ins.setAccountsToNotify(notify.accounts());
|
|
||||||
|
|
||||||
ReviewerSet reviewerSet = approvalsUtil.getReviewers(notes);
|
ReviewerSet reviewerSet = approvalsUtil.getReviewers(notes);
|
||||||
|
|
||||||
@@ -243,7 +240,7 @@ public class Revert extends RetryingRestModifyView<ChangeResource, RevertInput,
|
|||||||
try (BatchUpdate bu = updateFactory.create(project, user, now)) {
|
try (BatchUpdate bu = updateFactory.create(project, user, now)) {
|
||||||
bu.setRepository(git, revWalk, oi);
|
bu.setRepository(git, revWalk, oi);
|
||||||
bu.insertChange(ins);
|
bu.insertChange(ins);
|
||||||
bu.addOp(changeId, new NotifyOp(changeToRevert, ins, notify.handling(), notify.accounts()));
|
bu.addOp(changeId, new NotifyOp(changeToRevert, ins, notify));
|
||||||
bu.addOp(changeToRevert.getId(), new PostRevertedMessageOp(computedChangeId));
|
bu.addOp(changeToRevert.getId(), new PostRevertedMessageOp(computedChangeId));
|
||||||
bu.execute();
|
bu.execute();
|
||||||
}
|
}
|
||||||
@@ -278,18 +275,12 @@ public class Revert extends RetryingRestModifyView<ChangeResource, RevertInput,
|
|||||||
private class NotifyOp implements BatchUpdateOp {
|
private class NotifyOp implements BatchUpdateOp {
|
||||||
private final Change change;
|
private final Change change;
|
||||||
private final ChangeInserter ins;
|
private final ChangeInserter ins;
|
||||||
private final NotifyHandling notifyHandling;
|
private final NotifyResolver.Result notify;
|
||||||
private final ListMultimap<RecipientType, Account.Id> accountsToNotify;
|
|
||||||
|
|
||||||
NotifyOp(
|
NotifyOp(Change change, ChangeInserter ins, NotifyResolver.Result notify) {
|
||||||
Change change,
|
|
||||||
ChangeInserter ins,
|
|
||||||
NotifyHandling notifyHandling,
|
|
||||||
ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
|
||||||
this.change = change;
|
this.change = change;
|
||||||
this.ins = ins;
|
this.ins = ins;
|
||||||
this.notifyHandling = notifyHandling;
|
this.notify = notify;
|
||||||
this.accountsToNotify = accountsToNotify;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -298,8 +289,7 @@ public class Revert extends RetryingRestModifyView<ChangeResource, RevertInput,
|
|||||||
try {
|
try {
|
||||||
RevertedSender cm = revertedSenderFactory.create(ctx.getProject(), change.getId());
|
RevertedSender cm = revertedSenderFactory.create(ctx.getProject(), change.getId());
|
||||||
cm.setFrom(ctx.getAccountId());
|
cm.setFrom(ctx.getAccountId());
|
||||||
cm.setNotify(notifyHandling);
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(accountsToNotify);
|
|
||||||
cm.send();
|
cm.send();
|
||||||
} catch (Exception err) {
|
} catch (Exception err) {
|
||||||
logger.atSevere().withCause(err).log(
|
logger.atSevere().withCause(err).log(
|
||||||
|
|||||||
@@ -14,16 +14,14 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.submit;
|
package com.google.gerrit.server.submit;
|
||||||
|
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.config.SendEmailExecutor;
|
import com.google.gerrit.server.config.SendEmailExecutor;
|
||||||
import com.google.gerrit.server.mail.send.MergedSender;
|
import com.google.gerrit.server.mail.send.MergedSender;
|
||||||
import com.google.gerrit.server.util.RequestContext;
|
import com.google.gerrit.server.util.RequestContext;
|
||||||
@@ -42,8 +40,7 @@ class EmailMerge implements Runnable, RequestContext {
|
|||||||
Project.NameKey project,
|
Project.NameKey project,
|
||||||
Change.Id changeId,
|
Change.Id changeId,
|
||||||
Account.Id submitter,
|
Account.Id submitter,
|
||||||
NotifyHandling notifyHandling,
|
NotifyResolver.Result notify);
|
||||||
ListMultimap<RecipientType, Account.Id> accountsToNotify);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ExecutorService sendEmailsExecutor;
|
private final ExecutorService sendEmailsExecutor;
|
||||||
@@ -54,8 +51,7 @@ class EmailMerge implements Runnable, RequestContext {
|
|||||||
private final Project.NameKey project;
|
private final Project.NameKey project;
|
||||||
private final Change.Id changeId;
|
private final Change.Id changeId;
|
||||||
private final Account.Id submitter;
|
private final Account.Id submitter;
|
||||||
private final NotifyHandling notifyHandling;
|
private final NotifyResolver.Result notify;
|
||||||
private final ListMultimap<RecipientType, Account.Id> accountsToNotify;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EmailMerge(
|
EmailMerge(
|
||||||
@@ -66,8 +62,7 @@ class EmailMerge implements Runnable, RequestContext {
|
|||||||
@Assisted Project.NameKey project,
|
@Assisted Project.NameKey project,
|
||||||
@Assisted Change.Id changeId,
|
@Assisted Change.Id changeId,
|
||||||
@Assisted @Nullable Account.Id submitter,
|
@Assisted @Nullable Account.Id submitter,
|
||||||
@Assisted NotifyHandling notifyHandling,
|
@Assisted NotifyResolver.Result notify) {
|
||||||
@Assisted ListMultimap<RecipientType, Account.Id> accountsToNotify) {
|
|
||||||
this.sendEmailsExecutor = executor;
|
this.sendEmailsExecutor = executor;
|
||||||
this.mergedSenderFactory = mergedSenderFactory;
|
this.mergedSenderFactory = mergedSenderFactory;
|
||||||
this.requestContext = requestContext;
|
this.requestContext = requestContext;
|
||||||
@@ -75,8 +70,7 @@ class EmailMerge implements Runnable, RequestContext {
|
|||||||
this.project = project;
|
this.project = project;
|
||||||
this.changeId = changeId;
|
this.changeId = changeId;
|
||||||
this.submitter = submitter;
|
this.submitter = submitter;
|
||||||
this.notifyHandling = notifyHandling;
|
this.notify = notify;
|
||||||
this.accountsToNotify = accountsToNotify;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendAsync() {
|
void sendAsync() {
|
||||||
@@ -92,8 +86,7 @@ class EmailMerge implements Runnable, RequestContext {
|
|||||||
if (submitter != null) {
|
if (submitter != null) {
|
||||||
cm.setFrom(submitter);
|
cm.setFrom(submitter);
|
||||||
}
|
}
|
||||||
cm.setNotify(notifyHandling);
|
cm.setNotify(notify);
|
||||||
cm.setAccountsToNotify(accountsToNotify);
|
|
||||||
cm.send();
|
cm.send();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.atSevere().withCause(e).log("Cannot email merged notification for %s", changeId);
|
logger.atSevere().withCause(e).log("Cannot email merged notification for %s", changeId);
|
||||||
|
|||||||
@@ -501,12 +501,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
|
|||||||
// have failed fast in one of the other steps.
|
// have failed fast in one of the other steps.
|
||||||
try {
|
try {
|
||||||
args.mergedSenderFactory
|
args.mergedSenderFactory
|
||||||
.create(
|
.create(ctx.getProject(), getId(), submitter.getAccountId(), args.notify)
|
||||||
ctx.getProject(),
|
|
||||||
getId(),
|
|
||||||
submitter.getAccountId(),
|
|
||||||
args.notify.handling(),
|
|
||||||
args.notify.accounts())
|
|
||||||
.sendAsync();
|
.sendAsync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.atSevere().withCause(e).log("Cannot email merged notification for %s", getId());
|
logger.atSevere().withCause(e).log("Cannot email merged notification for %s", getId());
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import com.google.gerrit.acceptance.TestAccount;
|
|||||||
import com.google.gerrit.common.FooterConstants;
|
import com.google.gerrit.common.FooterConstants;
|
||||||
import com.google.gerrit.common.Nullable;
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.extensions.api.changes.FixInput;
|
import com.google.gerrit.extensions.api.changes.FixInput;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.ProblemInfo;
|
import com.google.gerrit.extensions.common.ProblemInfo;
|
||||||
@@ -38,6 +37,7 @@ import com.google.gerrit.server.ChangeUtil;
|
|||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.change.ChangeInserter;
|
import com.google.gerrit.server.change.ChangeInserter;
|
||||||
import com.google.gerrit.server.change.ConsistencyChecker;
|
import com.google.gerrit.server.change.ConsistencyChecker;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.change.PatchSetInserter;
|
import com.google.gerrit.server.change.PatchSetInserter;
|
||||||
import com.google.gerrit.server.notedb.ChangeNoteUtil;
|
import com.google.gerrit.server.notedb.ChangeNoteUtil;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
@@ -753,7 +753,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||||||
changeInserterFactory
|
changeInserterFactory
|
||||||
.create(id, commit, dest)
|
.create(id, commit, dest)
|
||||||
.setValidate(false)
|
.setValidate(false)
|
||||||
.setNotify(NotifyHandling.NONE)
|
.setNotify(NotifyResolver.Result.none())
|
||||||
.setFireRevisionCreated(false)
|
.setFireRevisionCreated(false)
|
||||||
.setSendMail(false);
|
.setSendMail(false);
|
||||||
bu.insertChange(ins).execute();
|
bu.insertChange(ins).execute();
|
||||||
@@ -778,7 +778,7 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
|
|||||||
.create(notes, nextPatchSetId(notes), commit)
|
.create(notes, nextPatchSetId(notes), commit)
|
||||||
.setValidate(false)
|
.setValidate(false)
|
||||||
.setFireRevisionCreated(false)
|
.setFireRevisionCreated(false)
|
||||||
.setNotify(NotifyHandling.NONE);
|
.setNotify(NotifyResolver.Result.none());
|
||||||
bu.addOp(notes.getChangeId(), ins).execute();
|
bu.addOp(notes.getChangeId(), ins).execute();
|
||||||
}
|
}
|
||||||
return reload(notes);
|
return reload(notes);
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import com.google.gerrit.extensions.api.changes.ChangeApi;
|
|||||||
import com.google.gerrit.extensions.api.changes.Changes.QueryRequest;
|
import com.google.gerrit.extensions.api.changes.Changes.QueryRequest;
|
||||||
import com.google.gerrit.extensions.api.changes.DraftInput;
|
import com.google.gerrit.extensions.api.changes.DraftInput;
|
||||||
import com.google.gerrit.extensions.api.changes.HashtagsInput;
|
import com.google.gerrit.extensions.api.changes.HashtagsInput;
|
||||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
||||||
import com.google.gerrit.extensions.api.changes.StarsInput;
|
import com.google.gerrit.extensions.api.changes.StarsInput;
|
||||||
@@ -90,6 +89,7 @@ import com.google.gerrit.server.account.AuthRequest;
|
|||||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||||
import com.google.gerrit.server.change.ChangeInserter;
|
import com.google.gerrit.server.change.ChangeInserter;
|
||||||
import com.google.gerrit.server.change.ChangeTriplet;
|
import com.google.gerrit.server.change.ChangeTriplet;
|
||||||
|
import com.google.gerrit.server.change.NotifyResolver;
|
||||||
import com.google.gerrit.server.change.PatchSetInserter;
|
import com.google.gerrit.server.change.PatchSetInserter;
|
||||||
import com.google.gerrit.server.config.AllUsersName;
|
import com.google.gerrit.server.config.AllUsersName;
|
||||||
import com.google.gerrit.server.git.meta.MetaDataUpdate;
|
import com.google.gerrit.server.git.meta.MetaDataUpdate;
|
||||||
@@ -3176,7 +3176,7 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
|||||||
PatchSetInserter inserter =
|
PatchSetInserter inserter =
|
||||||
patchSetFactory
|
patchSetFactory
|
||||||
.create(changeNotesFactory.createChecked(c), new PatchSet.Id(c.getId(), n), commit)
|
.create(changeNotesFactory.createChecked(c), new PatchSet.Id(c.getId(), n), commit)
|
||||||
.setNotify(NotifyHandling.NONE)
|
.setNotify(NotifyResolver.Result.none())
|
||||||
.setFireRevisionCreated(false)
|
.setFireRevisionCreated(false)
|
||||||
.setValidate(false);
|
.setValidate(false);
|
||||||
try (BatchUpdate bu = updateFactory.create(c.getProject(), user, TimeUtil.nowTs());
|
try (BatchUpdate bu = updateFactory.create(c.getProject(), user, TimeUtil.nowTs());
|
||||||
|
|||||||
Reference in New Issue
Block a user