(diffText: string)
| 1 | import { parsePatch } from "diff" |
| 2 | |
| 3 | export function getRevertDiffFiles(diffText: string) { |
| 4 | if (!diffText) return [] |
| 5 | |
| 6 | try { |
| 7 | return parsePatch(diffText).map((patch) => { |
| 8 | const filename = [patch.newFileName, patch.oldFileName].find((item) => item && item !== "/dev/null") ?? "unknown" |
| 9 | return { |
| 10 | filename: filename.replace(/^[ab]\//, ""), |
| 11 | additions: patch.hunks.reduce((sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("+")).length, 0), |
| 12 | deletions: patch.hunks.reduce((sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("-")).length, 0), |
| 13 | } |
| 14 | }) |
| 15 | } catch { |
| 16 | return [] |
| 17 | } |
| 18 | } |
no test coverage detected