@@ -855,6 +855,9 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
855855 // Check comment type.
856856 switch opts .Type {
857857 case CommentTypeCode :
858+ if err = updateAttachments (ctx , opts , comment ); err != nil {
859+ return err
860+ }
858861 if comment .ReviewID != 0 {
859862 if comment .Review == nil {
860863 if err := comment .loadReview (ctx ); err != nil {
@@ -872,22 +875,9 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
872875 }
873876 fallthrough
874877 case CommentTypeReview :
875- // Check attachments
876- attachments , err := repo_model .GetAttachmentsByUUIDs (ctx , opts .Attachments )
877- if err != nil {
878- return fmt .Errorf ("getAttachmentsByUUIDs [uuids: %v]: %w" , opts .Attachments , err )
879- }
880-
881- for i := range attachments {
882- attachments [i ].IssueID = opts .Issue .ID
883- attachments [i ].CommentID = comment .ID
884- // No assign value could be 0, so ignore AllCols().
885- if _ , err = db .GetEngine (ctx ).ID (attachments [i ].ID ).Update (attachments [i ]); err != nil {
886- return fmt .Errorf ("update attachment [%d]: %w" , attachments [i ].ID , err )
887- }
878+ if err = updateAttachments (ctx , opts , comment ); err != nil {
879+ return err
888880 }
889-
890- comment .Attachments = attachments
891881 case CommentTypeReopen , CommentTypeClose :
892882 if err = repo_model .UpdateRepoIssueNumbers (ctx , opts .Issue .RepoID , opts .Issue .IsPull , true ); err != nil {
893883 return err
@@ -897,6 +887,23 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
897887 return UpdateIssueCols (ctx , opts .Issue , "updated_unix" )
898888}
899889
890+ func updateAttachments (ctx context.Context , opts * CreateCommentOptions , comment * Comment ) error {
891+ attachments , err := repo_model .GetAttachmentsByUUIDs (ctx , opts .Attachments )
892+ if err != nil {
893+ return fmt .Errorf ("getAttachmentsByUUIDs [uuids: %v]: %w" , opts .Attachments , err )
894+ }
895+ for i := range attachments {
896+ attachments [i ].IssueID = opts .Issue .ID
897+ attachments [i ].CommentID = comment .ID
898+ // No assign value could be 0, so ignore AllCols().
899+ if _ , err = db .GetEngine (ctx ).ID (attachments [i ].ID ).Update (attachments [i ]); err != nil {
900+ return fmt .Errorf ("update attachment [%d]: %w" , attachments [i ].ID , err )
901+ }
902+ }
903+ comment .Attachments = attachments
904+ return nil
905+ }
906+
900907func createDeadlineComment (ctx context.Context , doer * user_model.User , issue * Issue , newDeadlineUnix timeutil.TimeStamp ) (* Comment , error ) {
901908 var content string
902909 var commentType CommentType
0 commit comments