Skip to content
Permalink
Browse files

27: Push notification email should contain ev. sponsor

Reviewed-by: ehelin
  • Loading branch information
Robin Westberg
Robin Westberg committed Jul 3, 2019
1 parent 8a62fc9 commit 0cfec5797ca0cc49271fbcda45df87b9d963316e
@@ -60,6 +60,9 @@ private String commitToText(HostedRepository repository, Commit commit) {

printer.println("Changeset: " + commit.hash().abbreviate());
printer.println("Author: " + commit.author().name() + " <" + commit.author().email() + ">");
if (!commit.author().equals(commit.committer())) {
printer.println("Committer: " + commit.committer().name() + " <" + commit.committer().email() + ">");
}
printer.println("Date: " + commit.date().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss +0000")));
printer.println("URL: " + repository.getWebUrl(commit.hash()));
printer.println();
@@ -65,6 +65,7 @@ void testJsonUpdaterBranch(TestInfo testInfo) throws IOException {
var jsonFolder = new TemporaryDirectory()) {
var repo = credentials.getHostedRepository();
var localRepo = CheckableRepository.init(tempFolder.path(), repo.getRepositoryType());
localRepo.fetch(repo.getUrl(), "testlock:testlock");
localRepo.pushAll(repo.getUrl());

var tagStorage = createTagStorage(repo);
@@ -98,6 +99,7 @@ void testJsonUpdaterTag(TestInfo testInfo) throws IOException {
var jsonFolder = new TemporaryDirectory()) {
var repo = credentials.getHostedRepository();
var localRepo = CheckableRepository.init(tempFolder.path(), repo.getRepositoryType());
localRepo.fetch(repo.getUrl(), "testlock:testlock");
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.tag(masterHash, "jdk-12+1", "Added tag 1", "Duke", "duke@openjdk.java.net");
localRepo.pushAll(repo.getUrl());
@@ -169,6 +171,7 @@ void testMailingList(TestInfo testInfo) throws IOException {
assertEquals(email.recipients(), List.of(recipient));
assertTrue(email.body().contains("Changeset: " + editHash.abbreviate()));
assertTrue(email.body().contains("23456789: More fixes"));
assertFalse(email.body().contains("Committer"));
assertFalse(email.body().contains(masterHash.abbreviate()));
}
}
@@ -212,4 +215,44 @@ void testMailingListMultiple(TestInfo testInfo) throws IOException {
assertFalse(email.body().contains(masterHash.abbreviate()));
}
}

@Test
void testMailingListSponsored(TestInfo testInfo) throws IOException {
try (var smtpServer = new SMTPServer();
var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory()) {
var repo = credentials.getHostedRepository();
var repoFolder = tempFolder.path().resolve("repo");
var localRepo = CheckableRepository.init(repoFolder, repo.getRepositoryType());
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, repo.getUrl(), "master", true);

var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);

var sender = EmailAddress.from("duke", "duke@duke.duke");
var recipient = EmailAddress.from("list", "list@list.list");
var updater = new MailingListUpdater(smtpServer.address(), recipient, sender);
var notifyBot = new JNotifyBot(repo, "master", tagStorage, branchStorage, List.of(updater));

// No mail should be sent on the first run as there is no history
TestBotRunner.runPeriodicItems(notifyBot);
assertThrows(RuntimeException.class, () -> smtpServer.receive(Duration.ofMillis(1)));

var editHash = CheckableRepository.appendAndCommit(localRepo, "Another line", "23456789: More fixes",
"author", "author@test.test",
"committer", "committer@test.test");
localRepo.push(editHash, repo.getUrl(), "master");
TestBotRunner.runPeriodicItems(notifyBot);
var email = smtpServer.receive(Duration.ofSeconds(10));
assertEquals(email.sender(), sender);
assertEquals(email.recipients(), List.of(recipient));
assertTrue(email.body().contains("Changeset: " + editHash.abbreviate()));
assertTrue(email.body().contains("23456789: More fixes"));
assertTrue(email.body().contains("Author: author <author@test.test>"));
assertTrue(email.body().contains("Committer: committer <committer@test.test>"));
assertFalse(email.body().contains(masterHash.abbreviate()));
}
}

}
@@ -96,14 +96,19 @@ public static Hash appendAndCommit(Repository repo, String body, String message)
}

public static Hash appendAndCommit(Repository repo, String body, String message, String authorName, String authorEmail) throws IOException {
return appendAndCommit(repo, body, message, authorName, authorEmail, authorName, authorEmail);
}

public static Hash appendAndCommit(Repository repo, String body, String message, String authorName, String authorEmail,
String committerName, String committerEmail) throws IOException {
var file = checkableFile(repo.root());
try (var output = Files.newBufferedWriter(file, StandardOpenOption.APPEND)) {
output.append(body);
output.append("\n");
}
repo.add(file);

return repo.commit(message, authorName, authorEmail);
return repo.commit(message, authorName, authorEmail, committerName, committerEmail);
}

public static Hash replaceAndCommit(Repository repo, String body) throws IOException {

0 comments on commit 0cfec57

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