fix(github): count PR diff lines whose added content starts with ++ (#6819)
Co-authored-by: ping <ping6174@gmail.com>
This commit is contained in:
@@ -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])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user