@@ -593,8 +593,11 @@ func FetchCodeCommentsByLine(ctx context.Context, gitRepo *git.Repository, repo
593593
594594// LoadCodeComments loads comments into each line, so that the comments can be displayed in the diff view.
595595// the comments' line number is recalculated based on the hunks of the diff.
596- func LoadCodeComments (ctx context.Context , gitRepo * git.Repository , repo * repo_model.Repository , diff * gitdiff.Diff , issueID int64 , currentUser * user_model.User , startCommit , endCommit * git.Commit , showOutdatedComments bool ) error {
597- if startCommit == nil || endCommit == nil {
596+ func LoadCodeComments (ctx context.Context , gitRepo * git.Repository , repo * repo_model.Repository ,
597+ diff * gitdiff.Diff , issueID int64 , currentUser * user_model.User ,
598+ beforeCommit , afterCommit * git.Commit , showOutdatedComments bool ,
599+ ) error {
600+ if beforeCommit == nil || afterCommit == nil {
598601 return errors .New ("startCommit and endCommit cannot be nil" )
599602 }
600603
@@ -609,9 +612,20 @@ func LoadCodeComments(ctx context.Context, gitRepo *git.Repository, repo *repo_m
609612 hunksCache := make (map [string ][]* git.HunkInfo )
610613 // filecomments should be sorted by created time, so that the latest comments are at the end
611614 for _ , comment := range fileComments {
612- dstCommitID := startCommit .ID .String ()
615+ if comment .CommitSHA == "" {
616+ if comment .Line > 0 {
617+ comment .CommitSHA = afterCommit .ID .String ()
618+ } else if comment .Line < 0 {
619+ comment .CommitSHA = beforeCommit .ID .String ()
620+ } else {
621+ // If the comment has no line number, we cannot display it in the diff view
622+ continue
623+ }
624+ }
625+
626+ dstCommitID := beforeCommit .ID .String ()
613627 if comment .Line > 0 {
614- dstCommitID = endCommit .ID .String ()
628+ dstCommitID = afterCommit .ID .String ()
615629 }
616630
617631 if comment .CommitSHA == dstCommitID {
0 commit comments