Skip to content
Browse files
1095: Ignore tags in pr branches when notifying
Reviewed-by: kcr
  • Loading branch information
erikj79 committed Jul 6, 2021
1 parent 8801187 commit ac074bcc465d8368e2c22d8cdfdfa4615e514067
@@ -208,6 +208,12 @@ private List<Throwable> handleTags(Repository localRepo, UpdateHistory history,
return errors;

// Filter for tags that appear in non pr-branches
var branches = repository.branches();
newTags =
.filter(tag -> tagInNonPrBranch(tag, branches, localRepo))

var allJdkTags =
@@ -295,6 +301,22 @@ private List<Throwable> handleTags(Repository localRepo, UpdateHistory history,
return errors;

private boolean tagInNonPrBranch(Tag tag, List<HostedBranch> branches, Repository localRepository) {
try {
for (var branch : branches) {
if (!PreIntegrations.isPreintegrationBranch( {
var hash = localRepository.resolve(tag).orElseThrow();
if (localRepository.isAncestor(hash, branch.hash())) {
return true;
} catch (IOException e) {
throw new UncheckedIOException(e);
return false;

public boolean concurrentWith(WorkItem other) {
if (!(other instanceof RepositoryWorkItem)) {
@@ -0,0 +1,101 @@
package org.openjdk.skara.bots.notify;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.openjdk.skara.forge.HostedRepository;
import org.openjdk.skara.test.*;
import org.openjdk.skara.vcs.*;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openjdk.skara.bots.notify.TestUtils.createBranchStorage;
import static org.openjdk.skara.bots.notify.TestUtils.createTagStorage;

public class RepositoryWorkItemTests {

private static class TestNotifier implements RepositoryListener {

private final List<Tag> newTags = new ArrayList<>();

public void onNewTagCommit(HostedRepository repository, Repository localRepository,
Path scratchPath, Commit commit, Tag tag, Tag.Annotated annotation) {

public String name() {
return "test";

public boolean idempotent() {
return true;

* Tests that the NotifierBot skips notifying on tags that only show up in
* pr branches.
void filterTagsInNonPrBranches(TestInfo testInfo) throws IOException {
try (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.repositoryType());

var tagStorage = createTagStorage(repo);
var branchStorage = createBranchStorage(repo);
var storageFolder = tempFolder.path().resolve("storage");

var notifyBot = NotifyBot.newBuilder()
var testNotifier = new TestNotifier();

// Create an initial tag to start history tracking. The notifier will never notify the first tag
var masterHash = localRepo.head();
localRepo.tag(masterHash, "initial-tag", "Tagging initial tag", "testauthor", "ta@none.none");
localRepo.push(masterHash, repo.url(), "master", false, true);

// Run bot to initialize notification history

// Create a "pr"-branch with a commit in it and tag that commit
var prBranchHash = CheckableRepository.appendAndCommit(localRepo, "Another line", "Change in pr branch");
localRepo.tag(prBranchHash, "pr-tag", "Tagging change in pr branch", "testauthor", "ta@none.none");
localRepo.push(prBranchHash, repo.url(), "pr/4711", false, true);

// Run the bot and verify that notifier is not called
assertTrue(testNotifier.newTags.isEmpty(), "Notifier called on pr branch: " + testNotifier.newTags);

// Create a commit in master branch and tag it
var masterTaggedHash = CheckableRepository.appendAndCommit(localRepo, "Master line", "Change in master branch");
localRepo.tag(masterTaggedHash, "master-tag", "Tagging change in master branch", "testauthor", "ta@none.none");
localRepo.push(masterTaggedHash, repo.url(), "master", false, true);

// Run the bot and verify that notifier is called for master branch
assertEquals(testNotifier.newTags.size(), 1, "Notifier not called on master branch: " + testNotifier.newTags);
assertEquals("master-tag", testNotifier.newTags.get(0).name(), "Notified wrong tag");

1 comment on commit ac074bc

Copy link

@openjdk-notifier openjdk-notifier bot commented on ac074bc Jul 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.