| 17 | * @returns the parsed body |
| 18 | */ |
| 19 | export function parseFileDiff(stdout: string): Types.FileHunks { |
| 20 | if (stdout.length > Limits.MAX_DIFF_BYTES) { |
| 21 | return LARGE_FILE_HUNKS |
| 22 | } |
| 23 | |
| 24 | const rows = stdout.split('\n') |
| 25 | |
| 26 | const headerRows = rows.flatMap((row, at) => |
| 27 | HUNK_HEADER.test(row) ? [at] : [], |
| 28 | ) |
| 29 | |
| 30 | return { |
| 31 | ...cutHunks( |
| 32 | headerRows.map((at, ordinal) => |
| 33 | hunkOf( |
| 34 | HUNK_HEADER.exec(rows[at] ?? '')?.groups, |
| 35 | rows.slice(at + 1, headerRows[ordinal + 1]).filter(isBodyLine), |
| 36 | ), |
| 37 | ), |
| 38 | ), |
| 39 | isLarge: false, |
| 40 | } |
| 41 | } |