Skip to content
Permalink
Browse files

610: Add support for other issue tracker email addresses than @openjd…

…k.org

Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Sep 7, 2020
1 parent 05b7064 commit 4a6a45bdb59f51a615f8f62e970964a7d28c157b
@@ -77,14 +77,25 @@ static IssueNotifierBuilder newBuilder() {
var authorEmail = EmailAddress.from(commit.author().email());
if (authorEmail.domain().equals("openjdk.org")) {
return Optional.of(authorEmail.localPart());
} else {
var user = issueProject.findUser(authorEmail.address());
if (user.isPresent()) {
return Optional.of(user.get().userName());
}
}

var committerEmail = EmailAddress.from(commit.committer().email());
if (!committerEmail.domain().equals("openjdk.org")) {
if (committerEmail.domain().equals("openjdk.org")) {
return Optional.of(committerEmail.localPart());
} else {
var user = issueProject.findUser(committerEmail.address());
if (user.isPresent()) {
return Optional.of(user.get().userName());
}

log.severe("Cannot determine issue tracker user name from committer email: " + committerEmail);
return Optional.empty();
}
return Optional.of(committerEmail.localPart());
}

@Override
@@ -408,6 +408,49 @@ void testIssue(TestInfo testInfo) throws IOException {
}
}

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

var repo = credentials.getHostedRepository();
var repoFolder = tempFolder.path().resolve("repo");
var localRepo = CheckableRepository.init(repoFolder, repo.repositoryType());
credentials.commitLock(localRepo);
localRepo.pushAll(repo.url());

var issueProject = credentials.getIssueProject();
var storageFolder = tempFolder.path().resolve("storage");
var jbsNotifierConfig = JSON.object().put("fixversions", JSON.object());
var notifyBot = testBotBuilder(repo, issueProject, storageFolder, jbsNotifierConfig).create("notify", JSON.object());

// Initialize history
TestBotRunner.runPeriodicItems(notifyBot);

// Create an issue and commit a fix
var authorEmailAddress = issueProject.issueTracker().currentUser().userName() + "@otherjdk.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", "Duke", authorEmailAddress);
localRepo.push(editHash, repo.url(), "master");
TestBotRunner.runPeriodicItems(notifyBot);

// The changeset should be reflected in a comment
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()));

// As well as a fixVersion
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());
}
}

@Test
void testIssueNoVersion(TestInfo testInfo) throws IOException {
try (var credentials = new HostCredentials(testInfo);
@@ -22,6 +22,7 @@
*/
package org.openjdk.skara.issuetracker;

import org.openjdk.skara.host.HostUser;
import org.openjdk.skara.json.JSONValue;

import java.net.URI;
@@ -34,4 +35,5 @@
Optional<Issue> issue(String id);
List<Issue> issues();
String name();
Optional<HostUser> findUser(String findBy);
}
@@ -22,6 +22,7 @@
*/
package org.openjdk.skara.issuetracker.jira;

import org.openjdk.skara.host.HostUser;
import org.openjdk.skara.issuetracker.*;
import org.openjdk.skara.json.*;
import org.openjdk.skara.network.*;
@@ -386,4 +387,24 @@ public Issue createIssue(String title, List<String> body, Map<String, JSONValue>
public String name() {
return projectName.toUpperCase();
}

@Override
public Optional<HostUser> findUser(String findBy) {
var user = request.get("user/search")
.param("username", findBy)
.onError(r -> r.statusCode() == 404 ? Optional.of(JSON.object().put("NOT_FOUND", true)) : Optional.empty())
.execute();
if (user.contains("NOT_FOUND")) {
return Optional.empty();
}
if (user.asArray().size() != 1) {
log.severe("Multiple results returned for user query: " + findBy);
return Optional.empty();
}
var data = user.asArray().get(0);
return Optional.of(new HostUser(data.get("name").asString(),
data.get("name").asString(),
data.get("displayName").asString(),
data.get("emailAddresss").asString()));
}
}
@@ -22,6 +22,7 @@
*/
package org.openjdk.skara.test;

import org.openjdk.skara.email.EmailAddress;
import org.openjdk.skara.forge.*;
import org.openjdk.skara.host.*;
import org.openjdk.skara.issuetracker.*;
@@ -129,6 +130,14 @@ public IssueProject project(String name) {
.findAny();
}

Optional<HostUser> findUser(String findBy) {
var findByLocalPart = EmailAddress.parse(findBy).localPart();
return data.users.stream()
.filter(user -> user.userName().equals(findBy) ||
user.userName().equals(findByLocalPart))
.findAny();
}

@Override
public HostUser currentUser() {
return data.users.get(currentUser);
@@ -22,6 +22,7 @@
*/
package org.openjdk.skara.test;

import org.openjdk.skara.host.HostUser;
import org.openjdk.skara.issuetracker.*;
import org.openjdk.skara.json.JSONValue;
import org.openjdk.skara.network.URIBuilder;
@@ -75,4 +76,9 @@ public Issue createIssue(String title, List<String> body, Map<String, JSONValue>
public String name() {
return projectName.toUpperCase();
}

@Override
public Optional<HostUser> findUser(String findBy) {
return host.findUser(findBy);
}
}

1 comment on commit 4a6a45b

@bridgekeeper

This comment has been minimized.

Copy link

@bridgekeeper bridgekeeper bot commented on 4a6a45b Sep 7, 2020

Please sign in to comment.