Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ public Collection<WorkItem> run(Path scratchPath) {

var jsonWebrevPath = scratchPath.resolve("mlbridge-webrevs").resolve("json");
var htmlWebrevPath = scratchPath.resolve("mlbridge-webrevs").resolve("html");
var listServer = MailingListServerFactory.createMailmanServer(bot.listArchive(), bot.smtpServer(), bot.sendInterval());
var archiver = new ReviewArchive(pr, bot.emailAddress());
var lastDraftTime = pr.lastMarkedAsDraftTime().orElse(null);

Expand Down Expand Up @@ -449,7 +448,7 @@ public Collection<WorkItem> run(Path scratchPath) {
.headers(bot.headers())
.recipients(recipients)
.build();
listServer.post(filteredEmail);
bot.mailingListServer().post(filteredEmail);
}
// Mixing forge time and local time for the latency is not ideal, but the best
// we can do here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.stream.Collectors;

public class MailingListArchiveReaderBot implements Bot {
private final MailingListReader list;
private final MailingListReader mailingListReader;
private final HostedRepository repository;
private final Map<EmailAddress, String> parsedConversations = new HashMap<>();
private final Map<EmailAddress, PullRequest> resolvedPullRequests = new HashMap<>();
Expand All @@ -44,8 +44,8 @@ public class MailingListArchiveReaderBot implements Bot {
private static final Pattern PULL_REQUEST_LINK_PATTERN = Pattern.compile("^(?:PR: |Pull request:\\R)(.*?)$", Pattern.MULTILINE);
private final Logger log = Logger.getLogger("org.openjdk.skara.bots.mlbridge");

MailingListArchiveReaderBot(MailingListReader list, HostedRepository repository) {
this.list = list;
MailingListArchiveReaderBot(MailingListReader mailingListReader, HostedRepository repository) {
this.mailingListReader = mailingListReader;
this.repository = repository;
}

Expand Down Expand Up @@ -131,7 +131,7 @@ synchronized void inspect(Conversation conversation) {

@Override
public List<WorkItem> getPeriodicItems() {
var readerItems = new ArchiveReaderWorkItem(this, list);
var readerItems = new ArchiveReaderWorkItem(this, mailingListReader);
var ret = new ArrayList<WorkItem>();
ret.add(readerItems);

Expand All @@ -145,6 +145,10 @@ public List<WorkItem> getPeriodicItems() {
return ret;
}

public MailingListReader mailingListReader() {
return mailingListReader;
}

@Override
public String name() {
return MailingListBridgeBotFactory.NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.openjdk.skara.mailinglist.MailingListServer;

public class MailingListBridgeBot implements Bot {
private final EmailAddress emailAddress;
Expand All @@ -43,33 +44,31 @@ public class MailingListBridgeBot implements Bot {
private final List<MailingListConfiguration> lists;
private final Set<String> ignoredUsers;
private final Set<Pattern> ignoredComments;
private final URI listArchive;
private final String smtpServer;
private final WebrevStorage webrevStorage;
private final Set<String> readyLabels;
private final Map<String, Pattern> readyComments;
private final Map<String, String> headers;
private final URI issueTracker;
private final Duration sendInterval;
private final Duration cooldown;
private final boolean repoInSubject;
private final Pattern branchInSubject;
private final Path seedStorage;
private final PullRequestPoller poller;
private final MailingListServer mailingListServer;

private final Logger log = Logger.getLogger("org.openjdk.skara.bots.mlbridge");

private volatile boolean labelsUpdated = false;

MailingListBridgeBot(EmailAddress from, HostedRepository repo, HostedRepository archive, String archiveRef,
HostedRepository censusRepo, String censusRef, List<MailingListConfiguration> lists,
Set<String> ignoredUsers, Set<Pattern> ignoredComments, URI listArchive, String smtpServer,
Set<String> ignoredUsers, Set<Pattern> ignoredComments,
HostedRepository webrevStorageHTMLRepository, HostedRepository webrevStorageJSONRepository,
String webrevStorageRef, Path webrevStorageBase, URI webrevStorageBaseUri,
boolean webrevGenerateHTML, boolean webrevGenerateJSON, Set<String> readyLabels,
Map<String, Pattern> readyComments, URI issueTracker, Map<String, String> headers,
Duration sendInterval, Duration cooldown, boolean repoInSubject, Pattern branchInSubject,
Path seedStorage) {
Duration cooldown, boolean repoInSubject, Pattern branchInSubject,
Path seedStorage, MailingListServer mailingListServer) {
emailAddress = from;
codeRepo = repo;
archiveRepo = archive;
Expand All @@ -79,17 +78,15 @@ public class MailingListBridgeBot implements Bot {
this.lists = lists;
this.ignoredUsers = ignoredUsers;
this.ignoredComments = ignoredComments;
this.listArchive = listArchive;
this.smtpServer = smtpServer;
this.readyLabels = readyLabels;
this.readyComments = readyComments;
this.headers = headers;
this.issueTracker = issueTracker;
this.sendInterval = sendInterval;
this.cooldown = cooldown;
this.repoInSubject = repoInSubject;
this.branchInSubject = branchInSubject;
this.seedStorage = seedStorage;
this.mailingListServer = mailingListServer;

webrevStorage = new WebrevStorage(webrevStorageHTMLRepository, webrevStorageJSONRepository, webrevStorageRef,
webrevStorageBase, webrevStorageBaseUri, from,
Expand Down Expand Up @@ -129,10 +126,6 @@ List<MailingListConfiguration> lists() {
return lists;
}

Duration sendInterval() {
return sendInterval;
}

Duration cooldown() {
return cooldown;
}
Expand All @@ -145,14 +138,6 @@ Set<Pattern> ignoredComments() {
return ignoredComments;
}

URI listArchive() {
return listArchive;
}

String smtpServer() {
return smtpServer;
}

WebrevStorage webrevStorage() {
return webrevStorage;
}
Expand Down Expand Up @@ -193,6 +178,10 @@ public void setLabelsUpdated(boolean labelsUpdated) {
this.labelsUpdated = labelsUpdated;
}

public MailingListServer mailingListServer() {
return mailingListServer;
}

@Override
public List<WorkItem> getPeriodicItems() {
List<WorkItem> ret = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.openjdk.skara.bots.mlbridge;

import org.openjdk.skara.mailinglist.MailingListServer;
import org.openjdk.skara.vcs.Branch;
import org.openjdk.skara.vcs.VCS;
import org.openjdk.skara.email.EmailAddress;
Expand All @@ -43,8 +44,6 @@ public class MailingListBridgeBotBuilder {
private List<MailingListConfiguration> lists;
private Set<String> ignoredUsers = Set.of();
private Set<Pattern> ignoredComments = Set.of();
private URI listArchive;
private String smtpServer;
private HostedRepository webrevStorageHTMLRepository;
private HostedRepository webrevStorageJSONRepository;
private String webrevStorageRef;
Expand All @@ -56,11 +55,11 @@ public class MailingListBridgeBotBuilder {
private Map<String, Pattern> readyComments = Map.of();
private URI issueTracker;
private Map<String, String> headers = Map.of();
private Duration sendInterval = Duration.ZERO;
private Duration cooldown = Duration.ZERO;
private boolean repoInSubject = false;
private Pattern branchInSubject = Pattern.compile("a^"); // Does not match anything
private Path seedStorage = null;
private MailingListServer mailingListServer;

MailingListBridgeBotBuilder() {
}
Expand Down Expand Up @@ -110,16 +109,6 @@ public MailingListBridgeBotBuilder ignoredComments(Set<Pattern> ignoredComments)
return this;
}

public MailingListBridgeBotBuilder listArchive(URI listArchive) {
this.listArchive = listArchive;
return this;
}

public MailingListBridgeBotBuilder smtpServer(String smtpServer) {
this.smtpServer = smtpServer;
return this;
}

public MailingListBridgeBotBuilder webrevStorageHTMLRepository(HostedRepository webrevStorageHTMLRepository) {
this.webrevStorageHTMLRepository = webrevStorageHTMLRepository;
return this;
Expand Down Expand Up @@ -175,11 +164,6 @@ public MailingListBridgeBotBuilder headers(Map<String, String> headers) {
return this;
}

public MailingListBridgeBotBuilder sendInterval(Duration sendInterval) {
this.sendInterval = sendInterval;
return this;
}

public MailingListBridgeBotBuilder cooldown(Duration cooldown) {
this.cooldown = cooldown;
return this;
Expand All @@ -200,12 +184,17 @@ public MailingListBridgeBotBuilder seedStorage(Path seedStorage) {
return this;
}

public MailingListBridgeBotBuilder mailingListServer(MailingListServer mailingListServer) {
this.mailingListServer = mailingListServer;
return this;
}

public MailingListBridgeBot build() {
return new MailingListBridgeBot(from, repo, archive, archiveRef, censusRepo, censusRef, lists,
ignoredUsers, ignoredComments, listArchive, smtpServer,
ignoredUsers, ignoredComments,
webrevStorageHTMLRepository, webrevStorageJSONRepository, webrevStorageRef,
webrevStorageBase, webrevStorageBaseUri, webrevGenerateHTML, webrevGenerateJSON,
readyLabels, readyComments, issueTracker, headers, sendInterval,
cooldown, repoInSubject, branchInSubject, seedStorage);
readyLabels, readyComments, issueTracker, headers,
cooldown, repoInSubject, branchInSubject, seedStorage, mailingListServer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
*/
package org.openjdk.skara.bots.mlbridge;

import java.net.URI;
import org.openjdk.skara.bot.*;
import org.openjdk.skara.email.EmailAddress;
import org.openjdk.skara.mailinglist.MailingListReader;
import org.openjdk.skara.mailinglist.MailingListServer;
import org.openjdk.skara.network.URIBuilder;
import org.openjdk.skara.json.*;
import org.openjdk.skara.mailinglist.MailingListServerFactory;
Expand Down Expand Up @@ -77,8 +79,13 @@ public List<Bot> create(BotConfiguration configuration) {
.map(pattern -> Pattern.compile(pattern, Pattern.MULTILINE | Pattern.DOTALL))
.collect(Collectors.toSet());
var listArchive = URIBuilder.base(specific.get("server").get("archive").asString()).build();
String archiveType = null;
if (specific.get("server").contains("type")) {
archiveType = specific.get("server").get("type").asString();
}
var listSmtp = specific.get("server").get("smtp").asString();
var interval = specific.get("server").contains("interval") ? Duration.parse(specific.get("server").get("interval").asString()) : Duration.ofSeconds(1);
var interval = specific.get("server").contains("interval") ?
Duration.parse(specific.get("server").get("interval").asString()) : Duration.ofSeconds(1);

var webrevHTMLRepo = configuration.repository(specific.get("webrevs").get("repository").get("html").asString());
var webrevJSONRepo = configuration.repository(specific.get("webrevs").get("repository").get("json").asString());
Expand All @@ -101,7 +108,7 @@ public List<Bot> create(BotConfiguration configuration) {
if (specific.get("server").contains("etag")) {
useEtag = specific.get("server").get("etag").asBoolean();
}
var mailmanServer = MailingListServerFactory.createMailmanServer(listArchive, listSmtp, Duration.ZERO, useEtag);
MailingListServer mailmanServer = createMailmanServer(archiveType, listArchive, listSmtp, interval, useEtag);

var mailingListReaderMap = new HashMap<List<String>, MailingListReader>();

Expand Down Expand Up @@ -161,8 +168,6 @@ public List<Bot> create(BotConfiguration configuration) {
.lists(lists)
.ignoredUsers(ignoredUsers)
.ignoredComments(ignoredComments)
.listArchive(listArchive)
.smtpServer(listSmtp)
.webrevStorageHTMLRepository(webrevHTMLRepo)
.webrevStorageJSONRepository(webrevJSONRepo)
.webrevStorageRef(webrevRef)
Expand All @@ -174,9 +179,9 @@ public List<Bot> create(BotConfiguration configuration) {
.readyComments(readyComments)
.issueTracker(issueTracker)
.headers(headers)
.sendInterval(interval)
.cooldown(cooldown)
.seedStorage(configuration.storageFolder().resolve("seeds"));
.seedStorage(configuration.storageFolder().resolve("seeds"))
.mailingListServer(mailmanServer);

if (repoConfig.contains("reponame")) {
botBuilder.repoInSubject(repoConfig.get("reponame").asBoolean());
Expand All @@ -189,4 +194,17 @@ public List<Bot> create(BotConfiguration configuration) {

return ret;
}

private static MailingListServer createMailmanServer(String archiveType, URI listArchive, String listSmtp,
Duration sendInterval, boolean useEtag) {
MailingListServer mailmanServer;
if (archiveType == null || archiveType.equals("mailman2")) {
mailmanServer = MailingListServerFactory.createMailman2Server(listArchive, listSmtp, sendInterval, useEtag);
} else if (archiveType.equals("mailman3")) {
mailmanServer = MailingListServerFactory.createMailman3Server(listArchive, listSmtp, sendInterval);
} else {
throw new RuntimeException("Invalid server archive type: " + archiveType);
}
return mailmanServer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class LabelsUpdaterTests {
@Test
void simple(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var listServer = new TestMailmanServer();) {
var listServer = TestMailmanServer.createV2();) {
var targetRepo = credentials.getHostedRepository();
var listAddress = EmailAddress.parse(listServer.createList("test"));
var mlBot = MailingListBridgeBot.newBuilder()
Expand Down Expand Up @@ -70,7 +70,7 @@ void simple(TestInfo testInfo) throws IOException {
@Test
void update(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var listServer = new TestMailmanServer();) {
var listServer = TestMailmanServer.createV2();) {
var targetRepo = credentials.getHostedRepository();
var listAddress = EmailAddress.parse(listServer.createList("test"));
var listAddress2 = EmailAddress.parse(listServer.createList("test2"));
Expand Down
Loading