fix(pull): fix code context of review comments on unchanged lines (#39799) (#39805)

Backport #39799

Fixes #39794

Co-authored-by: fixfon <12512757+fixfon@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-10-16 11:53:17 +00:00
1 parent 96cb6cd16f
commit c4e9d96162
3 files changed
+68 -3

No files matched your search

+4 -3
View File
@@ -275,11 +275,12 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
}
// If patch is still empty (unchanged line), generate code context
if patch == "" && commitID != "" {
patch, err = gitdiff.GeneratePatchForUnchangedLine(ctx, gitRepo, commitID, treePath, line, setting.UI.CodeCommentLines)
contextCommitID := util.Iif(line < 0, pr.MergeBase, headCommitID) // the line number is relative to the diff sides, not to the blamed commitID
if patch == "" && contextCommitID != "" {
patch, err = gitdiff.GeneratePatchForUnchangedLine(ctx, gitRepo, contextCommitID, treePath, line, setting.UI.CodeCommentLines)
if err != nil {
// Log the error but don't fail comment creation
log.Debug("Unable to generate patch for unchanged line (file=%s, line=%d, commit=%s): %v", treePath, line, commitID, err)
log.Debug("Unable to generate patch for unchanged line (file=%s, line=%d, commit=%s): %v", treePath, line, contextCommitID, err)
}
}
}