Skip to content
Snippets Groups Projects

feat: adding email notification when certian revalidation threshold is met

Merged Jordi Gómez requested to merge gnugomez/main/149 into main
Files
6
 
/**
 
* Copyright (c) 2025 Eclipse Foundation
 
*
 
* This program and the accompanying materials are made available under the terms of the Eclipse
 
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/
 
*
 
* Author: Jordi Gómez <jordi.gomez@eclipse-foundation.org>
 
*
 
* SPDX-License-Identifier: EPL-2.0
 
*/
 
package org.eclipsefoundation.git.eca.service.impl;
 
 
import org.eclipsefoundation.git.eca.config.MailerConfig;
 
import org.eclipsefoundation.git.eca.dto.GithubWebhookTracking;
 
import org.eclipsefoundation.git.eca.service.MailerService;
 
import org.slf4j.Logger;
 
import org.slf4j.LoggerFactory;
 
 
import io.quarkus.mailer.Mail;
 
import io.quarkus.mailer.Mailer;
 
import io.quarkus.qute.Location;
 
import io.quarkus.qute.Template;
 
import jakarta.enterprise.context.ApplicationScoped;
 
 
@ApplicationScoped
 
public class DefaultMailerService implements MailerService {
 
public static final Logger LOGGER = LoggerFactory.getLogger(DefaultMailerService.class);
 
private final MailerConfig config;
 
private final Mailer mailer;
 
 
@Location("emails/revalidation_alert")
 
Template revalidationAlertTemplate;
 
 
public DefaultMailerService(MailerConfig config, Mailer mailer) {
 
this.config = config;
 
this.mailer = mailer;
 
}
 
 
@Override
 
public void sendRevalidationAlert(GithubWebhookTracking tracking, Integer threshold) {
 
var revalidationAlertConfig = config.revalidationAlert();
 
 
if (revalidationAlertConfig.to().isEmpty()) {
 
LOGGER.warn("No recipients configured for revalidation alert. Skipping email notification.");
 
return;
 
}
 
 
String subject = "GitHub Webhook Revalidation Alert";
 
 
Mail messageBuilder = new Mail();
 
 
messageBuilder.setSubject(subject);
 
messageBuilder.setText(revalidationAlertTemplate.data("attempts", threshold)
 
.data("requestId", tracking.getId()).data("repository", tracking.getRepositoryFullName())
 
.data("pullRequest", tracking.getPullRequestNumber())
 
.data("lastState", tracking.getLastKnownState())
 
.data("lastUpdated", tracking.getLastUpdated().toString()).render());
 
 
messageBuilder.addTo(revalidationAlertConfig.to().toArray(String[]::new));
 
revalidationAlertConfig.authorMessage().replyTo().ifPresent(messageBuilder::addReplyTo);
 
revalidationAlertConfig.authorMessage().bcc()
 
.ifPresent(bcc -> messageBuilder.addBcc(bcc.toArray(String[]::new)));
 
 
mailer.send(messageBuilder);
 
LOGGER.info("Revalidation alert sent to: {}", revalidationAlertConfig.to());
 
}
 
 
}
Loading