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