Skip to content
Permalink
Browse files

121: Send notification emails when new tags are created

Reviewed-by: ehelin
  • Loading branch information
Robin Westberg
Robin Westberg committed Oct 10, 2019
1 parent 1ce5bd6 commit 07bb71a14a270a2094740ce1ef74375e22e9f13b
@@ -130,19 +130,23 @@ private void handleTags(Repository localRepo, UpdateHistory history) throws IOEx
.collect(Collectors.toList());

for (var tag : newJdkTags) {
// Update the history first - if there is a problem here we don't want to send out multiple updates
history.addTags(List.of(tag.tag()));

var commits = new ArrayList<Commit>();
var previous = existingPrevious(tag, allJdkTags);
if (previous.isEmpty()) {
log.warning("No previous tag found for '" + tag.tag() + "' - ignoring");
continue;
}
var commits = localRepo.commits(previous.get().tag() + ".." + tag.tag()).asList();
if (commits.size() == 0) {
continue;
var commit = localRepo.lookup(tag.tag());
if (commit.isEmpty()) {
throw new RuntimeException("Failed to lookup tag '" + tag.toString() + "'");
} else {
commits.add(commit.get());
log.warning("No previous tag found for '" + tag.tag() + "'");
}
} else {
commits.addAll(localRepo.commits(previous.get().tag() + ".." + tag.tag()).asList());
}

// Update the history first - if there is a problem here we don't want to send out multiple updates
history.addTags(List.of(tag.tag()));

Collections.reverse(commits);
for (var updater : updaters) {
updater.handleTagCommits(repository, commits, tag);
@@ -123,6 +123,16 @@ private String commitsToSubject(HostedRepository repository, List<Commit> commit
return subject.toString();
}

private String tagToSubject(HostedRepository repository, Hash hash, OpenJDKTag tag) {
return repository.getRepositoryType().shortName() +
": " +
repository.getName() +
": Added tag " +
tag.tag() +
" for changeset " +
hash.abbreviate();
}

private List<Commit> filterAndSendPrCommits(HostedRepository repository, List<Commit> commits) {
var ret = new ArrayList<Commit>();

@@ -207,6 +217,29 @@ public void handleCommits(HostedRepository repository, List<Commit> commits, Bra

@Override
public void handleTagCommits(HostedRepository repository, List<Commit> commits, OpenJDKTag tag) {
var writer = new StringWriter();
var printer = new PrintWriter(writer);

printer.println("The following commits are included in " + tag.tag());
printer.println("========================================================");
for (var commit : commits) {
printer.print(commit.hash().abbreviate());
if (commit.message().size() > 0) {
printer.print(": " + commit.message().get(0));
}
printer.println();
}

var tagCommit = commits.get(commits.size() - 1);
var subject = tagToSubject(repository, tagCommit.hash(), tag);
var finalAuthor = author != null ? author : commitsToAuthor(commits);
var email = Email.create(subject, writer.toString())
.sender(sender)
.author(finalAuthor)
.recipient(recipient)
.headers(headers)
.build();

list.post(email);
}
}
@@ -553,4 +553,94 @@ void testMailingListPR(TestInfo testInfo) throws IOException {
assertTrue(pushEmail.subject().contains("23456789: More fixes"));
}
}

@Test
void testMailinglistTag(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory();
var listServer = new TestMailmanServer()) {
var repo = credentials.getHostedRepository();
var localRepoFolder = tempFolder.path().resolve("repo");
var localRepo = CheckableRepository.init(localRepoFolder, repo.getRepositoryType());
credentials.commitLock(localRepo);
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.tag(masterHash, "jdk-12+1", "Added tag 1", "Duke", "duke@openjdk.java.net");
localRepo.pushAll(repo.getUrl());

var listAddress = EmailAddress.parse(listServer.createList("test"));
var mailmanServer = MailingListServerFactory.createMailmanServer(listServer.getArchive(), listServer.getSMTP());
var mailmanList = mailmanServer.getList(listAddress.address());
var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var storageFolder = tempFolder.path().resolve("storage");

var sender = EmailAddress.from("duke", "duke@duke.duke");
var updater = new MailingListUpdater(mailmanList, listAddress, sender, null, false, MailingListUpdater.Mode.ALL,
Map.of("extra1", "value1", "extra2", "value2"));
var notifyBot = new JNotifyBot(repo, storageFolder, Pattern.compile("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, () -> listServer.processIncoming(Duration.ofMillis(1)));

var editHash = CheckableRepository.appendAndCommit(localRepo, "Another line", "23456789: More fixes");
localRepo.fetch(repo.getUrl(), "history:history");
localRepo.tag(editHash, "jdk-12+2", "Added tag 2", "Duke", "duke@openjdk.java.net");
CheckableRepository.appendAndCommit(localRepo, "Another line 1", "34567890: Even more fixes");
CheckableRepository.appendAndCommit(localRepo, "Another line 2", "45678901: Yet even more fixes");
var editHash2 = CheckableRepository.appendAndCommit(localRepo, "Another line 3", "56789012: Still even more fixes");
localRepo.tag(editHash2, "jdk-12+4", "Added tag 3", "Duke", "duke@openjdk.java.net");
CheckableRepository.appendAndCommit(localRepo, "Another line 4", "67890123: Brand new fixes");
var editHash3 = CheckableRepository.appendAndCommit(localRepo, "Another line 5", "78901234: More brand new fixes");
localRepo.tag(editHash3, "jdk-13+0", "Added tag 4", "Duke", "duke@openjdk.java.net");
localRepo.pushAll(repo.getUrl());

TestBotRunner.runPeriodicItems(notifyBot);
listServer.processIncoming();
listServer.processIncoming();
listServer.processIncoming();

var conversations = mailmanList.conversations(Duration.ofDays(1));
assertEquals(3, conversations.size());

for (var conversation : conversations) {
var email = conversation.first();
if (email.subject().equals("git: test: Added tag jdk-12+2 for changeset " + editHash.abbreviate())) {
assertTrue(email.body().contains("23456789: More fixes"));
assertFalse(email.body().contains("34567890: Even more fixes"));
assertFalse(email.body().contains("45678901: Yet even more fixes"));
assertFalse(email.body().contains("56789012: Still even more fixes"));
assertFalse(email.body().contains("67890123: Brand new fixes"));
assertFalse(email.body().contains("78901234: More brand new fixes"));
} else if (email.subject().equals("git: test: Added tag jdk-12+4 for changeset " + editHash2.abbreviate())) {
assertFalse(email.body().contains("23456789: More fixes"));
assertTrue(email.body().contains("34567890: Even more fixes"));
assertTrue(email.body().contains("45678901: Yet even more fixes"));
assertTrue(email.body().contains("56789012: Still even more fixes"));
assertFalse(email.body().contains("67890123: Brand new fixes"));
assertFalse(email.body().contains("78901234: More brand new fixes"));
} else if (email.subject().equals("git: test: Added tag jdk-13+0 for changeset " + editHash3.abbreviate())) {
assertFalse(email.body().contains("23456789: More fixes"));
assertFalse(email.body().contains("34567890: Even more fixes"));
assertFalse(email.body().contains("45678901: Yet even more fixes"));
assertFalse(email.body().contains("56789012: Still even more fixes"));
assertFalse(email.body().contains("67890123: Brand new fixes"));
assertTrue(email.body().contains("78901234: More brand new fixes"));
} else if (email.subject().equals("git: test: 4 new changesets")) {
assertTrue(email.body().contains("23456789: More fixes"));
assertTrue(email.body().contains("34567890: Even more fixes"));
assertTrue(email.body().contains("45678901: Yet even more fixes"));
assertTrue(email.body().contains("56789012: Still even more fixes"));
assertTrue(email.body().contains("67890123: Brand new fixes"));
assertTrue(email.body().contains("78901234: More brand new fixes"));
} else {
fail("Mismatched subject: " + email.subject());
}
assertTrue(email.hasHeader("extra1"));
assertEquals("value1", email.headerValue("extra1"));
assertTrue(email.hasHeader("extra2"));
assertEquals("value2", email.headerValue("extra2"));
}
}
}
}

0 comments on commit 07bb71a

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