Skip to content
Permalink
Browse files
Filter out PR-headers before sending mails
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Sep 17, 2019
1 parent 3e6357c commit cd61be82d476cc70ca45aee8ed4726495185ddfe
Showing 4 changed files with 20 additions and 9 deletions.
@@ -33,9 +33,10 @@
import java.nio.file.Path;
import java.time.Duration;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.*;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

class ArchiveWorkItem implements WorkItem {
private final PullRequest pr;
@@ -301,7 +302,16 @@ public void run(Path scratchPath) {
pushMbox(archiveRepo, "Adding comments for PR " + bot.codeRepo().getName() + "/" + pr.getId());

// Finally post all new mails to the actual list
newMails.forEach(list::post);
for (var newMail : newMails) {
var filteredHeaders = newMail.headers().stream()
.filter(header -> !header.startsWith("PR-"))
.collect(Collectors.toMap(Function.identity(),
newMail::headerValue));
var filteredEmail = Email.from(newMail)
.replaceHeaders(filteredHeaders)
.build();
list.post(filteredEmail);
}
}

@Override
@@ -5,7 +5,6 @@
import org.openjdk.skara.host.*;
import org.openjdk.skara.vcs.Hash;

import java.io.*;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.*;
@@ -184,12 +183,7 @@ void create(URI webrev) {
}

private String latestHeadPrefix() {
try {
var latestCommit = prInstance.localRepo().lookup(prInstance.headHash()).orElseThrow(RuntimeException::new);
return String.format("[Rev %02d]", revisionCount());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return String.format("[Rev %02d]", revisionCount());
}

void addFull(URI webrev) {
@@ -881,6 +881,7 @@ void rebased(TestInfo testInfo) throws IOException {
for (var newMail : conversations.get(0).allMessages()) {
assertEquals(noreplyAddress(archive), newMail.author().address());
assertEquals(sender, newMail.sender());
assertFalse(newMail.hasHeader("PR-Head-Hash"));
}
assertEquals("Re: [Rev 01]: RFR: This is a pull request", conversations.get(0).allMessages().get(1).subject());
}
@@ -92,6 +92,12 @@ public EmailBuilder headers(Map<String, String> headers) {
return this;
}

public EmailBuilder replaceHeaders(Map<String, String> headers) {
this.headers.clear();
this.headers.putAll(headers);
return this;
}

public EmailBuilder date(ZonedDateTime date) {
this.date = date;
return this;

0 comments on commit cd61be8

Please sign in to comment.