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

976: Do not send empty emails #1128

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
@@ -114,7 +114,7 @@ private Repository materializeArchive(Path scratchPath) {
}
}

private final static Pattern commandPattern = Pattern.compile("^\\s*/([A-Za-z]+).*$");
private static final Pattern commandPattern = Pattern.compile("^\\s*/([A-Za-z]+).*$", Pattern.MULTILINE | Pattern.DOTALL);

private boolean ignoreComment(HostUser author, String body) {
if (pr.repository().forge().currentUser().equals(author)) {
@@ -124,11 +124,12 @@ private boolean ignoreComment(HostUser author, String body) {
return true;
}
// Check if this comment only contains command lines
var commandOnly = body.strip().lines()
.map(commandPattern::matcher)
.allMatch(Matcher::matches);
if (body.strip().lines().count() > 0 && commandOnly) {
return true;
var commandLineMatcher = commandPattern.matcher(body);
if (commandLineMatcher.find()) {
var filteredBody = commandLineMatcher.replaceAll("");
if (filteredBody.strip().isEmpty()) {
return true;
}
}
for (var ignoredCommentPattern : bot.ignoredComments()) {
var ignoredCommentMatcher = ignoredCommentPattern.matcher(body);
@@ -1516,6 +1516,18 @@ void filterComments(TestInfo testInfo) throws IOException {
assertFalse(archiveContains(archiveFolder.path(), "/newline"));
assertFalse(archiveContains(archiveFolder.path(), "/multiline"));
assertFalse(archiveContains(archiveFolder.path(), "will be dropped"));

// There should not be consecutive empty lines due to a filtered multiline message
var lines = archiveContents(archiveFolder.path(), "").orElseThrow();
assertFalse(lines.contains("\n\n\n"), lines);

// And a stand-alone multiline comment should not cause another mail to be sent
pr.addComment("/another\nmultiline\nwill not cause another mail");
TestBotRunner.runPeriodicItems(mlBot);
Repository.materialize(archiveFolder.path(), archive.url(), "master");
lines = archiveContents(archiveFolder.path(), "").orElseThrow();
var mails = Mbox.splitMbox(lines, EmailAddress.from("duke@openjdk.org"));
assertEquals(2, mails.size());
}
}