Skip to content

Commit

Permalink
Add support for adding extra headers to mails sent to mailing lists
Browse files Browse the repository at this point in the history
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Sep 24, 2019
1 parent 2ab7e26 commit 15376a9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public void run(Path scratchPath) {
newMail::headerValue));
var filteredEmail = Email.from(newMail)
.replaceHeaders(filteredHeaders)
.headers(bot.headers())
.build();
list.post(filteredEmail);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class MailingListBridgeBot implements Bot {
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 PullRequestUpdateCache updateCache;

Expand All @@ -53,7 +54,7 @@ public class MailingListBridgeBot implements Bot {
Set<String> ignoredUsers, Set<Pattern> ignoredComments, URI listArchive, String smtpServer,
HostedRepository webrevStorageRepository, String webrevStorageRef,
Path webrevStorageBase, URI webrevStorageBaseUri, Set<String> readyLabels,
Map<String, Pattern> readyComments, URI issueTracker) {
Map<String, Pattern> readyComments, URI issueTracker, Map<String, String> headers) {
emailAddress = from;
codeRepo = repo;
archiveRepo = archive;
Expand All @@ -66,6 +67,7 @@ public class MailingListBridgeBot implements Bot {
this.smtpServer = smtpServer;
this.readyLabels = readyLabels;
this.readyComments = readyComments;
this.headers = headers;
this.issueTracker = issueTracker;

this.webrevStorage = new WebrevStorage(webrevStorageRepository, webrevStorageRef, webrevStorageBase,
Expand Down Expand Up @@ -125,6 +127,10 @@ Map<String, Pattern> readyComments() {
return readyComments;
}

Map<String, String> headers() {
return headers;
}

URI issueTracker() {
return issueTracker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ public List<Bot> create(BotConfiguration configuration) {
var censusRepo = configuration.repository(repoConfig.get("census").asString());
var censusRef = configuration.repositoryRef(repoConfig.get("census").asString());

Map<String, String> headers = repoConfig.contains("headers") ?
repoConfig.get("headers").fields().stream()
.collect(Collectors.toMap(JSONObject.Field::name, field -> field.value().asString())) :
Map.of();

var list = EmailAddress.parse(repoConfig.get("list").asString());
var folder = repoConfig.contains("folder") ? repoConfig.get("folder").asString() : configuration.repositoryName(repo);
var bot = new MailingListBridgeBot(from, configuration.repository(repo), archiveRepo,
censusRepo, censusRef,
list, ignoredUsers, ignoredComments, listArchive, listSmtp,
webrevRepo, webrevRef, Path.of(folder),
URIBuilder.base(webrevWeb).build(), readyLabels, readyComments,
issueTracker);
issueTracker, headers);
ret.add(bot);

allListNames.add(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void simpleArchive(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// The mailing list as well
var mailmanServer = MailingListServerFactory.createMailmanServer(listServer.getArchive(), listServer.getSMTP());
Expand Down Expand Up @@ -136,7 +137,8 @@ void rememberBridged(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// The mailing list as well
var mailmanServer = MailingListServerFactory.createMailmanServer(listServer.getArchive(), listServer.getSMTP());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ void simpleArchive(TestInfo testInfo) throws IOException {
URIBuilder.base("http://www.test.test/").build(),
Set.of("rfr"), Map.of(ignored.host().getCurrentUserDetails().userName(),
Pattern.compile("ready")),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of("Extra1", "val1", "Extra2", "val2"));

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.getRepositoryType());
Expand Down Expand Up @@ -188,6 +189,8 @@ void simpleArchive(TestInfo testInfo) throws IOException {
assertEquals(pr.getAuthor().fullName(), mail.author().fullName().orElseThrow());
assertEquals(noreplyAddress(archive), mail.author().address());
assertEquals(from, mail.sender());
assertEquals("val1", mail.headerValue("Extra1"));
assertEquals("val2", mail.headerValue("Extra2"));

// And there should be a webrev
Repository.materialize(webrevFolder.path(), archive.getUrl(), "webrev");
Expand Down Expand Up @@ -264,7 +267,8 @@ void reviewComment(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -351,7 +355,8 @@ void combineComments(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -433,7 +438,8 @@ void commentThreading(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -542,7 +548,8 @@ void reviewContext(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -592,7 +599,8 @@ void multipleReviewContexts(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -660,7 +668,8 @@ void filterComments(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -718,7 +727,8 @@ void incrementalChanges(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -838,7 +848,8 @@ void rebased(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -930,7 +941,8 @@ void skipAddingExistingWebrev(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.getRepositoryType());
Expand Down Expand Up @@ -1002,7 +1014,8 @@ void notifyReviewVerdicts(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down Expand Up @@ -1085,7 +1098,8 @@ void ignoreComments(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
Expand Down

0 comments on commit 15376a9

Please sign in to comment.