Skip to content

Commit

Permalink
Append browse URI for issue instead of API URI, resolves #50
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Huginn committed Feb 22, 2024
1 parent b2894e3 commit 9bf8c15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jboss/draw/Lottery.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Lottery {
private Mailer mailer;

private static final Pattern USERNAME_FROM_EMAIL = Pattern.compile("\\s*(\\b[a-zA-Z0-9._%+-]+)@");
public static final String EMAIL_SUBJECT = "Subject";
public static final String EMAIL_SUBJECT = "This week's lottery issues picked for You";
private static final String EMAIL_BODY = """
Hi %s,
Expand Down Expand Up @@ -100,7 +100,7 @@ public static String createEmailText(String email, List<Issue> issues) {
Matcher matcher = USERNAME_FROM_EMAIL.matcher(email);
String username = matcher.find() ? matcher.group(1) : "Somebody";
return EMAIL_BODY.formatted(username,
issues.stream().map(issue -> issue.getUri().toString()).collect(Collectors.joining("\n")),
issues.stream().map(issue -> issue.getBrowseUri().toString()).collect(Collectors.joining("\n")),
configFileUrl());
}

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/org/jboss/draw/entities/Issue.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
package org.jboss.draw.entities;

import com.atlassian.jira.rest.client.api.domain.BasicComponent;
import io.quarkus.logging.Log;
import org.jboss.processing.state.SingleIssueState;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.stream.StreamSupport;

public class Issue {
private static final String BROWSE_URI = "https://issues.redhat.com/browse/";

private final Long id;
private final URI uri;
private final String project;
private final List<String> components;
private final String key;
private Participant assignee;

public Issue(SingleIssueState issue) {
this(issue.getId(),
issue.getSelf(),
issue.getProject().getKey(),
issue.getKey(),
issue.getComponents().stream().map(BasicComponent::getName).toList());
}

public Issue(com.atlassian.jira.rest.client.api.domain.Issue issue) {
this(issue.getId(),
issue.getSelf(),
issue.getProject().getKey(),
issue.getKey(),
StreamSupport.stream(issue.getComponents().spliterator(), false).map(BasicComponent::getName).toList());
}

public Issue(Long id, URI uri, String project, List<String> components) {
public Issue(Long id, URI uri, String project, String key, List<String> components) {
this.id = id;
this.uri = uri;
this.project = project;
this.key = key;
this.components = components;
}

Expand All @@ -43,6 +51,15 @@ public URI getUri() {
return uri;
}

public URI getBrowseUri() {
try {
return new URI(BROWSE_URI + key);
} catch (URISyntaxException e) {
Log.errorf(e, "Unable to construct browse URI for key %s", key);
throw new RuntimeException(e);
}
}

public String getProject() {
return project;
}
Expand Down

0 comments on commit 9bf8c15

Please sign in to comment.