Skip to content

Commit

Permalink
Add dates to the comments/description
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Nov 4, 2024
1 parent c1d16d4 commit 312b495
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ interface Formatting {
*/
@WithDefault("upstream-%s")
String labelTemplate();

/**
* Specify how {@link java.time.ZonedDateTime} is formatted to string.
*/
@WithDefault("EEEE, MMMM dd, yyyy 'at' HH:mm:ss z(Z)")
String timestampFormat();
}

interface EventProcessing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.hibernate.infra.replicate.jira.service.jira;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -39,6 +41,7 @@ public final class HandlerProjectContext implements AutoCloseable {

private final Map<String, HandlerProjectContext> allProjectsContextMap;
private final Pattern sourceLabelPattern;
private final DateTimeFormatter formatter;

public HandlerProjectContext(String projectName, String projectGroupName, JiraRestClient sourceJiraClient,
JiraRestClient destinationJiraClient, HandlerProjectGroupContext projectGroupContext,
Expand All @@ -59,6 +62,7 @@ public HandlerProjectContext(String projectName, String projectGroupName, JiraRe
this.allProjectsContextMap = allProjectsContextMap;
this.sourceLabelPattern = Pattern
.compile(projectGroupContext.projectGroup().formatting().labelTemplate().formatted(".+"));
this.formatter = DateTimeFormatter.ofPattern(projectGroupContext.projectGroup().formatting().timestampFormat());
}

public JiraConfig.JiraProject project() {
Expand Down Expand Up @@ -225,4 +229,8 @@ public Optional<HandlerProjectContext> contextForProjectInSameGroup(String proje
public boolean isSourceLabel(String label) {
return sourceLabelPattern.matcher(label).matches();
}

public String formatTimestamp(ZonedDateTime time) {
return time != null ? time.format(formatter) : "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ private JiraComment prepareComment(JiraIssue issue, JiraComment source) {
private String prepareCommentQuote(JiraIssue issue, JiraComment comment) {
URI jiraCommentUri = createJiraCommentUri(issue, comment);
UserData userData = userData(comment.self, comment.author, "the user %s");
UserData editUserData = userData(comment.self, comment.updateAuthor, "the user %s");
String content = """
{quote}This [comment|%s] was posted by [%s|%s].{quote}
{quote}This [comment|%s] was posted by [%s|%s] on %s.%s{quote}
""".formatted(jiraCommentUri, userData.name(), userData.uri());
""".formatted(jiraCommentUri, userData.name(), userData.uri(), context.formatTimestamp(comment.created),
comment.isUpdatedSameAsCreated()
? ""
: """
[%s|%s] edited the comment on %s.
""".formatted(editUserData.name(), editUserData.uri(),
context.formatTimestamp(comment.updated)));
return truncateContent(content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,19 @@ private String prepareDescriptionQuote(JiraIssue issue) {
Reported by: %s.
Upstream status: %s.{quote}
Upstream status: %s.
Created: %s.
Last updated: %s.{quote}
""".formatted(issue.key, issueUri,
assignee == null ? " Unassigned" : "[%s|%s]".formatted(assignee.name(), assignee.uri()),
reporter == null ? " Unknown" : "[%s|%s]".formatted(reporter.name(), reporter.uri()),
issue.fields.status != null ? issue.fields.status.name : "Unknown");
issue.fields.status != null ? issue.fields.status.name : "Unknown",
context.formatTimestamp(issue.fields.created),
context.formatTimestamp(issue.fields.updated != null ? issue.fields.updated : issue.fields.created));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hibernate.infra.replicate.jira.service.jira.model.rest;

import java.net.URI;
import java.time.ZonedDateTime;

import org.hibernate.infra.replicate.jira.service.jira.model.JiraBaseObject;

Expand All @@ -9,12 +10,19 @@ public class JiraComment extends JiraBaseObject {
public String id;
public URI self;
public JiraUser author = new JiraUser();
public JiraUser updateAuthor;
public String body;
public ZonedDateTime created;
public ZonedDateTime updated;

public JiraComment() {
}

public JiraComment(String id) {
this.id = id;
}

public boolean isUpdatedSameAsCreated() {
return updated != null && updated.equals(created);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hibernate.infra.replicate.jira.service.jira.model.rest;

import java.time.ZonedDateTime;
import java.util.List;

import org.hibernate.infra.replicate.jira.service.jira.model.JiraBaseObject;
Expand All @@ -22,6 +23,8 @@ public class JiraFields extends JiraBaseObject {
public List<JiraIssueLink> issuelinks;
public JiraComments comment;
public JiraIssue parent;
public ZonedDateTime created;
public ZonedDateTime updated;

@Override
public String toString() {
Expand Down

0 comments on commit 312b495

Please sign in to comment.