(diff: string)
| 6 | } |
| 7 | |
| 8 | export function countUnifiedDiffStats(diff: string): { |
| 9 | additions: number; |
| 10 | deletions: number; |
| 11 | } { |
| 12 | let additions = 0; |
| 13 | let deletions = 0; |
| 14 | let inHunk = false; |
| 15 | |
| 16 | for (const line of diff.split("\n")) { |
| 17 | if (line.startsWith("diff --git") || line.startsWith("index ")) { |
| 18 | inHunk = false; |
| 19 | continue; |
| 20 | } |
| 21 | |
| 22 | if (line.startsWith("@@")) { |
| 23 | inHunk = true; |
| 24 | continue; |
| 25 | } |
| 26 | |
| 27 | if (!inHunk) { |
| 28 | if (line.startsWith("---") || line.startsWith("+++")) { |
| 29 | continue; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | if (inHunk) { |
| 34 | if (line.startsWith("+")) { |
| 35 | additions += 1; |
| 36 | } else if (line.startsWith("-")) { |
| 37 | deletions += 1; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return { additions, deletions }; |
| 43 | } |
| 44 | |
| 45 | function countTextDiffStats( |
| 46 | original: string, |
no outgoing calls
no test coverage detected