From 95522358b1dd56f4d23036d081c1df70936ecdaa Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 12 Feb 2026 21:29:55 +0100 Subject: [PATCH] Address review: guard trimUnclosedCodeBlock and add GetIssueContentBody test Only call trimUnclosedCodeBlock when truncation actually occurred, and add unit tests for GetIssueContentBody covering pipe-delimited content. Co-Authored-By: Claude Opus 4.6 --- models/activities/action_test.go | 18 ++++++++++++++++++ services/feed/notifier.go | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/models/activities/action_test.go b/models/activities/action_test.go index 9447f39d62..a91a81325b 100644 --- a/models/activities/action_test.go +++ b/models/activities/action_test.go @@ -125,6 +125,24 @@ func TestConsistencyUpdateAction(t *testing.T) { unittest.CheckConsistencyFor(t, &activities_model.Action{}) } +func TestGetIssueContentBody(t *testing.T) { + tests := []struct { + content string + expected string + }{ + {content: "1|simple body", expected: "simple body"}, + {content: "1|A -->|text| B", expected: "A -->|text| B"}, + {content: "1|first|second|third", expected: "first|second|third"}, + {content: "1|", expected: ""}, + {content: "no-delimiter", expected: ""}, + {content: "", expected: ""}, + } + for _, test := range tests { + action := &activities_model.Action{Content: test.content} + assert.Equal(t, test.expected, action.GetIssueContentBody(), "content: %q", test.content) + } +} + func TestDeleteIssueActions(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) diff --git a/services/feed/notifier.go b/services/feed/notifier.go index 61352aff60..0acc0c59e1 100644 --- a/services/feed/notifier.go +++ b/services/feed/notifier.go @@ -152,7 +152,9 @@ func (a *actionNotifier) CreateIssueComment(ctx context.Context, doer *user_mode truncatedContent = truncatedContent[:lastSpaceIdx] + "…" } } - truncatedContent = trimUnclosedCodeBlock(truncatedContent) + if truncatedRight != "" { + truncatedContent = trimUnclosedCodeBlock(truncatedContent) + } act.Content = fmt.Sprintf("%d|%s", issue.Index, truncatedContent) if issue.IsPull {