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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,35 @@ 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 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().orElseThrow(
() -> new IllegalStateException("Link with title 'csr for' does not contain issue")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should throw an exception here. If we do, then a bad state in JBS will completely prevent the PullRequestBot from updating the status of the affected PR. I would prefer logging a warning and returning Optional.empty().

);
}
}
if (csr != null) {
return Issue.fromStringRelaxed(csr.id() + ": " + csr.title());
}
}
return Optional.empty();
}

private IssueProject issueProject() {
return workItem.bot.issueProject();
}
Expand Down
48 changes: 48 additions & 0 deletions bots/pr/src/test/java/org/openjdk/skara/bots/pr/CheckTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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);
Expand Down