diff options
author | jonmv <venstad@gmail.com> | 2022-04-30 22:07:40 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-05-02 12:02:02 +0200 |
commit | 5d947080f29cd1e3e4ea35afe099cffbb54212a7 (patch) | |
tree | 80503ca7545d39eaec0e1658461dbf4e9d117e3b /controller-api | |
parent | 741a0f5e87fe39dce271b2a35b6c2cf987f94ca6 (diff) |
Make IssueInfo public, and support attachments for Issues
Diffstat (limited to 'controller-api')
3 files changed, 101 insertions, 5 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/IssueHandler.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/IssueHandler.java index dc8b22ac32d..8123b6f2ce6 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/IssueHandler.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/IssueHandler.java @@ -2,8 +2,13 @@ package com.yahoo.vespa.hosted.controller.api.integration.organization; +import com.yahoo.vespa.hosted.controller.api.integration.jira.JiraIssue; + +import java.io.InputStream; import java.time.Duration; +import java.util.List; import java.util.Optional; +import java.util.function.Supplier; /** * @author jonmv @@ -19,12 +24,22 @@ public interface IssueHandler { IssueId file(Issue issue); /** + * Returns all open issues similar to the given. + * + * @param issue The issue to search for; relevant fields are the summary and the owner (propertyId). + * @return All open, similar issues. + */ + List<IssueInfo> findAllBySimilarity(Issue issue); + + /** * Returns the ID of this issue, if it exists and is open, based on a similarity search. * * @param issue The issue to search for; relevant fields are the summary and the owner (propertyId). * @return ID of the issue, if it is found. */ - Optional<IssueId> findBySimilarity(Issue issue); + default Optional<IssueId> findBySimilarity(Issue issue) { + return findAllBySimilarity(issue).stream().findFirst().map(IssueInfo::id); + } /** * Update the description of the issue with the given ID. @@ -108,4 +123,8 @@ public interface IssueHandler { * @throws RuntimeException exception if project not found */ ProjectInfo projectInfo(String projectKey); + + /** Upload an attachment to the issue, with indicated filename, from the given input stream. */ + void addAttachment(IssueId id, String filename, Supplier<InputStream> contentAsStream); + } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/IssueInfo.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/IssueInfo.java new file mode 100644 index 00000000000..52c022bebdf --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/IssueInfo.java @@ -0,0 +1,65 @@ +package com.yahoo.vespa.hosted.controller.api.integration.organization; + +import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId; +import com.yahoo.vespa.hosted.controller.api.integration.organization.User; + +import java.time.Instant; +import java.util.Optional; + +/** + * Information about a stored issue. + * + * @author jonmv + */ +public class IssueInfo { + + private final IssueId id; + private final Instant updated; + private final Status status; + private final User assignee; + + public IssueInfo(IssueId id, Instant updated, Status status, User assignee) { + this.id = id; + this.updated = updated; + this.status = status; + this.assignee = assignee; + } + + public IssueId id() { + return id; + } + + public Instant updated() { + return updated; + } + + public Status status() { + return status; + } + + public Optional<User> assignee() { + return Optional.ofNullable(assignee); + } + + + public enum Status { + + toDo("To Do"), + inProgress("In Progress"), + done("Done"), + noCategory("No Category"); + + private final String value; + + Status(String value) { this.value = value; } + + public static Status fromValue(String value) { + for (Status status : Status.values()) + if (status.value.equals(value)) + return status; + throw new IllegalArgumentException(value + " is not a valid status."); + } + + } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/MockIssueHandler.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/MockIssueHandler.java index 257d2ff5e67..a62f43d1cf5 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/MockIssueHandler.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/MockIssueHandler.java @@ -2,7 +2,9 @@ package com.yahoo.vespa.hosted.controller.api.integration.organization; import com.google.inject.Inject; +import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueInfo.Status; +import java.io.InputStream; import java.net.URI; import java.time.Clock; import java.time.Duration; @@ -14,6 +16,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Supplier; import java.util.stream.Collectors; /** @@ -24,6 +27,7 @@ public class MockIssueHandler implements IssueHandler { private final Clock clock; private final AtomicLong counter = new AtomicLong(); private final Map<IssueId, MockIssue> issues = new HashMap<>(); + private final Map<IssueId, Map<String, InputStream>> attachments = new HashMap<>(); private final Map<String, ProjectInfo> projects = new HashMap<>(); @Inject @@ -45,11 +49,14 @@ public class MockIssueHandler implements IssueHandler { } @Override - public Optional<IssueId> findBySimilarity(Issue issue) { + public List<IssueInfo> findAllBySimilarity(Issue issue) { return issues.entrySet().stream() - .filter(entry -> entry.getValue().issue.summary().equals(issue.summary())) - .findFirst() - .map(Map.Entry::getKey); + .filter(entry -> entry.getValue().issue.summary().equals(issue.summary())) + .map(entry -> new IssueInfo(entry.getKey(), + entry.getValue().updated, + entry.getValue().isOpen() ? Status.toDo : Status.done, + entry.getValue().assignee)) + .collect(Collectors.toList()); } @Override @@ -118,6 +125,11 @@ public class MockIssueHandler implements IssueHandler { return projects.get(projectKey); } + @Override + public void addAttachment(IssueId id, String filename, Supplier<InputStream> contentAsStream) { + attachments.computeIfAbsent(id, __ -> new HashMap<>()).put(filename, contentAsStream.get()); + } + public MockIssueHandler close(IssueId issueId) { issues.get(issueId).open = false; touch(issueId); |