Skip to content

Commit 0797f34

Browse files
committed
Improvements
1 parent 521b095 commit 0797f34

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

routers/web/repo/issue_comment.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,31 @@ func UpdateCommentContent(ctx *context.Context) {
239239
return
240240
}
241241

242-
oldContent := comment.Content
243242
newContent := ctx.FormString("content")
244243
contentVersion := ctx.FormInt("content_version")
245-
if newContent == oldContent {
244+
if newContent == comment.Content {
245+
if contentVersion != comment.ContentVersion {
246+
ctx.JSONError(ctx.Tr("repo.comments.edit.already_changed"))
247+
return
248+
}
249+
250+
if err := comment.LoadAttachments(ctx); err != nil {
251+
ctx.ServerError("LoadAttachments", err)
252+
return
253+
}
254+
246255
ctx.JSON(http.StatusOK, map[string]any{
247-
"content": oldContent,
256+
"content": comment.Content,
248257
"contentVersion": comment.ContentVersion,
249-
"attachments": attachmentsHTML(ctx, comment.Attachments, oldContent),
258+
"attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content),
250259
})
251260
return
252261
}
253262

254263
// allow to save empty content
255264
comment.Content = newContent
265+
oldContent := comment.Content
266+
256267
if err = issue_service.UpdateComment(ctx, comment, contentVersion, ctx.Doer, oldContent); err != nil {
257268
if errors.Is(err, user_model.ErrBlockedUser) {
258269
ctx.JSONError(ctx.Tr("repo.issues.comment.blocked_user"))

tests/integration/repo_webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ func Test_WebhookIssueComment(t *testing.T) {
300300
session.MakeRequest(t, req, http.StatusOK)
301301

302302
// 3. validate the webhook is not triggered because no content change
303-
assert.Equal(t, "", triggeredEvent)
304-
assert.Len(t, payloads, 0)
303+
assert.Empty(t, triggeredEvent)
304+
assert.Zero(t, payloads)
305305
})
306306
})
307307
}

0 commit comments

Comments
 (0)