diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/Emitter.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/Emitter.java new file mode 100644 index 000000000..e5315e913 --- /dev/null +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/Emitter.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package org.openjdk.skara.bots.notify; + +public interface Emitter { + void registerPullRequestListener(PullRequestListener listener); + void registerRepositoryListener(RepositoryListener listener); +} diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/Notifier.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/Notifier.java index 1a14257fc..bc4db4d11 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/Notifier.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/Notifier.java @@ -26,8 +26,6 @@ import org.openjdk.skara.json.JSONObject; public interface Notifier { - String name(); - static Notifier create(String name, BotConfiguration botConfiguration, JSONObject notifierConfiguration) { var factory = NotifierFactory.getNotifierFactories().stream() .filter(f -> f.name().equals(name)) @@ -37,4 +35,6 @@ static Notifier create(String name, BotConfiguration botConfiguration, JSONObjec } return factory.get().create(botConfiguration, notifierConfiguration); } + + void attachTo(Emitter e); } diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBot.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBot.java index e116409b4..d68ccf324 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBot.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBot.java @@ -31,7 +31,7 @@ import java.util.logging.Logger; import java.util.regex.Pattern; -public class NotifyBot implements Bot { +public class NotifyBot implements Bot, Emitter { private final Logger log = Logger.getLogger("org.openjdk.skara.bots");; private final HostedRepository repository; private final Path storagePath; @@ -39,8 +39,8 @@ public class NotifyBot implements Bot { private final StorageBuilder tagStorageBuilder; private final StorageBuilder branchStorageBuilder; private final StorageBuilder prStateStorageBuilder; - private final List updaters; - private final List prUpdaters; + private final List repoListeners = new ArrayList<>(); + private final List prListeners = new ArrayList<>(); private final PullRequestUpdateCache updateCache; private final Set readyLabels; private final Map readyComments; @@ -48,7 +48,6 @@ public class NotifyBot implements Bot { NotifyBot(HostedRepository repository, Path storagePath, Pattern branches, StorageBuilder tagStorageBuilder, StorageBuilder branchStorageBuilder, StorageBuilder prStateStorageBuilder, - List updaters, List prUpdaters, Set readyLabels, Map readyComments, String integratorId) { this.repository = repository; this.storagePath = storagePath; @@ -56,8 +55,6 @@ public class NotifyBot implements Bot { this.tagStorageBuilder = tagStorageBuilder; this.branchStorageBuilder = branchStorageBuilder; this.prStateStorageBuilder = prStateStorageBuilder; - this.updaters = updaters; - this.prUpdaters = prUpdaters; this.updateCache = new PullRequestUpdateCache(); this.readyLabels = readyLabels; this.readyComments = readyComments; @@ -98,6 +95,16 @@ private boolean isReady(PullRequest pr) { return true; } + @Override + public void registerPullRequestListener(PullRequestListener listener) { + prListeners.add(listener); + } + + @Override + public void registerRepositoryListener(RepositoryListener listener) { + repoListeners.add(listener); + } + @Override public String toString() { return "JNotifyBot@" + repository.name(); @@ -116,14 +123,14 @@ public List getPeriodicItems() { } ret.add(new PullRequestWorkItem(pr, prStateStorageBuilder, - prUpdaters, + prListeners, e -> updateCache.invalidate(pr), integratorId)); } } // Repository events - ret.add(new RepositoryWorkItem(repository, storagePath, branches, tagStorageBuilder, branchStorageBuilder, updaters)); + ret.add(new RepositoryWorkItem(repository, storagePath, branches, tagStorageBuilder, branchStorageBuilder, repoListeners)); return ret; } diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotBuilder.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotBuilder.java index b6334b4cb..f26bf67ea 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotBuilder.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotBuilder.java @@ -36,8 +36,6 @@ public class NotifyBotBuilder { private StorageBuilder tagStorageBuilder; private StorageBuilder branchStorageBuilder; private StorageBuilder prStateStorageBuilder; - private List updaters = List.of(); - private List prUpdaters = List.of(); private Set readyLabels = Set.of(); private Map readyComments = Map.of(); private String integratorId; @@ -72,16 +70,6 @@ public NotifyBotBuilder prStateStorageBuilder(StorageBuilder p return this; } - public NotifyBotBuilder updaters(List updaters) { - this.updaters = updaters; - return this; - } - - public NotifyBotBuilder prUpdaters(List prUpdaters) { - this.prUpdaters = prUpdaters; - return this; - } - public NotifyBotBuilder readyLabels(Set readyLabels) { this.readyLabels = readyLabels; return this; @@ -98,6 +86,6 @@ public NotifyBotBuilder integratorId(String integratorId) { } public NotifyBot build() { - return new NotifyBot(repository, storagePath, branches, tagStorageBuilder, branchStorageBuilder, prStateStorageBuilder, updaters, prUpdaters, readyLabels, readyComments, integratorId); + return new NotifyBot(repository, storagePath, branches, tagStorageBuilder, branchStorageBuilder, prStateStorageBuilder, readyLabels, readyComments, integratorId); } } diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotFactory.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotFactory.java index 10b265044..8fcfc270a 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotFactory.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/NotifyBotFactory.java @@ -89,34 +89,6 @@ public List create(BotConfiguration configuration) { branchPattern = Pattern.compile(repo.value().get("branches").asString()); } - var updaters = new ArrayList(); - var prUpdaters = new ArrayList(); - - for (var notifierFactory : notifierFactories) { - if (repo.value().contains(notifierFactory.name())) { - var confArray = repo.value().get(notifierFactory.name()); - if (!confArray.isArray()) { - confArray = JSON.array().add(confArray); - } - for (var conf : confArray.asArray()) { - var finalConfiguration = combineConfiguration(notifierConfiguration.get(notifierFactory.name()), conf.asObject()); - var notifier = Notifier.create(notifierFactory.name(), configuration, finalConfiguration); - log.info("Configuring notifier " + notifierFactory.name() + " for repository " + repoName); - if (notifier instanceof PullRequestUpdateConsumer) { - prUpdaters.add((PullRequestUpdateConsumer)notifier); - } - if (notifier instanceof RepositoryUpdateConsumer) { - updaters.add((RepositoryUpdateConsumer)notifier); - } - } - } - } - - if (updaters.isEmpty() && prUpdaters.isEmpty()) { - log.warning("No notifiers configured for notify bot repository: " + repoName); - continue; - } - var baseName = repo.value().contains("basename") ? repo.value().get("basename").asString() : configuration.repositoryName(repoName); var tagStorageBuilder = new StorageBuilder(baseName + ".tags.txt") @@ -132,12 +104,33 @@ public List create(BotConfiguration configuration) { .tagStorageBuilder(tagStorageBuilder) .branchStorageBuilder(branchStorageBuilder) .prStateStorageBuilder(prStateStorageBuilder) - .updaters(updaters) - .prUpdaters(prUpdaters) .readyLabels(readyLabels) .readyComments(readyComments) .integratorId(integratorId) .build(); + + var hasAttachedNotifier = false; + for (var notifierFactory : notifierFactories) { + if (repo.value().contains(notifierFactory.name())) { + var confArray = repo.value().get(notifierFactory.name()); + if (!confArray.isArray()) { + confArray = JSON.array().add(confArray); + } + for (var conf : confArray.asArray()) { + var finalConfiguration = combineConfiguration(notifierConfiguration.get(notifierFactory.name()), conf.asObject()); + var notifier = Notifier.create(notifierFactory.name(), configuration, finalConfiguration); + log.info("Configuring notifier " + notifierFactory.name() + " for repository " + repoName); + notifier.attachTo(bot); + hasAttachedNotifier = true; + } + } + } + + if (!hasAttachedNotifier) { + log.warning("No notifiers configured for notify bot repository: " + repoName); + continue; + } + ret.add(bot); } diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestUpdateConsumer.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestListener.java similarity index 96% rename from bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestUpdateConsumer.java rename to bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestListener.java index b19df6df7..ca696de7c 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestUpdateConsumer.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestListener.java @@ -26,7 +26,7 @@ import org.openjdk.skara.vcs.Hash; import org.openjdk.skara.vcs.openjdk.Issue; -public interface PullRequestUpdateConsumer extends Notifier { +public interface PullRequestListener { default void handleNewIssue(PullRequest pr, Issue issue) { } default void handleRemovedIssue(PullRequest pr, Issue issue) { diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestWorkItem.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestWorkItem.java index 79c911baa..e42d69dcb 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestWorkItem.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/PullRequestWorkItem.java @@ -38,14 +38,14 @@ public class PullRequestWorkItem implements WorkItem { private final PullRequest pr; private final StorageBuilder prStateStorageBuilder; - private final List pullRequestUpdateConsumers; + private final List listeners; private final Consumer errorHandler; private final String integratorId; - PullRequestWorkItem(PullRequest pr, StorageBuilder prStateStorageBuilder, List pullRequestUpdateConsumers, Consumer errorHandler, String integratorId) { + PullRequestWorkItem(PullRequest pr, StorageBuilder prStateStorageBuilder, List listeners, Consumer errorHandler, String integratorId) { this.pr = pr; this.prStateStorageBuilder = prStateStorageBuilder; - this.pullRequestUpdateConsumers = pullRequestUpdateConsumers; + this.listeners = listeners; this.errorHandler = errorHandler; this.integratorId = integratorId; } @@ -156,20 +156,20 @@ public boolean concurrentWith(WorkItem other) { return false; } - private void notifyListenersAdded(String issueId) { - pullRequestUpdateConsumers.forEach(c -> c.handleNewIssue(pr, new Issue(issueId, ""))); + private void notifyNewIssue(String issueId) { + listeners.forEach(c -> c.handleNewIssue(pr, new Issue(issueId, ""))); } - private void notifyListenersRemoved(String issueId) { - pullRequestUpdateConsumers.forEach(c -> c.handleRemovedIssue(pr, new Issue(issueId, ""))); + private void notifyRemovedIssue(String issueId) { + listeners.forEach(c -> c.handleRemovedIssue(pr, new Issue(issueId, ""))); } private void notifyNewPr(PullRequest pr) { - pullRequestUpdateConsumers.forEach(c -> c.handleNewPullRequest(pr)); + listeners.forEach(c -> c.handleNewPullRequest(pr)); } private void notifyIntegratedPr(PullRequest pr, Hash hash) { - pullRequestUpdateConsumers.forEach(c -> c.handleIntegratedPullRequest(pr, hash)); + listeners.forEach(c -> c.handleIntegratedPullRequest(pr, hash)); } @Override @@ -197,10 +197,10 @@ public Collection run(Path scratchPath) { var storedIssues = storedState.get().issueIds(); storedIssues.stream() .filter(issue -> !issues.contains(issue)) - .forEach(this::notifyListenersRemoved); + .forEach(this::notifyRemovedIssue); issues.stream() .filter(issue -> !storedIssues.contains(issue)) - .forEach(this::notifyListenersAdded); + .forEach(this::notifyNewIssue); var storedCommit = storedState.get().commitId(); if (!storedCommit.isPresent() && state.commitId().isPresent()) { @@ -208,7 +208,7 @@ public Collection run(Path scratchPath) { } } else { notifyNewPr(pr); - issues.forEach(this::notifyListenersAdded); + issues.forEach(this::notifyNewIssue); if (state.commitId().isPresent()) { notifyIntegratedPr(pr, state.commitId().get()); } diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryUpdateConsumer.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryListener.java similarity index 97% rename from bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryUpdateConsumer.java rename to bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryListener.java index 5bcd29c44..073911819 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryUpdateConsumer.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryListener.java @@ -28,7 +28,7 @@ import java.util.List; -public interface RepositoryUpdateConsumer extends Notifier { +public interface RepositoryListener { default void handleCommits(HostedRepository repository, Repository localRepository, List commits, Branch branch) throws NonRetriableException { } default void handleOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List commits, OpenJDKTag tag, Tag.Annotated annotated) throws NonRetriableException { diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryWorkItem.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryWorkItem.java index 7a8f086d9..f0e4317d9 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryWorkItem.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/RepositoryWorkItem.java @@ -42,18 +42,18 @@ public class RepositoryWorkItem implements WorkItem { private final Pattern branches; private final StorageBuilder tagStorageBuilder; private final StorageBuilder branchStorageBuilder; - private final List updaters; + private final List listeners; - RepositoryWorkItem(HostedRepository repository, Path storagePath, Pattern branches, StorageBuilder tagStorageBuilder, StorageBuilder branchStorageBuilder, List updaters) { + RepositoryWorkItem(HostedRepository repository, Path storagePath, Pattern branches, StorageBuilder tagStorageBuilder, StorageBuilder branchStorageBuilder, List listeners) { this.repository = repository; this.storagePath = storagePath; this.branches = branches; this.tagStorageBuilder = tagStorageBuilder; this.branchStorageBuilder = branchStorageBuilder; - this.updaters = updaters; + this.listeners = listeners; } - private void handleNewRef(Repository localRepo, Reference ref, Collection allRefs, RepositoryUpdateConsumer updater) throws NonRetriableException { + private void handleNewRef(Repository localRepo, Reference ref, Collection allRefs, RepositoryListener listener) throws NonRetriableException { // Figure out the best parent ref var candidates = new HashSet<>(allRefs); candidates.remove(ref); @@ -84,24 +84,24 @@ private void handleNewRef(Repository localRepo, Reference ref, Collection commits, RepositoryUpdateConsumer updater) throws NonRetriableException { + private void handleUpdatedRef(Repository localRepo, Reference ref, List commits, RepositoryListener listener) throws NonRetriableException { var branch = new Branch(ref.name()); - updater.handleCommits(repository, localRepo, commits, branch); + listener.handleCommits(repository, localRepo, commits, branch); } private List handleRef(Repository localRepo, UpdateHistory history, Reference ref, Collection allRefs) throws IOException { var errors = new ArrayList(); var branch = new Branch(ref.name()); - for (var updater : updaters) { - var lastHash = history.branchHash(branch, updater.name()); + for (var listener : listeners) { + var lastHash = history.branchHash(branch, listener.name()); if (lastHash.isEmpty()) { - log.warning("No previous history found for branch '" + branch + "' and updater '" + updater.name() + " - resetting mark"); - history.setBranchHash(branch, updater.name(), ref.hash()); + log.warning("No previous history found for branch '" + branch + "' and listener '" + listener.name() + " - resetting mark"); + history.setBranchHash(branch, listener.name(), ref.hash()); try { - handleNewRef(localRepo, ref, allRefs, updater); + handleNewRef(localRepo, ref, allRefs, listener); } catch (NonRetriableException e) { errors.add(e.cause()); } catch (RuntimeException e) { @@ -114,22 +114,22 @@ private List handleRef(Repository localRepo, UpdateHistory history, R continue; } if (commitMetadata.size() > 1000) { - history.setBranchHash(branch, updater.name(), ref.hash()); + history.setBranchHash(branch, listener.name(), ref.hash()); errors.add(new RuntimeException("Excessive amount of new commits on branch " + branch.name() + - " detected (" + commitMetadata.size() + ") for updater '" + - updater.name() + "' - skipping notifications")); + " detected (" + commitMetadata.size() + ") for listener '" + + listener.name() + "' - skipping notifications")); continue; } var commits = localRepo.commits(lastHash.get() + ".." + ref.hash(), true).asList(); - history.setBranchHash(branch, updater.name(), ref.hash()); + history.setBranchHash(branch, listener.name(), ref.hash()); try { - handleUpdatedRef(localRepo, ref, commits, updater); + handleUpdatedRef(localRepo, ref, commits, listener); } catch (NonRetriableException e) { errors.add(e.cause()); } catch (RuntimeException e) { // Attempt to roll back - history.setBranchHash(branch, updater.name(), lastHash.get()); + history.setBranchHash(branch, listener.name(), lastHash.get()); errors.add(e); } } @@ -151,23 +151,23 @@ private Optional existingPrevious(OpenJDKTag tag, Set al } } - private List handleTags(Repository localRepo, UpdateHistory history, RepositoryUpdateConsumer updater) throws IOException { + private List handleTags(Repository localRepo, UpdateHistory history, RepositoryListener listener) throws IOException { var errors = new ArrayList(); var tags = localRepo.tags(); var newTags = tags.stream() - .filter(tag -> !history.hasTag(tag, updater.name())) + .filter(tag -> !history.hasTag(tag, listener.name())) .collect(Collectors.toList()); if (tags.size() == newTags.size()) { if (tags.size() > 0) { log.warning("No previous tag history found - ignoring all current tags"); - history.addTags(tags, updater.name()); + history.addTags(tags, listener.name()); } return errors; } if (newTags.size() > 10) { - history.addTags(newTags, updater.name()); + history.addTags(newTags, listener.name()); errors.add(new RuntimeException("Excessive amount of new tags detected (" + newTags.size() + ") - skipping notifications")); return errors; @@ -206,14 +206,14 @@ private List handleTags(Repository localRepo, UpdateHistory history, Collections.reverse(commits); var annotation = localRepo.annotate(tag.tag()); - history.addTags(List.of(tag.tag()), updater.name()); + history.addTags(List.of(tag.tag()), listener.name()); try { - updater.handleOpenJDKTagCommits(repository, localRepo, commits, tag, annotation.orElse(null)); + listener.handleOpenJDKTagCommits(repository, localRepo, commits, tag, annotation.orElse(null)); } catch (NonRetriableException e) { errors.add(e.cause()); } catch (RuntimeException e) { errors.add(e); - history.retryTagUpdate(tag.tag(), updater.name()); + history.retryTagUpdate(tag.tag(), listener.name()); } } @@ -228,14 +228,14 @@ private List handleTags(Repository localRepo, UpdateHistory history, var annotation = localRepo.annotate(tag); - history.addTags(List.of(tag), updater.name()); + history.addTags(List.of(tag), listener.name()); try { - updater.handleTagCommit(repository, localRepo, commit.get(), tag, annotation.orElse(null)); + listener.handleTagCommit(repository, localRepo, commit.get(), tag, annotation.orElse(null)); } catch (NonRetriableException e) { errors.add(e.cause()); } catch (RuntimeException e) { errors.add(e); - history.retryTagUpdate(tag, updater.name()); + history.retryTagUpdate(tag, listener.name()); } } @@ -270,17 +270,17 @@ public Collection run(Path scratchPath) { var history = UpdateHistory.create(tagStorageBuilder, historyPath.resolve("tags"), branchStorageBuilder, historyPath.resolve("branches")); var errors = new ArrayList(); - for (var updater : updaters) { - errors.addAll(handleTags(localRepo, history, updater)); + for (var listener : listeners) { + errors.addAll(handleTags(localRepo, history, listener)); } boolean hasBranchHistory = !history.isEmpty(); for (var ref : knownRefs) { if (!hasBranchHistory) { log.warning("No previous history found for any branch - resetting mark for '" + ref.name()); - for (var updater : updaters) { - log.info("Resetting mark for branch '" + ref.name() + "' for updater '" + updater.name() + "'"); - history.setBranchHash(new Branch(ref.name()), updater.name(), ref.hash()); + for (var listener : listeners) { + log.info("Resetting mark for branch '" + ref.name() + "' for listener '" + listener.name() + "'"); + history.setBranchHash(new Branch(ref.name()), listener.name(), ref.hash()); } } else { errors.addAll(handleRef(localRepo, history, ref, knownRefs)); diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/issue/IssueNotifier.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/issue/IssueNotifier.java index 0192ef587..02c64b6eb 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/issue/IssueNotifier.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/issue/IssueNotifier.java @@ -33,7 +33,7 @@ import java.util.*; import java.util.logging.Logger; -class IssueNotifier implements PullRequestUpdateConsumer { +class IssueNotifier implements Notifier, PullRequestListener { private final IssueProject issueProject; private final boolean reviewLink; private final URI reviewIcon; @@ -53,11 +53,6 @@ static IssueNotifierBuilder newBuilder() { return new IssueNotifierBuilder(); } - @Override - public String name() { - return "issue"; - } - private Optional findIssueUsername(CommitMetadata commit) { var authorEmail = EmailAddress.from(commit.author().email()); if (authorEmail.domain().equals("openjdk.org")) { @@ -72,6 +67,11 @@ private Optional findIssueUsername(CommitMetadata commit) { return Optional.of(committerEmail.localPart()); } + @Override + public void attachTo(Emitter e) { + e.registerPullRequestListener(this); + } + @Override public void handleIntegratedPullRequest(PullRequest pr, Hash hash) { var repository = pr.repository(); diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/json/JsonNotifier.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/json/JsonNotifier.java index d68cb5c0f..ec623d1c5 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/json/JsonNotifier.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/json/JsonNotifier.java @@ -32,7 +32,7 @@ import java.time.format.DateTimeFormatter; import java.util.*; -class JsonNotifier implements RepositoryUpdateConsumer { +class JsonNotifier implements Notifier, RepositoryListener { private final Path path; private final String version; private final String defaultBuild; @@ -76,6 +76,11 @@ private JSONObject issuesToChanges(HostedRepository repository, Repository local return ret; } + @Override + public void attachTo(Emitter e) { + e.registerRepositoryListener(this); + } + @Override public void handleCommits(HostedRepository repository, Repository localRepository, List commits, Branch branch) throws NonRetriableException { try (var writer = new JsonWriter(path, repository.name())) { diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifier.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifier.java index b149ce68e..7b452c206 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifier.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifier.java @@ -35,7 +35,7 @@ import java.util.logging.Logger; import java.util.regex.Pattern; -class MailingListNotifier implements RepositoryUpdateConsumer { +class MailingListNotifier implements Notifier, RepositoryListener { private final MailingList list; private final EmailAddress recipient; private final EmailAddress sender; @@ -213,6 +213,11 @@ private Map commitHeaders(HostedRepository repository, List commits, Branch branch) throws NonRetriableException { if (mode == Mode.PR) { diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/slack/SlackNotifier.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/slack/SlackNotifier.java index cb691cf58..e40408fa4 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/slack/SlackNotifier.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/slack/SlackNotifier.java @@ -35,7 +35,7 @@ import java.util.List; import java.time.format.DateTimeFormatter; -class SlackNotifier implements RepositoryUpdateConsumer, PullRequestUpdateConsumer { +class SlackNotifier implements Notifier, RepositoryListener, PullRequestListener { private final RestRequest prWebhook; private final RestRequest commitWebhook; private final String username; @@ -46,6 +46,12 @@ class SlackNotifier implements RepositoryUpdateConsumer, PullRequestUpdateConsum this.username = username; } + @Override + public void attachTo(Emitter e) { + e.registerPullRequestListener(this); + e.registerRepositoryListener(this); + } + @Override public void handleNewPullRequest(PullRequest pr) { if (prWebhook == null) { 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 3f452680a..66e771df7 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 @@ -52,13 +52,13 @@ public static StorageBuilder createPullRequestStateStorage(Hos .remoteRepository(repository, "history", "Duke", "duke@openjdk.java.net", "Updated prissues"); } - private static class TestRepositoryUpdateConsumer implements RepositoryUpdateConsumer { + private static class TestRepositoryListener implements Notifier, RepositoryListener { private final String name; private final boolean idempotent; private int updateCount = 0; private boolean shouldFail = false; - TestRepositoryUpdateConsumer(String name, boolean idempotent) { + TestRepositoryListener(String name, boolean idempotent) { this.name = name; this.idempotent = idempotent; } @@ -98,6 +98,11 @@ public void handleNewBranch(HostedRepository repository, Repository localReposit public String name() { return name; } + + @Override + public void attachTo(Emitter e) { + e.registerRepositoryListener(this); + } } @Test @@ -115,8 +120,6 @@ void testIdempotenceMix(TestInfo testInfo) throws IOException { var prStateStorage = createPullRequestStateStorage(repo); var storageFolder = tempFolder.path().resolve("storage"); - var idempotent = new TestRepositoryUpdateConsumer("i", true); - var nonIdempotent = new TestRepositoryUpdateConsumer("ni", false); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -124,9 +127,14 @@ void testIdempotenceMix(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .updaters(List.of(idempotent, nonIdempotent)) .build(); + var idempotent = new TestRepositoryListener("i", true); + idempotent.attachTo(notifyBot); + + var nonIdempotent = new TestRepositoryListener("ni", false); + nonIdempotent.attachTo(notifyBot); + // Initialize history TestBotRunner.runPeriodicItems(notifyBot); diff --git a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/issue/IssueNotifierTests.java b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/issue/IssueNotifierTests.java index bf486460c..560f540a4 100644 --- a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/issue/IssueNotifierTests.java +++ b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/issue/IssueNotifierTests.java @@ -53,11 +53,6 @@ void testIssueIdempotence(TestInfo testInfo) throws IOException { var issueProject = credentials.getIssueProject(); var commitIcon = URI.create("http://www.example.com/commit.png"); - var updater = IssueNotifier.newBuilder() - .issueProject(issueProject) - .reviewLink(false) - .commitIcon(commitIcon) - .build(); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -65,9 +60,14 @@ void testIssueIdempotence(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .prUpdaters(List.of(updater)) .integratorId(repo.forge().currentUser().id()) .build(); + var updater = IssueNotifier.newBuilder() + .issueProject(issueProject) + .reviewLink(false) + .commitIcon(commitIcon) + .build(); + updater.attachTo(notifyBot); // Initialize history TestBotRunner.runPeriodicItems(notifyBot); @@ -123,11 +123,6 @@ void testPullRequest(TestInfo testInfo) throws IOException { var issueProject = credentials.getIssueProject(); var reviewIcon = URI.create("http://www.example.com/review.png"); - var updater = IssueNotifier.newBuilder() - .issueProject(issueProject) - .reviewIcon(reviewIcon) - .commitLink(false) - .build(); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -135,10 +130,15 @@ void testPullRequest(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .prUpdaters(List.of(updater)) .readyLabels(Set.of("rfr")) .readyComments(Map.of(reviewer.forge().currentUser().userName(), Pattern.compile("This is now ready"))) .build(); + var updater = IssueNotifier.newBuilder() + .issueProject(issueProject) + .reviewIcon(reviewIcon) + .commitLink(false) + .build(); + updater.attachTo(notifyBot); // Initialize history TestBotRunner.runPeriodicItems(notifyBot); @@ -224,12 +224,6 @@ void testPullRequestNoReview(TestInfo testInfo) throws IOException { var issueProject = credentials.getIssueProject(); var reviewIcon = URI.create("http://www.example.com/review.png"); - var updater = IssueNotifier.newBuilder() - .issueProject(issueProject) - .reviewLink(false) - .reviewIcon(reviewIcon) - .commitLink(false) - .build(); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -237,9 +231,17 @@ void testPullRequestNoReview(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .prUpdaters(List.of(updater)).readyLabels(Set.of("rfr")) + .readyLabels(Set.of("rfr")) .readyComments(Map.of(reviewer.forge().currentUser().userName(), Pattern.compile("This is now ready"))) .build(); + var updater = IssueNotifier.newBuilder() + .issueProject(issueProject) + .reviewLink(false) + .reviewIcon(reviewIcon) + .commitLink(false) + .build(); + updater.attachTo(notifyBot); + // Initialize history TestBotRunner.runPeriodicItems(notifyBot); @@ -283,12 +285,6 @@ void testPullRequestPROnly(TestInfo testInfo) throws IOException { var issueProject = credentials.getIssueProject(); var reviewIcon = URI.create("http://www.example.com/review.png"); - var updater = IssueNotifier.newBuilder() - .issueProject(issueProject) - .reviewIcon(reviewIcon) - .commitLink(true) - .commitIcon(reviewIcon) - .build(); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -296,9 +292,15 @@ void testPullRequestPROnly(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .prUpdaters(List.of(updater)) .integratorId(repo.forge().currentUser().id()) .build(); + var updater = IssueNotifier.newBuilder() + .issueProject(issueProject) + .reviewIcon(reviewIcon) + .commitLink(true) + .commitIcon(reviewIcon) + .build(); + updater.attachTo(notifyBot); // Initialize history localRepo.push(localRepo.resolve("master").orElseThrow(), repo.url(), "other"); diff --git a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/json/JsonNotifierTests.java b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/json/JsonNotifierTests.java index 0948aec38..3b2c85275 100644 --- a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/json/JsonNotifierTests.java +++ b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/json/JsonNotifierTests.java @@ -62,7 +62,6 @@ void testJsonNotifierBranch(TestInfo testInfo) throws IOException { Files.createDirectory(jsonFolder); var storageFolder = tempFolder.path().resolve("storage"); - var updater = new JsonNotifier(jsonFolder, "12", "team"); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -70,9 +69,11 @@ void testJsonNotifierBranch(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) .build(); + var updater = new JsonNotifier(jsonFolder, "12", "team"); + updater.attachTo(notifyBot); + TestBotRunner.runPeriodicItems(notifyBot); assertEquals(List.of(), findJsonFiles(jsonFolder, "")); @@ -110,7 +111,6 @@ void testJsonNotifierTag(TestInfo testInfo) throws IOException { Files.createDirectory(jsonFolder); var storageFolder =tempFolder.path().resolve("storage"); - var updater = new JsonNotifier(jsonFolder, "12", "team"); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -118,9 +118,11 @@ void testJsonNotifierTag(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) .build(); + var updater = new JsonNotifier(jsonFolder, "12", "team"); + updater.attachTo(notifyBot); + TestBotRunner.runPeriodicItems(notifyBot); assertEquals(List.of(), findJsonFiles(jsonFolder, "")); diff --git a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifierTests.java b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifierTests.java index 9fdcf4aea..4266fb026 100644 --- a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifierTests.java +++ b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/mailinglist/MailingListNotifierTests.java @@ -58,6 +58,14 @@ void testMailingList(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -68,15 +76,7 @@ void testMailingList(TestInfo testInfo) throws IOException { .headers(Map.of("extra1", "value1", "extra2", "value2")) .allowedAuthorDomains(Pattern.compile("none")) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) - .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -130,14 +130,6 @@ void testMailingListMultiple(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); - var updater = MailingListNotifier.newBuilder() - .list(mailmanList) - .recipient(listAddress) - .sender(sender) - .reportNewTags(false) - .reportNewBranches(false) - .reportNewBuilds(false) - .build(); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -145,8 +137,16 @@ void testMailingListMultiple(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) .build(); + var updater = MailingListNotifier.newBuilder() + .list(mailmanList) + .recipient(listAddress) + .sender(sender) + .reportNewTags(false) + .reportNewBranches(false) + .reportNewBuilds(false) + .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -202,14 +202,6 @@ void testMailingListSponsored(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); - var updater = MailingListNotifier.newBuilder() - .list(mailmanList) - .recipient(listAddress) - .sender(sender) - .reportNewTags(false) - .reportNewBranches(false) - .reportNewBuilds(false) - .build(); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -217,8 +209,16 @@ void testMailingListSponsored(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) .build(); + var updater = MailingListNotifier.newBuilder() + .list(mailmanList) + .recipient(listAddress) + .sender(sender) + .reportNewTags(false) + .reportNewBranches(false) + .reportNewBuilds(false) + .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -267,6 +267,14 @@ void testMailingListMultipleBranches(TestInfo testInfo) throws IOException { var sender = EmailAddress.from("duke", "duke@duke.duke"); var author = EmailAddress.from("author", "author@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master|another")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -277,15 +285,7 @@ void testMailingListMultipleBranches(TestInfo testInfo) throws IOException { .reportNewBranches(false) .reportNewBuilds(false) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master|another")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) - .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -365,6 +365,14 @@ void testMailingListPROnlyMultipleBranches(TestInfo testInfo) throws IOException var sender = EmailAddress.from("duke", "duke@duke.duke"); var author = EmailAddress.from("author", "author@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master|other")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -376,15 +384,7 @@ void testMailingListPROnlyMultipleBranches(TestInfo testInfo) throws IOException .includeBranch(true) .mode(MailingListNotifier.Mode.PR) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master|other")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) - .build(); + updater.attachTo(notifyBot); // Populate our known branches localRepo.push(masterHash, repo.url(), "master", true); @@ -450,6 +450,14 @@ void testMailingListPR(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -459,15 +467,7 @@ void testMailingListPR(TestInfo testInfo) throws IOException { .reportNewBuilds(false) .mode(MailingListNotifier.Mode.PR) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) - .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -542,6 +542,14 @@ void testMailingListPROnce(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master|other")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -552,15 +560,7 @@ void testMailingListPROnce(TestInfo testInfo) throws IOException { .reportNewBuilds(false) .mode(MailingListNotifier.Mode.PR) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master|other")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) - .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -637,6 +637,14 @@ void testMailinglistTag(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -644,6 +652,8 @@ void testMailinglistTag(TestInfo testInfo) throws IOException { .reportNewBranches(false) .headers(Map.of("extra1", "value1", "extra2", "value2")) .build(); + updater.attachTo(notifyBot); + var noTagsUpdater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -652,15 +662,7 @@ void testMailinglistTag(TestInfo testInfo) throws IOException { .reportNewBranches(false) .reportNewBuilds(false) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater, noTagsUpdater)) - .build(); + noTagsUpdater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -754,6 +756,14 @@ void testMailinglistPlainTags(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -762,6 +772,7 @@ void testMailinglistPlainTags(TestInfo testInfo) throws IOException { .reportNewBuilds(false) .headers(Map.of("extra1", "value1", "extra2", "value2")) .build(); + updater.attachTo(notifyBot); var noTagsUpdater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -770,15 +781,7 @@ void testMailinglistPlainTags(TestInfo testInfo) throws IOException { .reportNewBranches(false) .reportNewBuilds(false) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater, noTagsUpdater)) - .build(); + noTagsUpdater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -847,14 +850,6 @@ void testMailingListBranch(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); - var updater = MailingListNotifier.newBuilder() - .list(mailmanList) - .recipient(listAddress) - .sender(sender) - .reportNewTags(false) - .reportNewBuilds(false) - .headers(Map.of("extra1", "value1", "extra2", "value2")) - .build(); var notifyBot = NotifyBot.newBuilder() .repository(repo) .storagePath(storageFolder) @@ -862,8 +857,16 @@ void testMailingListBranch(TestInfo testInfo) throws IOException { .tagStorageBuilder(tagStorage) .branchStorageBuilder(branchStorage) .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) .build(); + var updater = MailingListNotifier.newBuilder() + .list(mailmanList) + .recipient(listAddress) + .sender(sender) + .reportNewTags(false) + .reportNewBuilds(false) + .headers(Map.of("extra1", "value1", "extra2", "value2")) + .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot); @@ -927,6 +930,14 @@ void testMailingListNoIdempotence(TestInfo testInfo) throws IOException { var storageFolder = tempFolder.path().resolve("storage"); var sender = EmailAddress.from("duke", "duke@duke.duke"); + var notifyBot = NotifyBot.newBuilder() + .repository(repo) + .storagePath(storageFolder) + .branches(Pattern.compile("master")) + .tagStorageBuilder(tagStorage) + .branchStorageBuilder(branchStorage) + .prStateStorageBuilder(prStateStorage) + .build(); var updater = MailingListNotifier.newBuilder() .list(mailmanList) .recipient(listAddress) @@ -937,15 +948,7 @@ void testMailingListNoIdempotence(TestInfo testInfo) throws IOException { .headers(Map.of("extra1", "value1", "extra2", "value2")) .allowedAuthorDomains(Pattern.compile("none")) .build(); - var notifyBot = NotifyBot.newBuilder() - .repository(repo) - .storagePath(storageFolder) - .branches(Pattern.compile("master")) - .tagStorageBuilder(tagStorage) - .branchStorageBuilder(branchStorage) - .prStateStorageBuilder(prStateStorage) - .updaters(List.of(updater)) - .build(); + updater.attachTo(notifyBot); // No mail should be sent on the first run as there is no history TestBotRunner.runPeriodicItems(notifyBot);