Skip to content

Commit 136822f

Browse files
committed
Truncate content (description/comment)
- since we apply a quote header to the original, we may hit the limit and an update will fail
1 parent 2b4b52d commit 136822f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/main/java/org/hibernate/infra/sync/jira/service/jira/handler/JiraCommentUpsertEventHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ private JiraComment prepareComment(JiraIssue issue, JiraComment source) {
5858
private String prepareCommentQuote(JiraIssue issue, JiraComment comment) {
5959
URI jiraCommentUri = createJiraCommentUri(issue, comment);
6060
URI jiraUserUri = createJiraUserUri(comment.self, comment.author);
61-
return """
61+
String content = """
6262
{quote}This [comment|%s] was posted by the [user %s|%s].{quote}
6363
6464
6565
""".formatted(jiraCommentUri, JiraTextContent.userIdPart(comment.author), jiraUserUri);
66+
return truncateContent(content);
6667
}
6768

6869
@Override

src/main/java/org/hibernate/infra/sync/jira/service/jira/handler/JiraEventHandler.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import jakarta.ws.rs.core.UriBuilder;
2020

2121
public abstract class JiraEventHandler implements Runnable {
22+
protected static final int MAX_CONTENT_SIZE = 65_535;
2223

2324
protected final Long objectId;
2425
protected final FailureCollector failureCollector;
@@ -162,6 +163,21 @@ public final void run() {
162163

163164
protected abstract void doRun();
164165

166+
protected String truncateContent(String content) {
167+
// NOTE: description/comment content has a limit, and maybe the original one is
168+
// close to that limit but since we modify it with the quote info we better make
169+
// sure we are still able to fit the content and truncate anything at the end
170+
// (we have a link to the original if we want to read that very last part).
171+
//
172+
// A possible exception returned by the API:
173+
// {"errorMessages":[],"errors":{"description":"The entered text is too long. It
174+
// exceeds the allowed limit of 65,535 characters."}}
175+
if (content.length() > MAX_CONTENT_SIZE) {
176+
content = content.substring(0, MAX_CONTENT_SIZE);
177+
}
178+
return content;
179+
}
180+
165181
protected String toDestinationKey(String key) {
166182
if (keyToUpdatePattern.matcher(key).matches()) {
167183
return "%s-%d".formatted(context.project().projectKey(), JiraIssue.keyToLong(key));

src/main/java/org/hibernate/infra/sync/jira/service/jira/handler/JiraIssueUpsertEventHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private JiraIssue issueToCreate(JiraIssue sourceIssue) {
9393
destinationIssue.fields.description = sourceIssue.fields.description;
9494
destinationIssue.fields.description = "%s%s".formatted(prepareDescriptionQuote(sourceIssue),
9595
Objects.toString(sourceIssue.fields.description, ""));
96+
destinationIssue.fields.description = truncateContent(destinationIssue.fields.description);
9697

9798
destinationIssue.fields.labels = sourceIssue.fields.labels;
9899
// let's also add fix versions to the labels

0 commit comments

Comments
 (0)