Merge pull request 'fix: don't show truncated comments in RSS/Atom feeds' (#5653) from gusted/forgejo-truncated-comment-rss into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5653 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
fac25238d4
4 changed files with 52 additions and 0 deletions
|
@ -13,7 +13,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
activities_model "code.gitea.io/gitea/models/activities"
|
activities_model "code.gitea.io/gitea/models/activities"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/markup"
|
"code.gitea.io/gitea/modules/markup"
|
||||||
"code.gitea.io/gitea/modules/markup/markdown"
|
"code.gitea.io/gitea/modules/markup/markdown"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
@ -232,6 +234,16 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio
|
||||||
case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull:
|
case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull:
|
||||||
desc = act.GetIssueTitle(ctx)
|
desc = act.GetIssueTitle(ctx)
|
||||||
comment := act.GetIssueInfos()[1]
|
comment := act.GetIssueInfos()[1]
|
||||||
|
if strings.HasSuffix(comment, "…") {
|
||||||
|
// Comment was truncated get the full content from the database.
|
||||||
|
// This truncation is done in `NotifyCreateIssueComment`.
|
||||||
|
commentModel, err := issues_model.GetCommentByID(ctx, act.CommentID)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Couldn't get comment[%d] for RSS feed: %v", act.CommentID, err)
|
||||||
|
} else {
|
||||||
|
comment = commentModel.Content
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(comment) != 0 {
|
if len(comment) != 0 {
|
||||||
desc += "\n\n" + string(renderMarkdown(ctx, act, comment))
|
desc += "\n\n" + string(renderMarkdown(ctx, act, comment))
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFeed(t *testing.T) {
|
func TestFeed(t *testing.T) {
|
||||||
|
defer tests.AddFixtures("tests/integration/fixtures/TestFeed/")()
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
t.Run("User", func(t *testing.T) {
|
t.Run("User", func(t *testing.T) {
|
||||||
|
@ -42,6 +43,28 @@ func TestFeed(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Repo", func(t *testing.T) {
|
t.Run("Repo", func(t *testing.T) {
|
||||||
t.Run("Normal", func(t *testing.T) {
|
t.Run("Normal", func(t *testing.T) {
|
||||||
|
t.Run("Atom", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", "/user2/repo1.atom")
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
data := resp.Body.String()
|
||||||
|
assert.Contains(t, data, `<feed xmlns="http://www.w3.org/2005/Atom"`)
|
||||||
|
assert.Contains(t, data, "This is a very long text, so lets scream together: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||||
|
})
|
||||||
|
t.Run("RSS", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", "/user2/repo1.rss")
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
data := resp.Body.String()
|
||||||
|
assert.Contains(t, data, `<rss version="2.0"`)
|
||||||
|
assert.Contains(t, data, "This is a very long text, so lets scream together: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
t.Run("Branch", func(t *testing.T) {
|
||||||
t.Run("Atom", func(t *testing.T) {
|
t.Run("Atom", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
|
9
tests/integration/fixtures/TestFeed/action.yml
Normal file
9
tests/integration/fixtures/TestFeed/action.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
- id: 1001
|
||||||
|
user_id: 2
|
||||||
|
op_type: 10 # close issue
|
||||||
|
act_user_id: 2
|
||||||
|
comment_id: 1001
|
||||||
|
repo_id: 1 # public
|
||||||
|
is_private: false
|
||||||
|
created_unix: 1680454039
|
||||||
|
content: '1|This is a very long text, so lets scream together: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…'
|
8
tests/integration/fixtures/TestFeed/comment.yml
Normal file
8
tests/integration/fixtures/TestFeed/comment.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
-
|
||||||
|
id: 1001
|
||||||
|
type: 0 # comment
|
||||||
|
poster_id: 2
|
||||||
|
issue_id: 1 # in repo_id 1
|
||||||
|
content: "This is a very long text, so lets scream together: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||||
|
created_unix: 1729602027
|
||||||
|
updated_unix: 1729602027
|
Loading…
Add table
Reference in a new issue