Skip to content

Commit 0c9f37d

Browse files
committed
revert unnecessary change in this pull request
1 parent 9c251fd commit 0c9f37d

File tree

8 files changed

+23
-121
lines changed

8 files changed

+23
-121
lines changed

models/fixtures/comment.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,3 @@
102102
review_id: 22
103103
assignee_id: 5
104104
created_unix: 946684817
105-
106-
-
107-
id: 12
108-
type: 22 # review
109-
poster_id: 100
110-
issue_id: 3
111-
content: ""
112-
review_id: 10
113-
created_unix: 946684812

models/issues/comment.go

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,75 +1113,35 @@ func UpdateComment(ctx context.Context, c *Comment, contentVersion int, doer *us
11131113
}
11141114

11151115
// DeleteComment deletes the comment
1116-
func DeleteComment(ctx context.Context, comment *Comment) (*Comment, error) {
1116+
func DeleteComment(ctx context.Context, comment *Comment) error {
11171117
if _, err := db.GetEngine(ctx).ID(comment.ID).NoAutoCondition().Delete(comment); err != nil {
1118-
return nil, err
1118+
return err
11191119
}
11201120

11211121
if _, err := db.DeleteByBean(ctx, &ContentHistory{
11221122
CommentID: comment.ID,
11231123
}); err != nil {
1124-
return nil, err
1124+
return err
11251125
}
11261126

11271127
if comment.Type.CountedAsConversation() {
11281128
if err := UpdateIssueNumComments(ctx, comment.IssueID); err != nil {
1129-
return nil, err
1129+
return err
11301130
}
11311131
}
11321132
if _, err := db.GetEngine(ctx).Table("action").
11331133
Where("comment_id = ?", comment.ID).
11341134
Update(map[string]any{
11351135
"is_deleted": true,
11361136
}); err != nil {
1137-
return nil, err
1138-
}
1139-
1140-
var deletedReviewComment *Comment
1141-
1142-
// delete review & review comment if the code comment is the last comment of the review
1143-
if comment.Type == CommentTypeCode && comment.ReviewID > 0 {
1144-
if err := comment.LoadReview(ctx); err != nil {
1145-
return nil, err
1146-
}
1147-
if comment.Review != nil && comment.Review.Type == ReviewTypeComment {
1148-
res, err := db.GetEngine(ctx).ID(comment.ReviewID).
1149-
Where("NOT EXISTS (SELECT 1 FROM comment WHERE review_id = ? AND `type` = ?)", comment.ReviewID, CommentTypeCode).
1150-
Delete(new(Review))
1151-
if err != nil {
1152-
return nil, err
1153-
}
1154-
if res > 0 {
1155-
var reviewComment Comment
1156-
has, err := db.GetEngine(ctx).Where("review_id = ?", comment.ReviewID).
1157-
And("`type` = ?", CommentTypeReview).Get(&reviewComment)
1158-
if err != nil {
1159-
return nil, err
1160-
}
1161-
if has && reviewComment.Content == "" {
1162-
if err := reviewComment.LoadAttachments(ctx); err != nil {
1163-
return nil, err
1164-
}
1165-
if len(reviewComment.Attachments) == 0 {
1166-
if _, err := db.GetEngine(ctx).ID(reviewComment.ID).Delete(new(Comment)); err != nil {
1167-
return nil, err
1168-
}
1169-
deletedReviewComment = &reviewComment
1170-
}
1171-
}
1172-
comment.ReviewID = 0 // reset review ID to 0 for the notification
1173-
}
1174-
}
1137+
return err
11751138
}
11761139

11771140
if err := comment.neuterCrossReferences(ctx); err != nil {
1178-
return nil, err
1141+
return err
11791142
}
11801143

1181-
if err := DeleteReaction(ctx, &ReactionOptions{CommentID: comment.ID}); err != nil {
1182-
return nil, err
1183-
}
1184-
return deletedReviewComment, nil
1144+
return DeleteReaction(ctx, &ReactionOptions{CommentID: comment.ID})
11851145
}
11861146

11871147
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id

routers/api/v1/repo/issue_comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ func deleteIssueComment(ctx *context.APIContext) {
726726
return
727727
}
728728

729-
if _, err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
729+
if err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
730730
ctx.APIErrorInternal(err)
731731
return
732732
}

routers/web/repo/issue_comment.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,12 @@ func DeleteComment(ctx *context.Context) {
325325
return
326326
}
327327

328-
deletedReviewComment, err := issue_service.DeleteComment(ctx, ctx.Doer, comment)
329-
if err != nil {
328+
if err := issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
330329
ctx.ServerError("DeleteComment", err)
331330
return
332331
}
333332

334-
res := map[string]any{}
335-
if deletedReviewComment != nil {
336-
res["deletedReviewCommentHashTag"] = deletedReviewComment.HashTag()
337-
}
338-
339-
ctx.JSON(http.StatusOK, res)
333+
ctx.Status(http.StatusOK)
340334
}
341335

342336
// ChangeCommentReaction create a reaction for comment

services/issue/comments.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,42 +132,40 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, contentVersion
132132
}
133133

134134
// deleteComment deletes the comment
135-
func deleteComment(ctx context.Context, comment *issues_model.Comment, removeAttachments bool) (*issues_model.Comment, error) {
136-
return db.WithTx2(ctx, func(ctx context.Context) (*issues_model.Comment, error) {
135+
func deleteComment(ctx context.Context, comment *issues_model.Comment, removeAttachments bool) error {
136+
return db.WithTx(ctx, func(ctx context.Context) error {
137137
if removeAttachments {
138138
// load attachments before deleting the comment
139139
if err := comment.LoadAttachments(ctx); err != nil {
140-
return nil, err
140+
return err
141141
}
142142
}
143143

144144
// deletedReviewComment should be a review comment with no content and no attachments
145-
deletedReviewComment, err := issues_model.DeleteComment(ctx, comment)
146-
if err != nil {
147-
return nil, err
145+
if err := issues_model.DeleteComment(ctx, comment); err != nil {
146+
return err
148147
}
149148

150149
if removeAttachments {
151150
// mark comment attachments as deleted
152151
if _, err := repo_model.MarkAttachmentsDeleted(ctx, comment.Attachments); err != nil {
153-
return nil, err
152+
return err
154153
}
155154
}
156-
return deletedReviewComment, nil
155+
return nil
157156
})
158157
}
159158

160-
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) (*issues_model.Comment, error) {
161-
deletedReviewComment, err := deleteComment(ctx, comment, true)
162-
if err != nil {
163-
return nil, err
159+
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) error {
160+
if err := deleteComment(ctx, comment, true); err != nil {
161+
return err
164162
}
165163

166164
attachment.AddAttachmentsToCleanQueue(ctx, comment.Attachments)
167165

168166
notify_service.DeleteComment(ctx, doer, comment)
169167

170-
return deletedReviewComment, nil
168+
return nil
171169
}
172170

173171
// LoadCommentPushCommits Load push commits

services/issue/comments_test.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

services/issue/issue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue, deleteAttachmen
315315
}
316316

317317
for _, comment := range issue.Comments {
318-
_, err := deleteComment(ctx, comment, deleteAttachments)
319-
if err != nil {
318+
if err := deleteComment(ctx, comment, deleteAttachments); err != nil {
320319
return nil, fmt.Errorf("deleteComment [comment_id: %d]: %w", comment.ID, err)
321320
}
322321
toBeCleanedAttachments = append(toBeCleanedAttachments, comment.Attachments...)

services/user/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func deleteUser(ctx context.Context, u *user_model.User, purge bool) (toBeCleane
122122
return nil, err
123123
}
124124

125-
if _, err = issues_model.DeleteComment(ctx, comment); err != nil {
125+
if err = issues_model.DeleteComment(ctx, comment); err != nil {
126126
return nil, err
127127
}
128128

0 commit comments

Comments
 (0)