MCPcopy Create free account
hub / github.com/backnotprop/plannotator / parseDiffToFiles

Function parseDiffToFiles

packages/review-editor/utils/diffParser.ts:31–61  ·  view source on GitHub ↗
(rawPatch: string)

Source from the content-addressed store, hash-verified

29}
30
31export function parseDiffToFiles(rawPatch: string): DiffFile[] {
32 const files: DiffFile[] = [];
33
34 for (const chunk of splitDiffChunks(rawPatch)) {
35 const lines = chunk.split('\n');
36 const fromFileLines = parseDiffFilePathLines(lines);
37 const fromHeader = parseDiffGitHeader(lines[0] ?? '');
38 const oldPath = fromFileLines.oldPath ?? fromFileLines.newPath ?? fromHeader.oldPath;
39 const newPath = fromFileLines.newPath ?? fromFileLines.oldPath ?? fromHeader.newPath;
40 if (!oldPath || !newPath) continue;
41
42 let additions = 0;
43 let deletions = 0;
44
45 for (const line of lines) {
46 if (line.startsWith('+') && !line.startsWith('+++')) additions += 1;
47 if (line.startsWith('-') && !line.startsWith('---')) deletions += 1;
48 }
49
50 files.push({
51 path: newPath,
52 oldPath: oldPath !== newPath ? oldPath : undefined,
53 patch: chunk,
54 additions,
55 deletions,
56 status: deriveStatus(lines, oldPath, newPath),
57 });
58 }
59
60 return files;
61}

Callers 4

ReviewAppFunction · 0.90
applyPRResponseFunction · 0.90
diffParser.test.tsFile · 0.90
parseFunction · 0.90

Calls 5

parseDiffFilePathLinesFunction · 0.90
parseDiffGitHeaderFunction · 0.90
splitDiffChunksFunction · 0.85
deriveStatusFunction · 0.85
pushMethod · 0.45

Tested by 1

parseFunction · 0.72