@@ -301,12 +301,15 @@ export const codeReview = async (
301
301
}
302
302
}
303
303
304
+ // Write a function that takes diff for a single file as a string
305
+ // and splits the diff into separate patches
306
+
304
307
const split_patch = ( patch : string | null | undefined ) : string [ ] => {
305
308
if ( ! patch ) {
306
309
return [ ]
307
310
}
308
311
309
- const pattern = / ( ^ @ @ - ( \d + ) , ( \d + ) \+ ( \d + ) , ( \d + ) @ @ ) / gm
312
+ const pattern = / ( ^ @ @ - ( \d + ) , ( \d + ) \+ ( \d + ) , ( \d + ) @ @ ) . * $ / gm
310
313
311
314
const result : string [ ] = [ ]
312
315
let last = - 1
@@ -316,6 +319,7 @@ const split_patch = (patch: string | null | undefined): string[] => {
316
319
last = match . index
317
320
} else {
318
321
result . push ( patch . substring ( last , match . index ) )
322
+ last = match . index
319
323
}
320
324
}
321
325
if ( last !== - 1 ) {
@@ -325,10 +329,12 @@ const split_patch = (patch: string | null | undefined): string[] => {
325
329
}
326
330
327
331
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
329
333
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
332
338
} else {
333
339
return - 1
334
340
}
0 commit comments