fix(github): count PR diff lines whose added content starts with ++ (#6819)

Co-authored-by: ping <ping6174@gmail.com>
This commit is contained in:
PP
2026-07-03 17:25:32 -07:00
committed by GitHub
co-authored by ping
parent 41e395b66b
commit 69415946dd
2 changed files with 22 additions and 1 deletions
@@ -23,4 +23,22 @@ describe('getPRReviewCommentLineNumbersFromPatch', () => {
it('returns an empty list when GitHub omits the patch', () => {
expect(getPRReviewCommentLineNumbersFromPatch(undefined)).toEqual([])
})
it('counts added lines whose content begins with ++', () => {
// Inside a hunk, GitHub's per-file patch never carries a `+++ b/file` header
// (those precede the first @@), so `+++count` is an added line of content `++count`
// and must stay comment-eligible.
const patch = ['@@ -1,1 +1,2 @@', ' const a = 1', '+++count'].join('\n')
expect(getPRReviewCommentLineNumbersFromPatch(patch)).toEqual([1, 2])
})
it('does not treat removed lines whose content begins with -- as commentable', () => {
// Asymmetry guard: removed lines never advance the new-side counter, so `--count`
// (diff line `---count`) must not become commentable. Locks the intended difference
// from the added-line case so a future "symmetric" edit can't regress it.
const patch = ['@@ -1,2 +1,1 @@', ' const a = 1', '---count'].join('\n')
expect(getPRReviewCommentLineNumbersFromPatch(patch)).toEqual([1])
})
})
+4 -1
View File
@@ -21,7 +21,10 @@ export function getPRReviewCommentLineNumbersFromPatch(patch: string | undefined
continue
}
if (line.startsWith('+') && !line.startsWith('+++')) {
// Inside a hunk every `+` line is added content. GitHub's per-file patch keeps the
// `+++ b/file` header before the first @@, so a `+++…` line here is `++…` content,
// not a header, and must stay comment-eligible.
if (line.startsWith('+')) {
lineNumbers.push(nextModifiedLine)
nextModifiedLine++
continue