diff --git a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/IssueUpdater.java b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/IssueUpdater.java index 117c4565a..00f5cf9e0 100644 --- a/bots/notify/src/main/java/org/openjdk/skara/bots/notify/IssueUpdater.java +++ b/bots/notify/src/main/java/org/openjdk/skara/bots/notify/IssueUpdater.java @@ -22,6 +22,7 @@ */ package org.openjdk.skara.bots.notify; +import org.openjdk.skara.email.EmailAddress; import org.openjdk.skara.forge.*; import org.openjdk.skara.issuetracker.Issue; import org.openjdk.skara.issuetracker.*; @@ -216,6 +217,20 @@ private Issue findIssue(Issue primary, String fixVersion) { return createBackportIssue(primary); } + private Optional findIssueUsername(Commit commit) { + var authorEmail = EmailAddress.from(commit.author().email()); + if (authorEmail.domain().equals("openjdk.org")) { + return Optional.of(authorEmail.localPart()); + } + + var committerEmail = EmailAddress.from(commit.committer().email()); + if (!committerEmail.domain().equals("openjdk.org")) { + log.severe("Cannot determine issue tracker user name from committer email: " + committerEmail); + return Optional.empty(); + } + return Optional.of(committerEmail.localPart()); + } + @Override public void handleCommits(HostedRepository repository, Repository localRepository, List commits, Branch branch) { for (var commit : commits) { @@ -267,7 +282,16 @@ public void handleCommits(HostedRepository repository, Repository localRepositor if (!alreadyPostedComment) { issue.addComment(commitNotification); } - issue.setState(Issue.State.RESOLVED); + if (issue.state() == Issue.State.OPEN) { + issue.setState(Issue.State.RESOLVED); + if (issue.assignees().isEmpty()) { + var username = findIssueUsername(commit); + if (username.isPresent()) { + var assignee = issueProject.issueTracker().user(username.get()); + issue.setAssignees(List.of(assignee)); + } + } + } if (commitLink) { var linkBuilder = Link.create(repository.webUrl(commit.hash()), "Commit") diff --git a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java index 931467d97..0666e906d 100644 --- a/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java +++ b/bots/notify/src/test/java/org/openjdk/skara/bots/notify/UpdaterTests.java @@ -926,19 +926,22 @@ void testIssue(TestInfo testInfo) throws IOException { TestBotRunner.runPeriodicItems(notifyBot); // Create an issue and commit a fix + var authorEmailAddress = issueProject.issueTracker().currentUser().userName() + "@openjdk.org"; var issue = issueProject.createIssue("This is an issue", List.of("Indeed"), Map.of("issuetype", JSON.of("Enhancement"))); - var editHash = CheckableRepository.appendAndCommit(localRepo, "Another line", issue.id() + ": Fix that issue"); + var editHash = CheckableRepository.appendAndCommit(localRepo, "Another line", issue.id() + ": Fix that issue", "Duke", authorEmailAddress); localRepo.push(editHash, repo.url(), "master"); TestBotRunner.runPeriodicItems(notifyBot); // The changeset should be reflected in a comment - var comments = issue.comments(); + var updatedIssue = issueProject.issue(issue.id()).orElseThrow(); + + var comments = updatedIssue.comments(); assertEquals(1, comments.size()); var comment = comments.get(0); assertTrue(comment.body().contains(editHash.abbreviate())); // And in a link - var links = issue.links(); + var links = updatedIssue.links(); assertEquals(1, links.size()); var link = links.get(0); assertEquals(commitIcon, link.iconUrl().orElseThrow()); @@ -946,7 +949,11 @@ void testIssue(TestInfo testInfo) throws IOException { assertEquals(repo.webUrl(editHash), link.uri().orElseThrow()); // As well as a fixVersion - assertEquals(Set.of("0.1"), fixVersions(issue)); + assertEquals(Set.of("0.1"), fixVersions(updatedIssue)); + + // The issue should be assigned and resolved + assertEquals(RESOLVED, updatedIssue.state()); + assertEquals(List.of(issueProject.issueTracker().currentUser()), updatedIssue.assignees()); } } @@ -1200,7 +1207,8 @@ void testIssueBackport(TestInfo testInfo) throws IOException { issue.setProperty("fixVersions", JSON.array().add("13.0.1")); issue.setProperty("priority", JSON.of("1")); - var editHash = CheckableRepository.appendAndCommit(localRepo, "Another line", issue.id() + ": Fix that issue"); + var authorEmailAddress = issueProject.issueTracker().currentUser().userName() + "@openjdk.org"; + var editHash = CheckableRepository.appendAndCommit(localRepo, "Another line", issue.id() + ": Fix that issue", "Duke", authorEmailAddress); localRepo.push(editHash, repo.url(), "master"); TestBotRunner.runPeriodicItems(notifyBot); @@ -1208,6 +1216,7 @@ void testIssueBackport(TestInfo testInfo) throws IOException { var updatedIssue = issueProject.issue(issue.id()).orElseThrow(); assertEquals(Set.of("13.0.1"), fixVersions(updatedIssue)); assertEquals(OPEN, updatedIssue.state()); + assertEquals(List.of(), updatedIssue.assignees()); // There should be a link var links = updatedIssue.links(); @@ -1215,9 +1224,10 @@ void testIssueBackport(TestInfo testInfo) throws IOException { var link = links.get(0); var backport = link.issue().orElseThrow(); - // The backport issue should have a correct fixVersion + // The backport issue should have a correct fixVersion and assignee assertEquals(Set.of("12.0.2"), fixVersions(backport)); assertEquals(RESOLVED, backport.state()); + assertEquals(List.of(issueProject.issueTracker().currentUser()), backport.assignees()); // Custom properties should also propagate assertEquals("1", backport.properties().get("priority").asString());