Skip to content
Permalink
Browse files
934: Bots incorrectly assigned "build" label despite no obvious match…
…ing rule

Reviewed-by: erikj
  • Loading branch information
rwestberg committed Apr 15, 2021
1 parent e3b75ff commit 132acee4bac602881c45041e2800efc7fd7056bf
Showing 2 changed files with 57 additions and 2 deletions.
@@ -123,6 +123,57 @@ void match(TestInfo testInfo) throws IOException {
}
}

@Test
void copy(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory()) {
var author = credentials.getHostedRepository();
var reviewer = credentials.getHostedRepository();

var labelConfiguration = LabelConfigurationJson.builder()
.addMatchers("test1", List.of(Pattern.compile("a.txt")))
.addMatchers("test2", List.of(Pattern.compile("b.txt")))
.build();
var censusBuilder = credentials.getCensusBuilder()
.addAuthor(author.forge().currentUser().id())
.addReviewer(reviewer.forge().currentUser().id());
var labelBot = PullRequestBot.newBuilder()
.repo(author)
.censusRepo(censusBuilder.build())
.labelConfiguration(labelConfiguration)
.build();

// Populate the projects repository
var localRepoFolder = tempFolder.path();
var localRepo = CheckableRepository.init(localRepoFolder, author.repositoryType());
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, author.url(), "master", true);

// Add an unrelated file to master
var fileB = localRepoFolder.resolve("b.txt");
Files.writeString(fileB, "Hello");
localRepo.add(fileB);
var hashB = localRepo.commit("test1", "test", "test@test");
localRepo.push(hashB, author.url(), "master");

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash, author.url(), "edit", true);

var fileA = localRepoFolder.resolve("a.txt");
Files.writeString(fileA, "Hello");
localRepo.add(fileA);
var hashA = localRepo.commit("test1", "test", "test@test");
localRepo.push(hashA, author.url(), "edit");

var pr = credentials.createPullRequest(author, "master", "edit", "This is a pull request");

// Check the status - there should now be a test1 label
TestBotRunner.runPeriodicItems(labelBot);
assertEquals(Set.of("rfr", "test1"), new HashSet<>(pr.labelNames()));
}
}

@Test
void initialLabelCommand(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
@@ -186,8 +186,12 @@ public static Set<Path> changedFiles(PullRequest pr, Repository localRepo) throw
var ret = new HashSet<Path>();
var changes = localRepo.diff(baseHash(pr, localRepo), pr.headHash());
for (var patch : changes.patches()) {
patch.target().path().ifPresent(ret::add);
patch.source().path().ifPresent(ret::add);
if (patch.status().isDeleted() || patch.status().isRenamed()) {
patch.source().path().ifPresent(ret::add);
}
if (!patch.status().isDeleted()) {
patch.target().path().ifPresent(ret::add);
}
}
return ret;
}

1 comment on commit 132acee

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 132acee Apr 15, 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.