Send mail only when there are recipients
@@ -453,7 +453,6 @@ public class InternalStepRunner implements StepRunner {
private void sendNotification(Run run, DualLogger logger) {
Application application = controller.applications().require(run.id().application());
Notifications notifications = application.deploymentSpec().notifications();
- if (notifications != Notifications.none()) {
boolean newCommit = application.change().application()
.map(run.versions().targetApplication()::equals)
.orElse(false);
@@ -463,6 +462,9 @@ public class InternalStepRunner implements StepRunner {
if (notifications.emailRolesFor(when).contains(author))
run.versions().targetApplication().authorEmail().ifPresent(recipients::add);
+ if (recipients.isEmpty())
+ return;
+
try {
if (run.status() == outOfCapacity && run.id().type().isProduction())
controller.mailer().send(mails.outOfCapacity(run.id(), recipients));
@@ -479,7 +481,6 @@ public class InternalStepRunner implements StepRunner {
logger.log(INFO, "Exception trying to send mail for " + run.id(), e);
}
}
- }
/** Returns the deployment of the real application in the zone of the given job, if it exists. */
private Optional<Deployment> deployment(ApplicationId id, JobType type) {
