in java/com/google/gerrit/plugins/checks/ChecksUpdate.java [183:243]
private void maybeSendEmail(
@Nullable NotifyHandling notifyHandling,
@Nullable Map<RecipientType, NotifyInfo> notifyDetails,
Check updatedCheck,
CombinedCheckState oldCombinedCheckState,
CombinedCheckState newCombinedCheckState)
throws BadRequestException, IOException, ConfigInvalidException {
if (oldCombinedCheckState == newCombinedCheckState) {
// do not send an email if the combined check state was not updated
return;
}
CheckKey checkKey = updatedCheck.key();
ChangeNotes changeNotes =
notesFactory.create(checkKey.repository(), checkKey.patchSet().changeId());
if (!checkKey.patchSet().equals(changeNotes.getCurrentPatchSet().id())) {
// do not send an email for non-current patch sets
return;
}
notifyHandling =
notifyHandling != null
? notifyHandling
: newCombinedCheckState == CombinedCheckState.SUCCESSFUL
|| newCombinedCheckState == CombinedCheckState.NOT_RELEVANT
? NotifyHandling.ALL
: NotifyHandling.OWNER;
NotifyResolver.Result notify = notifyResolver.resolve(notifyHandling, notifyDetails);
try {
CombinedCheckStateUpdatedSender sender =
combinedCheckStateUpdatedSenderFactory.create(
checkKey.repository(), checkKey.patchSet().changeId());
if (currentUser.isPresent()) {
sender.setFrom(currentUser.get().getAccountId());
}
PatchSet patchSet = psUtil.get(changeNotes, checkKey.patchSet());
sender.setPatchSet(patchSet);
sender.setCombinedCheckState(oldCombinedCheckState, newCombinedCheckState);
sender.setCheck(
checkers
.getChecker(checkKey.checkerUuid())
.orElseThrow(
() ->
new IllegalStateException(
String.format(
"checker %s of check %s not found",
checkKey.checkerUuid(), checkKey))),
updatedCheck);
sender.setNotify(notify);
sender.setChecksByChecker(getAllChecksByChecker(checkKey));
sender.setMessageId(
messageIdGenerator.fromChangeUpdate(checkKey.repository(), checkKey.patchSet()));
sender.send();
} catch (Exception e) {
logger.atSevere().withCause(e).log(
"Cannot email update for change %s", checkKey.patchSet().changeId());
}
}