PR #90: @@ hunk-header positions not mapped — PostReview fails for hunk-level comments #97
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What was missed
BuildPositionToLineMapcorrectly incrementspositionand updatesmaxPositionswhen it encounters a@@hunk-header line, but it does not insert an entry intopm.files[currentFile][position]. The GitHub diff-position spec — and issue #79 explicitly — defines the@@line as position 1 (or the continuing counter for subsequent hunks), and it is a valid target for inline comments. Because no map entry is written for@@positions,Translate()falls into the!okbranch and returns a hard error ("position N out of range for file"), rather than falling back to the nearest non-deletion line below the header.Deletion lines already get this fallback treatment (they are stored as
-1and Translate follows the chain). Hunk-header positions should receive the same: map them to0(or a sentinel) and let Translate fall through to the nearest context/addition line below. The current asymmetry means any LLM comment positioned at a@@line will causePostReviewto abort for that file's comments entirely.Source
gitea/position.go, hunk-header handling blockWhat needs to happen
BuildPositionToLineMap, when a@@hunk-header line is encountered, store the position with a sentinel value (e.g.,0) inpm.files[currentFile]:pm.files[currentFile][position] = 0.Translate(), add a branch forlineNum == 0that applies the same "nearest non-deletion line below" fallback used for deletion lines (lineNum == -1).position_test.gothat callTranslate(file, 1)(single-hunk) and the continuing@@position in a multi-hunk diff, verifying they return the first new-file line of the hunk rather than an error.Acceptance criteria
Translate(file, hunkHeaderPosition)returns the line number of the first context/addition line in the hunk, not an error@@positionsReferences