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
2 unresolved threads
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 java.util.List;
 
import java.util.Optional;
 
 
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 io.smallrye.config.ConfigMapping;
 
import jakarta.enterprise.context.ApplicationScoped;
 
 
@ApplicationScoped
 
public class DefaultMailerService implements MailerService {
 
public static final Logger LOGGER = LoggerFactory.getLogger(DefaultMailerService.class);
 
private final EclipseMailerConfig config;
 
private final Mailer mailer;
 
 
@Location("emails/revalidation-alert")
 
Template revalidationAlertTemplate;
 
 
public DefaultMailerService(EclipseMailerConfig 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());
 
}
 
 
/**
 
* Represents configuration for the default mailer service.
 
*
 
* @author Martin Lowe
 
*
 
*/
 
@ConfigMapping(prefix = "eclipse.mailer")
 
public interface EclipseMailerConfig {
 
 
public RevalidationAlert revalidationAlert();
 
 
/**
 
* This interface defines the contract for specifying recipients and message
 
* configuration when sending revalidation alerts within the ECA validation
 
* process.
 
*/
 
public interface RevalidationAlert {
 
public List<String> to();
 
 
public MessageConfiguration authorMessage();
 
}
 
 
public interface MessageConfiguration {
 
public Optional<String> replyTo();
 
 
public Optional<List<String>> bcc();
 
}
 
}
 
 
}
Loading