Skip to content

Commit

Permalink
🎨 include the GH login in the from address
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Jul 20, 2024
1 parent 9b47a8f commit a8276a3
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.commonhaus.automation.github.context.EventPayload;
import org.commonhaus.automation.mail.MailEvent;
import org.commonhaus.automation.markdown.MarkdownConverter;
import org.eclipse.microprofile.config.ConfigProvider;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -24,6 +25,8 @@

@JsonDeserialize(as = EmailAction.class)
public class EmailAction extends Action {
static String fromAddress = null;

@CheckedTemplate
static class Templates {
public static native MailTemplateInstance commentEvent(String title, String htmlBody,
Expand Down Expand Up @@ -58,6 +61,8 @@ public void apply(EventQueryContext qc) {
eventData.getLogId(), List.of(addresses));

final String title;
final String sender;

String status = qc.getStatus();
if ("created".equals(status)) {
status = "";
Expand All @@ -74,6 +79,7 @@ public void apply(EventQueryContext qc) {
? payload.pullRequest
: payload.issue;

sender = item.author.login;
title = String.format("%s[%s] #%s %s",
status,
eventData.getRepoSlug(),
Expand All @@ -91,6 +97,7 @@ public void apply(EventQueryContext qc) {
: payload.issue;
DataCommonComment comment = payload.comment;

sender = comment.author.login;
title = String.format("Re: [%s] #%s %s",
eventData.getRepoSlug(),
item.number, item.title);
Expand All @@ -105,6 +112,7 @@ public void apply(EventQueryContext qc) {
EventPayload.DiscussionPayload payload = eventData.getEventPayload();
DataDiscussion discussion = payload.discussion;

sender = discussion.author.login;
title = String.format("%s[%s] #%s %s",
status,
eventData.getRepoSlug(),
Expand All @@ -120,6 +128,7 @@ public void apply(EventQueryContext qc) {
DataDiscussion discussion = payload.discussion;
DataDiscussionComment comment = payload.comment;

sender = comment.author.login;
title = String.format("Re: [%s] #%s %s",
eventData.getRepoSlug(),
discussion.number, discussion.title);
Expand All @@ -133,6 +142,7 @@ public void apply(EventQueryContext qc) {
default -> {
Log.warnf("[%s] EmailAction.apply: unsupported event type", eventData.getLogId());
title = null;
sender = null;
yield null;
}
};
Expand All @@ -144,7 +154,12 @@ public void apply(EventQueryContext qc) {
String subject = title;

if (mailTemplateInstance != null) {
if (fromAddress == null) {
fromAddress = ConfigProvider.getConfig().getValue("quarkus.mailer.from", String.class);
}

Log.debugf("[%s] EmailAction.apply: Sending email to %s; %s", eventData.getLogId(), List.of(addresses), subject);
mailTemplateInstance.from(sender + " <" + fromAddress + ">");
MailEvent mailEvent = new MailEvent(eventData.getLogId(),
mailTemplateInstance, subject, addresses);
Arc.container().instance(EventBus.class).get().send(MailEvent.ADDRESS, mailEvent);
Expand Down

0 comments on commit a8276a3

Please sign in to comment.