Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait with resolving PR until needed when bridging mails #500

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -37,7 +37,8 @@ public class MailingListArchiveReaderBot implements Bot {
private final EmailAddress archivePoster;
private final Set<MailingList> lists;
private final Set<HostedRepository> repositories;
private final Map<EmailAddress, PullRequest> parsedConversations = new HashMap<>();
private final Map<EmailAddress, String> parsedConversations = new HashMap<>();
private final Map<EmailAddress, PullRequest> resolvedPullRequests = new HashMap<>();
private final Set<EmailAddress> parsedEmailIds = new HashSet<>();
private final Queue<CommentPosterWorkItem> commentQueue = new ConcurrentLinkedQueue<>();
private final Pattern pullRequestLinkPattern = Pattern.compile("^(?:PR: |Pull request:\\R)(.*?)$", Pattern.MULTILINE);
@@ -55,9 +56,8 @@ private synchronized void invalidate(List<Email> messages) {

synchronized void inspect(Conversation conversation) {
// Is this a new conversation?
if (!parsedConversations.containsKey(conversation.first().id())) {
var first = conversation.first();

var first = conversation.first();
if (!parsedConversations.containsKey(first.id())) {
// This conversation has already been parsed without finding any matching PR
if (parsedEmailIds.contains(first.id())) {
return;
@@ -66,7 +66,7 @@ synchronized void inspect(Conversation conversation) {
parsedEmailIds.add(first.id());

// Not an RFR - cannot match a PR
if (!conversation.first().subject().contains("RFR: ")) {
if (!first.subject().contains("RFR: ")) {
return;
}

@@ -77,18 +77,8 @@ synchronized void inspect(Conversation conversation) {
return;
}

var pr = repositories.stream()
.map(repository -> repository.parsePullRequestUrl(matcher.group(1)))
.filter(Optional::isPresent)
.map(Optional::get)
.findAny();
if (pr.isEmpty()) {
log.info("PR link that can't be matched to an actual PR: " + matcher.group(1));
return;
}

// Matching pull request found!
parsedConversations.put(conversation.first().id(), pr.get());
// Valid looking pull request link found!
parsedConversations.put(first.id(), matcher.group(1));
parsedEmailIds.remove(first.id());
}

@@ -104,13 +94,30 @@ synchronized void inspect(Conversation conversation) {
parsedEmailIds.add(newMessage.id());
}

var pr = parsedConversations.get(conversation.first().id());
var pr = resolvedPullRequests.get(first.id());
if (pr == null) {
var prLink = parsedConversations.get(first.id());
if (prLink.equals("invalid")) {
return;
}
var foundPr = repositories.stream()
.map(repository -> repository.parsePullRequestUrl(prLink))
.filter(Optional::isPresent)
.map(Optional::get).findAny();
if (foundPr.isEmpty()) {
log.info("PR link that can't be matched to an actual PR: " + prLink);
parsedConversations.put(first.id(), "invalid");
return;
}
pr = foundPr.get();
resolvedPullRequests.put(first.id(), pr);
}
var bridgeIdPattern = Pattern.compile("^[^.]+\\.[^.]+@" + pr.repository().url().getHost() + "$");

// Filter out already bridged comments
var bridgeCandidates = newMessages.stream()
.filter(email -> !bridgeIdPattern.matcher(email.id().address()).matches())
.collect(Collectors.toList());
.filter(email -> !bridgeIdPattern.matcher(email.id().address()).matches())
.collect(Collectors.toList());
if (bridgeCandidates.isEmpty()) {
return;
}