diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/MailingListUpdater.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/MailingListUpdater.java index dcc708a09..9501c56b2 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/MailingListUpdater.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/MailingListUpdater.java @@ -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(); diff --git a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java index 916bd5378..97b20c26a 100644 --- a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java +++ b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java @@ -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 ")); + assertTrue(email.body().contains("Committer: committer ")); + assertFalse(email.body().contains(masterHash.abbreviate())); + } + } + } diff --git a/test/src/main/java/org/openjdk/skara/test/CheckableRepository.java b/test/src/main/java/org/openjdk/skara/test/CheckableRepository.java index bc4f17f2d..59a3888e4 100644 --- a/test/src/main/java/org/openjdk/skara/test/CheckableRepository.java +++ b/test/src/main/java/org/openjdk/skara/test/CheckableRepository.java @@ -96,6 +96,11 @@ 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); @@ -103,7 +108,7 @@ public static Hash appendAndCommit(Repository repo, String body, String message, } 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 {