Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 3c15119

Browse files
committed
fix split_patch
1 parent f05cace commit 3c15119

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

dist/index.js

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/review.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,15 @@ export const codeReview = async (
301301
}
302302
}
303303

304+
// Write a function that takes diff for a single file as a string
305+
// and splits the diff into separate patches
306+
304307
const split_patch = (patch: string | null | undefined): string[] => {
305308
if (!patch) {
306309
return []
307310
}
308311

309-
const pattern = /(^@@ -(\d+),(\d+) \+(\d+),(\d+) @@)/gm
312+
const pattern = /(^@@ -(\d+),(\d+) \+(\d+),(\d+) @@).*$/gm
310313

311314
const result: string[] = []
312315
let last = -1
@@ -316,6 +319,7 @@ const split_patch = (patch: string | null | undefined): string[] => {
316319
last = match.index
317320
} else {
318321
result.push(patch.substring(last, match.index))
322+
last = match.index
319323
}
320324
}
321325
if (last !== -1) {
@@ -325,10 +329,12 @@ const split_patch = (patch: string | null | undefined): string[] => {
325329
}
326330

327331
const patch_comment_line = (patch: string): number => {
328-
const pattern = /(^@@ -(\d+),(\d+) \+(?<begin>\d+),(?<diff>\d+) @@)/gm
332+
const pattern = /(^@@ -(\d+),(\d+) \+(\d+),(\d+) @@)/gm
329333
const match = pattern.exec(patch)
330-
if (match && match.groups) {
331-
return parseInt(match.groups.begin) + parseInt(match.groups.diff) - 1
334+
if (match) {
335+
const begin = parseInt(match[4])
336+
const diff = parseInt(match[5])
337+
return begin + diff - 1
332338
} else {
333339
return -1
334340
}

0 commit comments

Comments
 (0)