@@ -301,12 +301,14 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
301
301
attachmentPaths = append (attachmentPaths , issue .Attachments [i ].RelativePath ())
302
302
}
303
303
304
- // TODO: deference all review comments
304
+ // deference all review comments
305
+ if err := issue .LoadComments (ctx ); err != nil {
306
+ return nil , err
307
+ }
305
308
306
309
// delete all database data still assigned to this issue
307
310
if err := db .DeleteBeans (ctx ,
308
311
& issues_model.ContentHistory {IssueID : issue .ID },
309
- & issues_model.Comment {IssueID : issue .ID },
310
312
& issues_model.IssueLabel {IssueID : issue .ID },
311
313
& issues_model.IssueDependency {IssueID : issue .ID },
312
314
& issues_model.IssueAssignees {IssueID : issue .ID },
@@ -327,6 +329,41 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
327
329
return nil , err
328
330
}
329
331
332
+ for _ , comment := range issue .Comments {
333
+ if err := issues_model .DeleteComment (ctx , comment ); err != nil {
334
+ return nil , err
335
+ }
336
+
337
+ if comment .ReviewID > 0 {
338
+ if err := comment .LoadIssue (ctx ); err != nil {
339
+ return nil , err
340
+ }
341
+ if err := comment .Issue .LoadRepo (ctx ); err != nil {
342
+ return nil , err
343
+ }
344
+ if err := comment .Issue .LoadPullRequest (ctx ); err != nil {
345
+ return nil , err
346
+ }
347
+ if err := git .RemoveRef (ctx , comment .Issue .Repo .RepoPath (), issues_model .GetCodeCommentRef (comment .Issue .PullRequest .Index , comment .ID )); err != nil {
348
+ log .Error ("Unable to remove ref in base repository for PR[%d] Error: %v" , comment .Issue .PullRequest .ID , err )
349
+ // We should not return error here, because the comment has been removed from database.
350
+ // users have to delete this ref manually or we should have a synchronize between
351
+ // database comment table and git refs.
352
+ }
353
+ }
354
+
355
+ // delete all attachments related to this comment
356
+ for _ , attachment := range comment .Attachments {
357
+ if err := storage .Attachments .Delete (repo_model .AttachmentRelativePath (attachment .UUID )); err != nil {
358
+ // Even delete files failed, but the attachments has been removed from database, so we
359
+ // should not return error but only record the error on logs.
360
+ // users have to delete this attachments manually or we should have a
361
+ // synchronize between database attachment table and attachment storage
362
+ log .Error ("delete attachment[uuid: %s] failed: %v" , attachment .UUID , err )
363
+ }
364
+ }
365
+ }
366
+
330
367
if err := committer .Commit (); err != nil {
331
368
return nil , err
332
369
}
0 commit comments