mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-03 02:21:17 +02:00
Fix the bug when the last code comment deleted, a review comment type comment is still in the activity list of the pull request
This commit is contained in:
8 files changed
+116
-15
No files matched your search
@@ -131,17 +131,17 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, contentVersion
|
||||
}
|
||||
|
||||
// DeleteComment deletes the comment
|
||||
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) error {
|
||||
err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) (*issues_model.Comment, error) {
|
||||
deletedReviewComment, err := db.WithTx2(ctx, func(ctx context.Context) (*issues_model.Comment, error) {
|
||||
return issues_model.DeleteComment(ctx, comment)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notify_service.DeleteComment(ctx, doer, comment)
|
||||
|
||||
return nil
|
||||
return deletedReviewComment, nil
|
||||
}
|
||||
|
||||
// LoadCommentPushCommits Load push commits
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package issue
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_DeleteCommentWithReview(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 7})
|
||||
assert.NoError(t, comment.LoadAttachments(t.Context()))
|
||||
assert.Len(t, comment.Attachments, 1)
|
||||
assert.Equal(t, int64(13), comment.Attachments[0].ID)
|
||||
assert.Equal(t, int64(10), comment.ReviewID)
|
||||
review := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: comment.ReviewID})
|
||||
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
// since this is the last comment of the review, it should be deleted when the comment is deleted
|
||||
deletedReviewComment, err := DeleteComment(db.DefaultContext, user1, comment)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, deletedReviewComment)
|
||||
|
||||
// the review should be deleted as well
|
||||
unittest.AssertNotExistsBean(t, &issues_model.Review{ID: review.ID})
|
||||
// the attachment should be deleted as well
|
||||
newAttachment, err := repo_model.GetAttachmentByID(t.Context(), comment.Attachments[0].ID)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, newAttachment)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
|
||||
}
|
||||
|
||||
for _, comment := range comments {
|
||||
if err = issues_model.DeleteComment(ctx, comment); err != nil {
|
||||
if _, err = issues_model.DeleteComment(ctx, comment); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user