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 1 commit
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
@@ -116,11 +116,32 @@ private List<Issue> issues() {
var issues = new ArrayList<Issue>();
issues.add(issue.get());
issues.addAll(SolvesTracker.currentSolved(pr.repository().forge().currentUser(), comments));
getCsrIssue(issue.get()).ifPresent(issues::add);
return issues;
}
return List.of();
}

private Optional<Issue> getCsrIssue(Issue issue) {
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().orElseThrow(
() -> new IllegalStateException("Link with title 'csr for' does not contain issue")
);
}
}
if (csr != null) {
return Issue.fromStringRelaxed(csr.id() + ": " + csr.title());
}
return Optional.empty();
}

private IssueProject issueProject() {
return workItem.bot.issueProject();
}
@@ -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"));

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

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