Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow targeting non-open issues with the label command #943

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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) {