Skip to content
Permalink
Browse files

37: Make mailing list bridge ready check configurable

Reviewed-by: ehelin
  • Loading branch information
Robin Westberg
Robin Westberg committed Jul 2, 2019
1 parent dc54456 commit 81550df5ebd5e7221cc1b9a697dd96c68aa0d82b
@@ -551,10 +551,34 @@ public void run(Path scratchPath) {

// First determine if this PR should be inspected further or not
if (archiveMails.isEmpty()) {
// Wait until the PR is ready for review
if (!pr.getLabels().contains("rfr")) {
log.fine("PR is not yet ready for review");
return;
var labels = new HashSet<>(pr.getLabels());
for (var readyLabel : bot.readyLabels()) {
if (!labels.contains(readyLabel)) {
log.fine("PR is not yet ready - missing label '" + readyLabel + "'");
return;
}
}
}

// Also inspect comments before making the first post
var comments = pr.getComments();
if (archiveMails.isEmpty()) {
for (var readyComment : bot.readyComments().entrySet()) {
var commentFound = false;
for (var comment : comments) {
if (comment.author().userName().equals(readyComment.getKey())) {
var matcher = readyComment.getValue().matcher(comment.body());
if (matcher.find()) {
commentFound = true;
break;
}
}
}
if (!commentFound) {
log.fine("PR is not yet ready - missing ready comment from '" + readyComment.getKey() +
"containing '" + readyComment.getValue().pattern() + "'");
return;
}
}
}

@@ -564,7 +588,6 @@ public void run(Path scratchPath) {
var newMails = new ArrayList<Email>();
var stableIdToMail = archiveMails.stream().collect(Collectors.toMap(email -> getStableMessageId(email.id()),
Function.identity()));
var comments = pr.getComments();
var prInstance = new PullRequestInstance(scratchPath.resolve("mlbridge-mergebase"), pr);

// First post
@@ -30,6 +30,7 @@
import java.net.URI;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class MailingListBridgeBot implements Bot {
@@ -41,28 +42,28 @@
private final URI listArchive;
private final String smtpServer;
private final WebrevStorage webrevStorage;
private final Set<String> readyLabels;
private final Map<String, Pattern> readyComments;

MailingListBridgeBot(EmailAddress from, HostedRepository repo, HostedRepository archive, EmailAddress list,
Set<String> ignoredUsers, URI listArchive, String smtpServer,
HostedRepository webrevStorageRepository, String webrevStorageRef,
Path webrevStorageBase, URI webrevStorageBaseUri) {
Path webrevStorageBase, URI webrevStorageBaseUri, Set<String> readyLabels,
Map<String, Pattern> readyComments) {
emailAddress = from;
codeRepo = repo;
archiveRepo = archive;
listAddress = list;
this.ignoredUsers = ignoredUsers;
this.listArchive = listArchive;
this.smtpServer = smtpServer;
this.readyLabels = readyLabels;
this.readyComments = readyComments;

this.webrevStorage = new WebrevStorage(webrevStorageRepository, webrevStorageRef, webrevStorageBase,
webrevStorageBaseUri, from);
}

JCheckConfiguration configuration() {
var confFile = codeRepo.getFileContents(".jcheck/conf", "master");
return JCheckConfiguration.parse(confFile.lines().collect(Collectors.toList()));
}

HostedRepository codeRepo() {
return codeRepo;
}
@@ -95,6 +96,14 @@ WebrevStorage webrevStorage() {
return webrevStorage;
}

Set<String> readyLabels() {
return readyLabels;
}

Map<String, Pattern> readyComments() {
return readyComments;
}

@Override
public List<WorkItem> getPeriodicItems() {
List<WorkItem> ret = new LinkedList<>();
@@ -26,11 +26,12 @@
import org.openjdk.skara.email.EmailAddress;
import org.openjdk.skara.host.HostedRepository;
import org.openjdk.skara.host.network.URIBuilder;
import org.openjdk.skara.json.JSONValue;
import org.openjdk.skara.json.*;
import org.openjdk.skara.mailinglist.MailingListServerFactory;

import java.nio.file.Path;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class MailingListBridgeBotFactory implements BotFactory {
@@ -58,14 +59,22 @@ public String name() {
var allListNames = new HashSet<EmailAddress>();
var allRepositories = new HashSet<HostedRepository>();

var readyLabels = specific.get("ready").get("labels").stream()
.map(JSONValue::asString)
.collect(Collectors.toSet());
var readyComments = specific.get("ready").get("comments").stream()
.map(JSONValue::asObject)
.collect(Collectors.toMap(obj -> obj.get("user").asString(),
obj -> Pattern.compile(obj.get("pattern").asString())));

for (var repoConfig : specific.get("repositories").asArray()) {
var repo = repoConfig.get("repository").asString();
var archive = repoConfig.get("archive").asString();
var list = EmailAddress.parse(repoConfig.get("list").asString());
var bot = new MailingListBridgeBot(from, configuration.repository(repo), configuration.repository(archive),
list, ignoredUsers, listArchive, listSmtp,
configuration.repository(webrevRepo), webrevRef, Path.of(repo),
URIBuilder.base(webrevWeb).build());
URIBuilder.base(webrevWeb).build(), readyLabels, readyComments);
ret.add(bot);

allListNames.add(list);
@@ -68,7 +68,8 @@ void simpleArchive(TestInfo testInfo) throws IOException {
Set.of(ignored.host().getCurrentUserDetails().userName()),
listServer.getArchive(), listServer.getSMTP(),
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build());
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of());

// The mailing list as well
var mailmanServer = MailingListServerFactory.createMailmanServer(listServer.getArchive(), listServer.getSMTP());
@@ -87,7 +88,6 @@ void simpleArchive(TestInfo testInfo) throws IOException {
localRepo.push(editHash, author.getUrl(), "edit", true);
var pr = credentials.createPullRequest(archive, "master", "edit", "This is a pull request");
pr.setBody("This should now be ready");
pr.addLabel("rfr");

// Run an archive pass
TestBotRunner.runPeriodicItems(mlBot);
@@ -129,7 +129,8 @@ void rememberBridged(TestInfo testInfo) throws IOException {
Set.of(ignored.host().getCurrentUserDetails().userName()),
listServer.getArchive(), listServer.getSMTP(),
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build());
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of());

// The mailing list as well
var mailmanServer = MailingListServerFactory.createMailmanServer(listServer.getArchive(), listServer.getSMTP());
@@ -148,7 +149,6 @@ void rememberBridged(TestInfo testInfo) throws IOException {
localRepo.push(editHash, author.getUrl(), "edit", true);
var pr = credentials.createPullRequest(archive, "master", "edit", "This is a pull request");
pr.setBody("This should now be ready");
pr.addLabel("rfr");

// Run an archive pass
TestBotRunner.runPeriodicItems(mlBot);

0 comments on commit 81550df

Please sign in to comment.
You can’t perform that action at this time.