Skip to content

Commit 78cd2ce

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

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

services/gitdiff/gitdiff.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,14 @@ 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
}
230-
// Check if comments are in the hidden range
231-
// depending on 'end-of-file' expansion might be RightHunkSize = 0
229+
lineNum := int(commentLineNum)
232230
isEndOfFileExpansion := line.SectionInfo.RightHunkSize == 0
233-
inRange := absLineNum > line.SectionInfo.LastRightIdx &&
234-
(isEndOfFileExpansion && absLineNum <= line.SectionInfo.RightIdx ||
235-
!isEndOfFileExpansion && absLineNum < line.SectionInfo.RightIdx)
231+
inRange := lineNum > line.SectionInfo.LastRightIdx &&
232+
(isEndOfFileExpansion && lineNum <= line.SectionInfo.RightIdx ||
233+
!isEndOfFileExpansion && lineNum < line.SectionInfo.RightIdx)
236234

237235
if inRange {
238236
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)