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 boolean copyLabels;
|
||||||
private SshInfo sshInfo;
|
private SshInfo sshInfo;
|
||||||
private boolean draft;
|
private boolean draft;
|
||||||
|
private boolean runHooks;
|
||||||
|
private boolean sendMail;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PatchSetInserter(ChangeHooks hooks,
|
public PatchSetInserter(ChangeHooks hooks,
|
||||||
@@ -124,6 +126,8 @@ public class PatchSetInserter {
|
|||||||
this.refControl = refControl;
|
this.refControl = refControl;
|
||||||
this.change = change;
|
this.change = change;
|
||||||
this.commit = commit;
|
this.commit = commit;
|
||||||
|
this.runHooks = true;
|
||||||
|
this.sendMail = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PatchSetInserter setPatchSet(PatchSet patchSet) {
|
public PatchSetInserter setPatchSet(PatchSet patchSet) {
|
||||||
@@ -169,6 +173,16 @@ public class PatchSetInserter {
|
|||||||
return this;
|
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,
|
public Change insert() throws InvalidChangeOperationException, OrmException,
|
||||||
IOException {
|
IOException {
|
||||||
init();
|
init();
|
||||||
@@ -248,23 +262,27 @@ public class PatchSetInserter {
|
|||||||
db.changeMessages().insert(Collections.singleton(changeMessage));
|
db.changeMessages().insert(Collections.singleton(changeMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (sendMail) {
|
||||||
PatchSetInfo info = patchSetInfoFactory.get(commit, patchSet.getId());
|
try {
|
||||||
ReplacePatchSetSender cm =
|
PatchSetInfo info = patchSetInfoFactory.get(commit, patchSet.getId());
|
||||||
replacePatchSetFactory.create(updatedChange);
|
ReplacePatchSetSender cm =
|
||||||
cm.setFrom(user.getAccountId());
|
replacePatchSetFactory.create(updatedChange);
|
||||||
cm.setPatchSet(patchSet, info);
|
cm.setFrom(user.getAccountId());
|
||||||
cm.setChangeMessage(changeMessage);
|
cm.setPatchSet(patchSet, info);
|
||||||
cm.addReviewers(oldReviewers);
|
cm.setChangeMessage(changeMessage);
|
||||||
cm.addExtraCC(oldCC);
|
cm.addReviewers(oldReviewers);
|
||||||
cm.send();
|
cm.addExtraCC(oldCC);
|
||||||
} catch (Exception err) {
|
cm.send();
|
||||||
log.error("Cannot send email for new patch set on change " + updatedChange.getId(),
|
} catch (Exception err) {
|
||||||
err);
|
log.error("Cannot send email for new patch set on change " + updatedChange.getId(),
|
||||||
|
err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
indexer.index(updatedChange);
|
indexer.index(updatedChange);
|
||||||
hooks.doPatchsetCreatedHook(updatedChange, patchSet, db);
|
if (runHooks) {
|
||||||
|
hooks.doPatchsetCreatedHook(updatedChange, patchSet, db);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
db.rollback();
|
db.rollback();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user