Improvements

This commit is contained in:
Lunny Xiao 2025-05-09 22:00:38 -07:00
parent 11f43139f5
commit fb83abe39c
2 changed files with 17 additions and 6 deletions

View File

@ -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"))

View File

@ -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)
})
})
}