Skip to content
Permalink
Browse files
Allow targeting non-open issues with the label command
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Nov 5, 2020
1 parent 5b49aac commit 5045eeb5550cc4759bf9d230dbbcadbdf940b9d6
Showing 3 changed files with 77 additions and 4 deletions.
@@ -587,6 +587,12 @@ private String getStatusMessage(List<Comment> comments, List<Review> reviews, Pu
progressBody.append(" ⚠️ Title mismatch between PR and JBS.");
setExpiration(Duration.ofMinutes(10));
}
if (iss.get().state() != org.openjdk.skara.issuetracker.Issue.State.OPEN) {
if (!pr.labels().contains("backport")) {
progressBody.append(" ⚠️ Issue is not open.");
}
continue;
}
progressBody.append("\n");
} else {
progressBody.append("⚠️ Failed to retrieve information on issue `");
@@ -139,10 +139,6 @@ private void addIssue(PullRequestBot bot, PullRequest pr, String args, Set<Strin
reply.println("The issue `" + issue.shortId() + "` was not found in the `" + bot.issueProject().name() + "` project - make sure you have entered it correctly.");
continue;
}
if (validatedIssue.get().state() != org.openjdk.skara.issuetracker.Issue.State.OPEN) {
reply.println("The issue [" + validatedIssue.get().id() + "](" + validatedIssue.get().webUrl() + ") isn't open - make sure you have selected the correct issue.");
continue;
}
if (issue.description() == null) {
validatedIssues.add(new Issue(validatedIssue.get().id(), validatedIssue.get().title()));
} else {
@@ -385,6 +385,77 @@ void issueInBody(TestInfo testInfo) throws IOException {
}
}

@Test
void closedIssue(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory()) {
var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();
var issues = credentials.getIssueProject();

var censusBuilder = credentials.getCensusBuilder()
.addAuthor(author.forge().currentUser().id());
var prBot = PullRequestBot.newBuilder().repo(integrator).censusRepo(censusBuilder.build()).issueProject(issues).build();

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

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash, author.url(), "edit", true);
var issue1 = issues.createIssue("First", List.of("Hello"), Map.of());
issue1.setState(Issue.State.RESOLVED);
var pr = credentials.createPullRequest(author, "master", "edit",
issue1.id() + ": This is a pull request");

// First check
TestBotRunner.runPeriodicItems(prBot);
assertTrue(pr.body().contains(issue1.id()));
assertTrue(pr.body().contains("First"));
assertTrue(pr.body().contains("## Issue\n"));
assertTrue(pr.body().contains("Issue is not open"));
}
}

@Test
void closedIssueBackport(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory()) {
var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();
var issues = credentials.getIssueProject();

var censusBuilder = credentials.getCensusBuilder()
.addAuthor(author.forge().currentUser().id());
var prBot = PullRequestBot.newBuilder().repo(integrator).censusRepo(censusBuilder.build()).issueProject(issues).build();

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

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash, author.url(), "edit", true);
var issue1 = issues.createIssue("First", List.of("Hello"), Map.of());
issue1.setState(Issue.State.RESOLVED);
var pr = credentials.createPullRequest(author, "master", "edit",
issue1.id() + ": This is a pull request");
pr.addLabel("backport");

// First check
TestBotRunner.runPeriodicItems(prBot);
assertTrue(pr.body().contains(issue1.id()));
assertTrue(pr.body().contains("First"));
assertTrue(pr.body().contains("## Issue\n"));
assertFalse(pr.body().contains("Issue is not open"));
}
}

private static final Pattern addedIssuePattern = Pattern.compile("`(.*)` was successfully created", Pattern.MULTILINE);

private static Issue issueFromLastComment(PullRequest pr, IssueProject issueProject) {

1 comment on commit 5045eeb

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 5045eeb Nov 5, 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.