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

286: Add a link to CSR in the PR's first comment #1244

Closed
wants to merge 6 commits into from
Closed
Changes from 3 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
@@ -110,17 +110,41 @@ private boolean isTargetBranchAllowed() {
return matcher.matches();
}

private List<Issue> issues() {
private List<Issue> issues(boolean withCsr) {
var issue = Issue.fromStringRelaxed(pr.title());
if (issue.isPresent()) {
var issues = new ArrayList<Issue>();
issues.add(issue.get());
issues.addAll(SolvesTracker.currentSolved(pr.repository().forge().currentUser(), comments));
if (withCsr) {
getCsrIssue(issue.get()).ifPresent(issues::add);
}
return issues;
}
return List.of();
}

private Optional<Issue> getCsrIssue(Issue issue) {
var issueProject = issueProject();
if (issueProject != null) {
var jbsIssue = issueProject.issue(issue.shortId());
if (jbsIssue.isEmpty()) {
return Optional.empty();
}
org.openjdk.skara.issuetracker.Issue csr = null;
for (var link : jbsIssue.get().links()) {
var relationship = link.relationship();
if (relationship.isPresent() && relationship.get().equals("csr for")) {
csr = link.issue().orElse(null);
}
}
if (csr != null) {
return Issue.fromStringRelaxed(csr.id() + ": " + csr.title());
}
}
return Optional.empty();
}

private IssueProject issueProject() {
return workItem.bot.issueProject();
}
@@ -182,7 +206,7 @@ private Map<String, String> blockingIntegrationLabels() {
private List<String> botSpecificIntegrationBlockers() {
var ret = new ArrayList<String>();

var issues = issues();
var issues = issues(false);
var issueProject = issueProject();
if (issueProject != null) {
for (var currentIssue : issues) {
@@ -454,7 +478,7 @@ private String getStatusMessage(List<Comment> comments, List<Review> reviews, Pu
progressBody.append(warningListToText(integrationBlockers));
}

var issues = issues();
var issues = issues(true);
var issueProject = issueProject();
if (issueProject != null && !issues.isEmpty()) {
progressBody.append("\n\n### Issue");
@@ -480,6 +504,10 @@ private String getStatusMessage(List<Comment> comments, List<Review> reviews, Pu
progressBody.append(iss.get().webUrl());
progressBody.append("): ");
progressBody.append(iss.get().title());
var issueType = iss.get().properties().get("issuetype");
if (issueType != null && "CSR".equals(issueType.asString())) {
progressBody.append(" (**CSR**)");
}
if (!relaxedEquals(iss.get().title(), currentIssue.description())) {
progressBody.append(" ⚠️ Title mismatch between PR and JBS.");
setExpiration(Duration.ofMinutes(10));
@@ -24,6 +24,7 @@

import org.junit.jupiter.api.*;
import org.openjdk.skara.forge.*;
import org.openjdk.skara.issuetracker.Link;
import org.openjdk.skara.json.JSON;
import org.openjdk.skara.test.*;

@@ -1126,6 +1127,53 @@ void issueInSummaryExternalUpdate(TestInfo testInfo) throws IOException {
}
}

@Test
void issueWithCsr(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
var tempFolder = new TemporaryDirectory()) {
var author = credentials.getHostedRepository();
var reviewer = credentials.getHostedRepository();
var bot = credentials.getHostedRepository();
var issues = credentials.getIssueProject();
var censusBuilder = credentials.getCensusBuilder()
.addAuthor(author.forge().currentUser().id())
.addReviewer(reviewer.forge().currentUser().id());
var checkBot = PullRequestBot.newBuilder().repo(bot).issueProject(issues)
.censusRepo(censusBuilder.build()).build();

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.repositoryType(),
Path.of("appendable.txt"), Set.of("issues"), null);
var masterHash = localRepo.resolve("master").orElseThrow();
localRepo.push(masterHash, author.url(), "master", true);

var mainIssue = issues.createIssue("The main issue", List.of("main"), Map.of("issuetype", JSON.of("Bug")));
var csrIssue = issues.createIssue("The csr issue", List.of("csr"), Map.of("issuetype", JSON.of("CSR")));

// Make a change with a corresponding PR
var editHash = CheckableRepository.appendAndCommit(localRepo);
localRepo.push(editHash, author.url(), "edit", true);
var pr = credentials.createPullRequest(author, "master", "edit", mainIssue.id() + ": " + mainIssue.title());

// PR should have one issue
TestBotRunner.runPeriodicItems(checkBot);
assertTrue(pr.body().contains("### Issue"));
assertFalse(pr.body().contains("### Issues"));
assertTrue(pr.body().contains("The main issue"));
assertFalse(pr.body().contains("The csr issue (**CSR**)"));

// Require CSR
mainIssue.addLink(Link.create(csrIssue, "csr for").build());
pr.addComment("/csr");

// PR should have two issues
TestBotRunner.runPeriodicItems(checkBot);
assertTrue(pr.body().contains("### Issues"));
assertTrue(pr.body().contains("The main issue"));
assertTrue(pr.body().contains("The csr issue (**CSR**)"));
}
}

@Test
void cancelCheck(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);