|
|
@@ -27,26 +27,29 @@ const cache = new Map<string, FileDiffMetadata>()
|
|
|
|
|
|
function patch(diff: ReviewDiff) {
|
|
|
if (typeof diff.patch === "string") {
|
|
|
- const [patch] = parsePatch(diff.patch)
|
|
|
+ try {
|
|
|
+ const [patch] = parsePatch(diff.patch)
|
|
|
+ const beforeLines = []
|
|
|
+ const afterLines = []
|
|
|
|
|
|
- const beforeLines = []
|
|
|
- const afterLines = []
|
|
|
-
|
|
|
- for (const hunk of patch.hunks) {
|
|
|
- for (const line of hunk.lines) {
|
|
|
- if (line.startsWith("-")) {
|
|
|
- beforeLines.push(line.slice(1))
|
|
|
- } else if (line.startsWith("+")) {
|
|
|
- afterLines.push(line.slice(1))
|
|
|
- } else {
|
|
|
- // context line (starts with ' ')
|
|
|
- beforeLines.push(line.slice(1))
|
|
|
- afterLines.push(line.slice(1))
|
|
|
+ for (const hunk of patch.hunks) {
|
|
|
+ for (const line of hunk.lines) {
|
|
|
+ if (line.startsWith("-")) {
|
|
|
+ beforeLines.push(line.slice(1))
|
|
|
+ } else if (line.startsWith("+")) {
|
|
|
+ afterLines.push(line.slice(1))
|
|
|
+ } else {
|
|
|
+ // context line (starts with ' ')
|
|
|
+ beforeLines.push(line.slice(1))
|
|
|
+ afterLines.push(line.slice(1))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- return { before: beforeLines.join("\n"), after: afterLines.join("\n"), patch: diff.patch }
|
|
|
+ return { before: beforeLines.join("\n"), after: afterLines.join("\n"), patch: diff.patch }
|
|
|
+ } catch {
|
|
|
+ return { before: "", after: "", patch: diff.patch }
|
|
|
+ }
|
|
|
}
|
|
|
return {
|
|
|
before: "before" in diff && typeof diff.before === "string" ? diff.before : "",
|