Allow callers of PatchSetInserter to suppress emails and hooks
Add methods to allow callers of the PatchSetInserter class to prevent it from sending email notifications and executing hooks after creating a new patch set. Change-Id: I1a3e62ff74011d917dc8b029c941c0e78b62f25e
This commit is contained in:
@@ -93,6 +93,8 @@ public class PatchSetInserter {
|
||||
private boolean copyLabels;
|
||||
private SshInfo sshInfo;
|
||||
private boolean draft;
|
||||
private boolean runHooks;
|
||||
private boolean sendMail;
|
||||
|
||||
@Inject
|
||||
public PatchSetInserter(ChangeHooks hooks,
|
||||
@@ -124,6 +126,8 @@ public class PatchSetInserter {
|
||||
this.refControl = refControl;
|
||||
this.change = change;
|
||||
this.commit = commit;
|
||||
this.runHooks = true;
|
||||
this.sendMail = true;
|
||||
}
|
||||
|
||||
public PatchSetInserter setPatchSet(PatchSet patchSet) {
|
||||
@@ -169,6 +173,16 @@ public class PatchSetInserter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PatchSetInserter setRunHooks(boolean runHooks) {
|
||||
this.runHooks = runHooks;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PatchSetInserter setSendMail(boolean sendMail) {
|
||||
this.sendMail = sendMail;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Change insert() throws InvalidChangeOperationException, OrmException,
|
||||
IOException {
|
||||
init();
|
||||
@@ -248,23 +262,27 @@ public class PatchSetInserter {
|
||||
db.changeMessages().insert(Collections.singleton(changeMessage));
|
||||
}
|
||||
|
||||
try {
|
||||
PatchSetInfo info = patchSetInfoFactory.get(commit, patchSet.getId());
|
||||
ReplacePatchSetSender cm =
|
||||
replacePatchSetFactory.create(updatedChange);
|
||||
cm.setFrom(user.getAccountId());
|
||||
cm.setPatchSet(patchSet, info);
|
||||
cm.setChangeMessage(changeMessage);
|
||||
cm.addReviewers(oldReviewers);
|
||||
cm.addExtraCC(oldCC);
|
||||
cm.send();
|
||||
} catch (Exception err) {
|
||||
log.error("Cannot send email for new patch set on change " + updatedChange.getId(),
|
||||
err);
|
||||
if (sendMail) {
|
||||
try {
|
||||
PatchSetInfo info = patchSetInfoFactory.get(commit, patchSet.getId());
|
||||
ReplacePatchSetSender cm =
|
||||
replacePatchSetFactory.create(updatedChange);
|
||||
cm.setFrom(user.getAccountId());
|
||||
cm.setPatchSet(patchSet, info);
|
||||
cm.setChangeMessage(changeMessage);
|
||||
cm.addReviewers(oldReviewers);
|
||||
cm.addExtraCC(oldCC);
|
||||
cm.send();
|
||||
} catch (Exception err) {
|
||||
log.error("Cannot send email for new patch set on change " + updatedChange.getId(),
|
||||
err);
|
||||
}
|
||||
}
|
||||
|
||||
indexer.index(updatedChange);
|
||||
hooks.doPatchsetCreatedHook(updatedChange, patchSet, db);
|
||||
if (runHooks) {
|
||||
hooks.doPatchsetCreatedHook(updatedChange, patchSet, db);
|
||||
}
|
||||
} finally {
|
||||
db.rollback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user