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

166: Update PR status in body with multiple issues if needed #265

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -263,27 +263,36 @@ private String getChecksList(PullRequestCheckIssueVisitor visitor) {
}
}

private String getStatusMessage(List<Review> reviews, PullRequestCheckIssueVisitor visitor) {
private String getStatusMessage(List<Comment> comments, List<Review> reviews, PullRequestCheckIssueVisitor visitor) {
var progressBody = new StringBuilder();
progressBody.append("## Progress\n");
progressBody.append(getChecksList(visitor));

var issue = Issue.fromString(pr.title());
if (issueProject != null && issue.isPresent()) {
progressBody.append("\n\n## Issue\n");
var iss = issueProject.issue(issue.get().id());
if (iss.isPresent()) {
progressBody.append("[");
progressBody.append(iss.get().id());
progressBody.append("](");
progressBody.append(iss.get().webUrl());
progressBody.append("): ");
progressBody.append(iss.get().title());
progressBody.append("\n");
} else {
progressBody.append("⚠️ Failed to retrieve information on issue `");
progressBody.append(issue.get().id());
progressBody.append("`.\n");
var allIssues = new ArrayList<Issue>();
allIssues.add(issue.get());
allIssues.addAll(SolvesTracker.currentSolved(pr.repository().forge().currentUser(), comments));
progressBody.append("\n\n## Issue");
if (allIssues.size() > 1) {
progressBody.append("s");
}
progressBody.append("\n");
for (var currentIssue : allIssues) {
var iss = issueProject.issue(currentIssue.id());
if (iss.isPresent()) {
progressBody.append("[");
progressBody.append(iss.get().id());
progressBody.append("](");
progressBody.append(iss.get().webUrl());
progressBody.append("): ");
progressBody.append(iss.get().title());
progressBody.append("\n");
} else {
progressBody.append("⚠️ Failed to retrieve information on issue `");
progressBody.append(currentIssue.id());
progressBody.append("`.\n");
}
}
}

@@ -477,7 +486,7 @@ private void checkStatus() {
updateReadyForReview(visitor, additionalErrors);

// Calculate and update the status message if needed
var statusMessage = getStatusMessage(activeReviews, visitor);
var statusMessage = getStatusMessage(comments, activeReviews, visitor);
var updatedBody = updateStatusMessage(statusMessage);

// Post / update approval messages (only needed if the review itself can't contain a body)
@@ -44,7 +44,7 @@
private final Map<String, String> blockingLabels;
private final IssueProject issueProject;

private final Pattern metadataComments = Pattern.compile("<!-- (?:(add|remove) contributor)|(?:summary: ')");
private final Pattern metadataComments = Pattern.compile("<!-- (?:(add|remove) contributor)|(?:summary: ')|(?:solves: ')");
private final Logger log = Logger.getLogger("org.openjdk.skara.bots.pr");

CheckWorkItem(PullRequest pr, HostedRepository censusRepo, String censusRef, Map<String, String> blockingLabels,
@@ -29,7 +29,7 @@
import org.openjdk.skara.vcs.Repository;

import java.io.IOException;
import java.util.List;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.openjdk.skara.bots.pr.PullRequestAsserts.assertLastCommentContains;
@@ -191,7 +191,6 @@ void issueInTitle(TestInfo testInfo) throws IOException {
var tempFolder = new TemporaryDirectory()) {
var author = credentials.getHostedRepository();
var integrator = credentials.getHostedRepository();
var external = credentials.getHostedRepository();

var censusBuilder = credentials.getCensusBuilder()
.addAuthor(author.forge().currentUser().id());
@@ -229,4 +228,52 @@ void issueInTitle(TestInfo testInfo) throws IOException {
assertEquals("1234: Yes this is an issue", updatedPr.title());
}
}

@Test
void issueInBody(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 = new PullRequestBot(integrator, censusBuilder.build(), "master",
Map.of(), Map.of(), Map.of(), Set.of(), Map.of(), issues);

// 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"));
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"));

// Add an extra issue
var issue2 = issues.createIssue("Second", List.of("There"));
pr.addComment("/solves " + issue2.id() + ": Description");

// Check that the body was updated
TestBotRunner.runPeriodicItems(prBot);
TestBotRunner.runPeriodicItems(prBot);
assertTrue(pr.body().contains(issue1.id()));
assertTrue(pr.body().contains("First"));
assertTrue(pr.body().contains(issue2.id()));
assertTrue(pr.body().contains("Second"));
assertFalse(pr.body().contains("## Issue\n"));
assertTrue(pr.body().contains("## Issues\n"));
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.