Merge "Add notify option to SubmitChange Rest API endpoint"
This commit is contained in:
@@ -4914,6 +4914,11 @@ format link:rest-api-accounts.html#account-id[accepted by the accounts REST
|
||||
API]. Using this option requires
|
||||
link:access-control.html#category_submit_on_behalf_of[Submit (On Behalf Of)]
|
||||
permission on the branch.
|
||||
|`notify`|optional|
|
||||
Notify handling that defines to whom email notifications should be sent after
|
||||
the change is submitted. +
|
||||
Allowed values are `NONE`, `OWNER`, `OWNER_REVIEWERS` and `ALL`. +
|
||||
If not set, the default is `ALL`.
|
||||
|===========================
|
||||
|
||||
[[submit-record]]
|
||||
|
@@ -14,10 +14,14 @@
|
||||
|
||||
package com.google.gerrit.extensions.api.changes;
|
||||
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
|
||||
|
||||
public class SubmitInput {
|
||||
/** Not used anymore, kept for backward compatibility */
|
||||
@Deprecated
|
||||
public boolean waitForMerge;
|
||||
|
||||
public String onBehalfOf;
|
||||
|
||||
public NotifyHandling notify = NotifyHandling.ALL;
|
||||
}
|
||||
|
@@ -121,6 +121,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
||||
|
||||
public TestSubmitInput(SubmitInput base, boolean failAfterRefUpdates) {
|
||||
this.onBehalfOf = base.onBehalfOf;
|
||||
this.notify = base.notify;
|
||||
this.failAfterRefUpdates = failAfterRefUpdates;
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@@ -42,7 +43,7 @@ public class EmailMerge implements Runnable, RequestContext {
|
||||
|
||||
public interface Factory {
|
||||
EmailMerge create(Project.NameKey project, Change.Id changeId,
|
||||
Account.Id submitter);
|
||||
Account.Id submitter, NotifyHandling notifyHandling);
|
||||
}
|
||||
|
||||
private final ExecutorService sendEmailsExecutor;
|
||||
@@ -54,6 +55,7 @@ public class EmailMerge implements Runnable, RequestContext {
|
||||
private final Project.NameKey project;
|
||||
private final Change.Id changeId;
|
||||
private final Account.Id submitter;
|
||||
private final NotifyHandling notifyHandling;
|
||||
private ReviewDb db;
|
||||
|
||||
@Inject
|
||||
@@ -64,7 +66,8 @@ public class EmailMerge implements Runnable, RequestContext {
|
||||
IdentifiedUser.GenericFactory identifiedUserFactory,
|
||||
@Assisted Project.NameKey project,
|
||||
@Assisted Change.Id changeId,
|
||||
@Assisted @Nullable Account.Id submitter) {
|
||||
@Assisted @Nullable Account.Id submitter,
|
||||
@Assisted NotifyHandling notifyHandling) {
|
||||
this.sendEmailsExecutor = executor;
|
||||
this.mergedSenderFactory = mergedSenderFactory;
|
||||
this.schemaFactory = schemaFactory;
|
||||
@@ -73,6 +76,7 @@ public class EmailMerge implements Runnable, RequestContext {
|
||||
this.project = project;
|
||||
this.changeId = changeId;
|
||||
this.submitter = submitter;
|
||||
this.notifyHandling = notifyHandling;
|
||||
}
|
||||
|
||||
public void sendAsync() {
|
||||
@@ -87,6 +91,7 @@ public class EmailMerge implements Runnable, RequestContext {
|
||||
if (submitter != null) {
|
||||
cm.setFrom(submitter);
|
||||
}
|
||||
cm.setNotify(notifyHandling);
|
||||
cm.send();
|
||||
} catch (Exception e) {
|
||||
log.error("Cannot email merged notification for " + changeId, e);
|
||||
|
@@ -676,7 +676,7 @@ public class MergeOp implements AutoCloseable {
|
||||
CodeReviewCommit branchTip) throws IntegrationException {
|
||||
return submitStrategyFactory.create(submitType, db, or.repo, or.rw, or.ins,
|
||||
or.canMergeFlag, getAlreadyAccepted(or, branchTip), destBranch, caller,
|
||||
mergeTip, commits, submissionId);
|
||||
mergeTip, commits, submissionId, submitInput.notify);
|
||||
}
|
||||
|
||||
private Set<RevCommit> getAlreadyAccepted(OpenRepo or,
|
||||
|
@@ -63,6 +63,7 @@ import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.extensions.api.changes.HashtagsInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
|
||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap.Entry;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
@@ -1814,7 +1815,7 @@ public class ReceiveCommits {
|
||||
RevisionResource rsrc = new RevisionResource(changes.parse(changeCtl), ps);
|
||||
try (MergeOp op = mergeOpProvider.get()) {
|
||||
op.merge(db, rsrc.getChange(),
|
||||
changeCtl.getUser().asIdentifiedUser(), false, null);
|
||||
changeCtl.getUser().asIdentifiedUser(), false, new SubmitInput());
|
||||
}
|
||||
addMessage("");
|
||||
Change c = notesFactory
|
||||
|
@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.ChangeHooks;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.extensions.config.FactoryModule;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
@@ -89,7 +90,8 @@ public abstract class SubmitStrategy {
|
||||
RevFlag canMergeFlag,
|
||||
ReviewDb db,
|
||||
Set<RevCommit> alreadyAccepted,
|
||||
String submissionId);
|
||||
String submissionId,
|
||||
NotifyHandling notifyHandling);
|
||||
}
|
||||
|
||||
final AccountCache accountCache;
|
||||
@@ -120,6 +122,7 @@ public abstract class SubmitStrategy {
|
||||
final Set<RevCommit> alreadyAccepted;
|
||||
final String submissionId;
|
||||
final SubmitType submitType;
|
||||
final NotifyHandling notifyHandling;
|
||||
|
||||
final ProjectState project;
|
||||
final MergeSorter mergeSorter;
|
||||
@@ -154,7 +157,8 @@ public abstract class SubmitStrategy {
|
||||
@Assisted ReviewDb db,
|
||||
@Assisted Set<RevCommit> alreadyAccepted,
|
||||
@Assisted String submissionId,
|
||||
@Assisted SubmitType submitType) {
|
||||
@Assisted SubmitType submitType,
|
||||
@Assisted NotifyHandling notifyHandling) {
|
||||
this.accountCache = accountCache;
|
||||
this.approvalsUtil = approvalsUtil;
|
||||
this.batchUpdateFactory = batchUpdateFactory;
|
||||
@@ -183,6 +187,7 @@ public abstract class SubmitStrategy {
|
||||
this.alreadyAccepted = alreadyAccepted;
|
||||
this.submissionId = submissionId;
|
||||
this.submitType = submitType;
|
||||
this.notifyHandling = notifyHandling;
|
||||
|
||||
this.project = checkNotNull(projectCache.get(destBranch.getParentKey()),
|
||||
"project not found: %s", destBranch.getParentKey());
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.git.strategy;
|
||||
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -51,11 +52,11 @@ public class SubmitStrategyFactory {
|
||||
Repository repo, CodeReviewRevWalk rw, ObjectInserter inserter,
|
||||
RevFlag canMergeFlag, Set<RevCommit> alreadyAccepted,
|
||||
Branch.NameKey destBranch, IdentifiedUser caller, MergeTip mergeTip,
|
||||
CommitStatus commits, String submissionId)
|
||||
CommitStatus commits, String submissionId, NotifyHandling notifyHandling)
|
||||
throws IntegrationException {
|
||||
SubmitStrategy.Arguments args = argsFactory.create(submitType, destBranch,
|
||||
commits, rw, caller, mergeTip, inserter, repo, canMergeFlag, db,
|
||||
alreadyAccepted, submissionId);
|
||||
alreadyAccepted, submissionId, notifyHandling);
|
||||
switch (submitType) {
|
||||
case CHERRY_PICK:
|
||||
return new CherryPick(args);
|
||||
|
@@ -518,7 +518,8 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
|
||||
// have failed fast in one of the other steps.
|
||||
try {
|
||||
args.mergedSenderFactory
|
||||
.create(ctx.getProject(), getId(), submitter.getAccountId())
|
||||
.create(ctx.getProject(), getId(), submitter.getAccountId(),
|
||||
args.notifyHandling)
|
||||
.sendAsync();
|
||||
} catch (Exception e) {
|
||||
log.error("Cannot email merged notification for " + getId(), e);
|
||||
|
Reference in New Issue
Block a user