* Parse stats from a unified diff patch
(patch: string)
| 863 | * Parse stats from a unified diff patch |
| 864 | */ |
| 865 | function parsePatchStats(patch: string): { filesChanged: number; insertions: number; deletions: number } { |
| 866 | const lines = patch.split("\n") |
| 867 | const files = new Set<string>() |
| 868 | let insertions = 0 |
| 869 | let deletions = 0 |
| 870 | |
| 871 | for (const line of lines) { |
| 872 | if (line.startsWith("diff --git")) { |
| 873 | const match = line.match(/diff --git a\/(.+) b\//) |
| 874 | if (match) files.add(match[1]) |
| 875 | } else if (line.startsWith("+") && !line.startsWith("+++")) { |
| 876 | insertions++ |
| 877 | } else if (line.startsWith("-") && !line.startsWith("---")) { |
| 878 | deletions++ |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | return { filesChanged: files.size, insertions, deletions } |
| 883 | } |
| 884 | |
| 885 | // Max patch size to return (1MB) - larger patches are truncated |
| 886 | const MAX_PATCH_SIZE = 1024 * 1024 |
no outgoing calls
no test coverage detected