Skip to content
Permalink
Browse files
681: No (obvious) way to remove "test-request" label
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Jan 12, 2021
1 parent c24e546 commit 8f85cb4a90ce4107bad940a1c64320efd90cc422
@@ -329,6 +329,9 @@ public Collection<WorkItem> run(Path scratchPath) {
log.warning("Could not find check for job with " + jobId + " for hash " + hash + " for PR " + pr.webUrl());
}
}
if (pr.labels().contains(TEST_REQUEST_LABEL)) {
pr.removeLabel(TEST_REQUEST_LABEL);
}
} else if (stage == Stage.REQUESTED) {
var requestedJobs = state.requested().body().substring("/test".length());
if (requestedJobs.trim().isEmpty()) {
@@ -1200,4 +1200,102 @@ void pendingTestShouldHaveTestRequestLabel() throws IOException {
assertEquals(fourthComment, comments.get(3));
}
}

@Test
void cancelledPendingTestShouldNotHaveTestRequestLabel() throws IOException {
try (var tmp = new TemporaryDirectory()) {
var ci = new InMemoryContinuousIntegration();
var approvers = "0";
var available = List.of("tier1", "tier2", "tier3");
var defaultJobs = List.of("tier1");
var name = "test";
var storage = tmp.path().resolve("storage");
var scratch = tmp.path().resolve("storage");

var bot = HostUser.create(1, "bot", "openjdk [bot]");
var host = new InMemoryHost();
host.currentUserDetails = bot;

var repo = new InMemoryHostedRepository();
repo.host = host;

var pr = new InMemoryPullRequest();
pr.repository = repo;

var duke = HostUser.create(0, "duke", "Duke");
host.groups = Map.of(approvers, Set.of(duke));
pr.author = duke;
pr.headHash = new Hash("01234567890123456789012345789012345789");

var now = ZonedDateTime.now();
var comment = new Comment("0", "/test foobar", duke, now, now);
pr.comments = new ArrayList<>(List.of(comment));

var item = new TestWorkItem(ci, approvers, Set.of(), available, defaultJobs, name, storage, pr,
u -> false);

// Non-existing test group should result in error
item.run(scratch);

var comments = pr.comments();
assertEquals(2, comments.size());
assertEquals(comment, comments.get(0));

var secondComment = comments.get(1);
assertEquals(bot, secondComment.author());

var lines = secondComment.body().split("\n");
assertEquals(2, lines.length);
assertEquals("<!-- TEST ERROR -->", lines[0]);
assertEquals("@duke the test group foobar does not exist", lines[1]);

// Trying to test again should be fine
var thirdComment = new Comment("2", "/test tier1", duke, now, now);
pr.comments.add(thirdComment);
item.run(scratch);

comments = pr.comments();
assertEquals(4, comments.size());
assertEquals(comment, comments.get(0));
assertEquals(secondComment, comments.get(1));
assertEquals(thirdComment, comments.get(2));

var fourthComment = comments.get(3);
assertEquals(bot, fourthComment.author());

lines = fourthComment.body().split("\n");
assertEquals("<!-- TEST PENDING -->", lines[0]);
assertEquals("<!-- 01234567890123456789012345789012345789 -->", lines[1]);
assertEquals("<!-- tier1 -->", lines[2]);
assertEquals("@duke you need to get approval to run the tests in tier1 for commits up until 01234567",
lines[3]);

assertEquals(List.of("test-request"), pr.labels());

// Nothing should change if we run it yet again
item.run(scratch);

comments = pr.comments();
assertEquals(4, comments.size());
assertEquals(comment, comments.get(0));
assertEquals(secondComment, comments.get(1));
assertEquals(thirdComment, comments.get(2));
assertEquals(fourthComment, comments.get(3));

// Cancelling the test again should remove the test-request label
var fifthComment = new Comment("4", "/test cancel", duke, now, now);
pr.comments.add(fifthComment);
item.run(scratch);

comments = pr.comments();
assertEquals(5, comments.size());
assertEquals(comment, comments.get(0));
assertEquals(secondComment, comments.get(1));
assertEquals(thirdComment, comments.get(2));
assertEquals(fourthComment, comments.get(3));
assertEquals(fifthComment, comments.get(4));

assertEquals(List.of(), pr.labels());
}
}
}
@@ -50,6 +50,10 @@ public class GitPrTest {
.fullname("approve")
.helptext("Approve a test request")
.optional(),
Switch.shortcut("")
.fullname("cancel")
.helptext("Cancel a test request")
.optional(),
Switch.shortcut("")
.fullname("verbose")
.helptext("Turn on verbose output")
@@ -84,6 +88,8 @@ public static void main(String[] args) throws IOException, InterruptedException
var command = "/test";
if (arguments.contains("approve")) {
command += " approve";
} else if (arguments.contains("cancel")) {
command += " cancel";
} else if (arguments.contains("job")) {
command += arguments.get("job").asString();
}

1 comment on commit 8f85cb4

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 8f85cb4 Jan 12, 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.