From fb83abe39c00f9f5d0a1f519eb84652d18b66221 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 9 May 2025 22:00:38 -0700 Subject: [PATCH] Improvements --- routers/web/repo/issue_comment.go | 19 +++++++++++++++---- tests/integration/repo_webhook_test.go | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/routers/web/repo/issue_comment.go b/routers/web/repo/issue_comment.go index 64dc1cee28..9c917ff55b 100644 --- a/routers/web/repo/issue_comment.go +++ b/routers/web/repo/issue_comment.go @@ -239,20 +239,31 @@ func UpdateCommentContent(ctx *context.Context) { return } - oldContent := comment.Content newContent := ctx.FormString("content") contentVersion := ctx.FormInt("content_version") - if newContent == oldContent { + if newContent == comment.Content { + if contentVersion != comment.ContentVersion { + ctx.JSONError(ctx.Tr("repo.comments.edit.already_changed")) + return + } + + if err := comment.LoadAttachments(ctx); err != nil { + ctx.ServerError("LoadAttachments", err) + return + } + ctx.JSON(http.StatusOK, map[string]any{ - "content": oldContent, + "content": comment.Content, "contentVersion": comment.ContentVersion, - "attachments": attachmentsHTML(ctx, comment.Attachments, oldContent), + "attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content), }) return } // allow to save empty content comment.Content = newContent + oldContent := comment.Content + if err = issue_service.UpdateComment(ctx, comment, contentVersion, ctx.Doer, oldContent); err != nil { if errors.Is(err, user_model.ErrBlockedUser) { ctx.JSONError(ctx.Tr("repo.issues.comment.blocked_user")) diff --git a/tests/integration/repo_webhook_test.go b/tests/integration/repo_webhook_test.go index ebb654d4a7..5ac0a9298e 100644 --- a/tests/integration/repo_webhook_test.go +++ b/tests/integration/repo_webhook_test.go @@ -300,8 +300,8 @@ func Test_WebhookIssueComment(t *testing.T) { session.MakeRequest(t, req, http.StatusOK) // 3. validate the webhook is not triggered because no content change - assert.Equal(t, "", triggeredEvent) - assert.Len(t, payloads, 0) + assert.Empty(t, triggeredEvent) + assert.Zero(t, payloads) }) }) }