Skip to content

Commit d920c87

Browse files
committed
fix(gitdiff): fix line number handling in FillHiddenCommentIDsForDiffLine
1 parent 9356dbe commit d920c87

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

services/gitdiff/gitdiff.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,16 @@ func FillHiddenCommentIDsForDiffLine(line *DiffLine, lineComments map[int64][]*i
223223

224224
var hiddenCommentIDs []int64
225225
for commentLineNum, comments := range lineComments {
226-
absLineNum := int(commentLineNum)
227-
if absLineNum < 0 {
228-
absLineNum = -absLineNum
226+
if commentLineNum < 0 {
227+
continue // Skip left-side
229228
}
229+
lineNum := int(commentLineNum)
230230
// Check if comments are in the hidden range
231-
// depending on 'end-of-file' expansion might be RightHunkSize = 0
231+
// The hidden range depends on whether this is an end-of-file expansion
232232
isEndOfFileExpansion := line.SectionInfo.RightHunkSize == 0
233-
inRange := absLineNum > line.SectionInfo.LastRightIdx &&
234-
(isEndOfFileExpansion && absLineNum <= line.SectionInfo.RightIdx ||
235-
!isEndOfFileExpansion && absLineNum < line.SectionInfo.RightIdx)
233+
inRange := lineNum > line.SectionInfo.LastRightIdx &&
234+
(isEndOfFileExpansion && lineNum <= line.SectionInfo.RightIdx ||
235+
!isEndOfFileExpansion && lineNum < line.SectionInfo.RightIdx)
236236

237237
if inRange {
238238
for _, comment := range comments {

services/gitdiff/gitdiff_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,10 @@ func TestCalculateHiddenCommentIDsForLine(t *testing.T) {
805805
},
806806
},
807807
lineComments: map[int64][]*issues_model.Comment{
808-
-15: {{ID: 100}},
808+
-15: {{ID: 100}}, // Left-side comment, should NOT be counted
809+
15: {{ID: 101}}, // Right-side comment, should be counted
809810
},
810-
expected: []int64{100},
811+
expected: []int64{101}, // Only right-side comment
811812
},
812813
{
813814
name: "boundary conditions - normal expansion (both boundaries exclusive)",

0 commit comments

Comments
 (0)