Skip to content
Permalink
Browse files
689: Do not automatically adjust labels after users intervenes
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Sep 17, 2020
1 parent aa02b31 commit d7cdb985412682ddb90d3a1d5a693825a0b027fc
Showing 2 changed files with 17 additions and 22 deletions.
@@ -115,6 +115,17 @@ public Collection<WorkItem> run(Path scratchPath) {
if (bot.labelConfiguration().allowed().isEmpty()) {
return List.of();
}

var comments = pr.comments();
var manuallyAdded = LabelTracker.currentAdded(pr.repository().forge().currentUser(), comments);
var manuallyRemoved = LabelTracker.currentRemoved(pr.repository().forge().currentUser(), comments);

// If a manual label command has been issued before we have done any labeling,
// that is considered to be a request to override any automatic labelling
if (manuallyAdded.size() > 0 || manuallyRemoved.size() > 0) {
return List.of();
}

try {
var path = scratchPath.resolve("pr").resolve("labeler").resolve(pr.repository().name());
var seedPath = bot.seedStorage().orElse(scratchPath.resolve("seeds"));
@@ -125,15 +136,6 @@ public Collection<WorkItem> run(Path scratchPath) {
.filter(key -> bot.labelConfiguration().allowed().contains(key))
.collect(Collectors.toSet());

var comments = pr.comments();
var manuallyAdded = LabelTracker.currentAdded(pr.repository().forge().currentUser(), comments);
var manuallyRemoved = LabelTracker.currentRemoved(pr.repository().forge().currentUser(), comments);

// If a manual label command has been issued before we have done any labeling,
// that is considered to be a request to override any automatic labelling
if (bot.currentLabels().isEmpty() && !(manuallyAdded.isEmpty() && manuallyRemoved.isEmpty())) {
return List.of();
}

// Add all labels not already set that are not manually removed
var labelsToAdd = newLabels.stream()
@@ -166,33 +166,26 @@ void adjustAutoApplied(TestInfo testInfo) throws IOException {
assertLastCommentContains(pr, "The following label will be automatically applied");
assertLastCommentContains(pr, "`2`");

// It will refuse to remove it
// The bot will remove the label
pr.addComment("/label remove 2");
TestBotRunner.runPeriodicItems(prBot);
assertLastCommentContains(pr, "The `2` label was successfully removed.");

// Add another file to trigger a group match
// Add another file that would have trigger a group match
Files.writeString(localRepoFolder.resolve("test.cpp"), "Hello there");
localRepo.add(Path.of("test.cpp"));
editHash = localRepo.commit("Another one", "duke", "duke@openjdk.org");
localRepo.push(editHash, author.url(), "edit");

// The bot should have applied more labels automatically (but not the manually removed)
TestBotRunner.runPeriodicItems(prBot);
assertEquals(Set.of("group", "rfr"), new HashSet<>(pr.labels()));

// Remove one of these as well
pr.addComment("/label remove group");
// The bot should not apply labels since the user has manually removed labels
TestBotRunner.runPeriodicItems(prBot);
assertLastCommentContains(pr, "The `group` label was successfully removed.");
assertEquals(Set.of("rfr"), new HashSet<>(pr.labels()));

// Adding them back again is fine
pr.addComment("/label add group 1");
// Adding the label manually is fine
pr.addComment("/label add group");
TestBotRunner.runPeriodicItems(prBot);
assertLastCommentContains(pr, "The `group` label was successfully added.");
assertLastCommentContains(pr, "The `1` label was successfully added.");
assertEquals(Set.of("1", "group", "rfr"), new HashSet<>(pr.labels()));
assertEquals(Set.of("group", "rfr"), new HashSet<>(pr.labels()));
}
}

1 comment on commit d7cdb98

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on d7cdb98 Sep 17, 2020

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.