diff --git a/services/feed/action.go b/services/feed/action.go index f178e99001..2d07f39284 100644 --- a/services/feed/action.go +++ b/services/feed/action.go @@ -488,6 +488,12 @@ func encodeContent(params ...string) string { func abbreviatedComment(comment string) string { firstLine := strings.Split(comment, "\n")[0] + if strings.HasPrefix(firstLine, "```") { + // First line is is a fenced code block... with no special abbreviate we would display a blank block, or in the + // worst-case a ```mermaid would display an error. Better to omit the comment. + return "" + } + truncatedContent, truncatedRight := util.SplitStringAtByteN(firstLine, 200) if truncatedRight != "" { // in case the content is in a Latin family language, we remove the last broken word. diff --git a/services/feed/action_test.go b/services/feed/action_test.go index 35b170e95c..48de7995bf 100644 --- a/services/feed/action_test.go +++ b/services/feed/action_test.go @@ -185,6 +185,16 @@ func TestAbbreviatedComment(t *testing.T) { input: "Interesting point, here's a digram with my thoughts:\n```mermaid\ngraph LR\n a -->|some text| b\n```", expected: "Interesting point, here's a digram with my thoughts:", }, + { + name: "block start", + input: "```\n# This file describes the expected reviewers for a PR based on the changed\n# files.\n```\n\nI think this comment is wrong...", + expected: "", + }, + { + name: "labeled block start", + input: "```mermaid\ngraph LR\n a -->|some text| b\n```", + expected: "", + }, } for _, tt := range tests {