Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): keep review comments inside the pull request's hunks #12583

Mergedagomesp(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/12583/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 91 additions and 1 deletion.

x
0 of 2 viewed, 2 left
76 additions and 0 deletionsapps/web/src/reviewCommentContext.test.tsModified
View file
@@ -1,3 +1,4 @@
+import { hydratePartialDiff } from "@pierre/diffs";
import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles";
import { describe, expect, it } from "vite-plus/test";
​
@@ -6,6 +7,7 @@
buildFileReviewComment,
formatReviewCommentFence,
inferReviewCommentFenceLanguage,
+ resolveDiffReviewPosition,
restoreDiffReviewCommentRange,
} from "./reviewCommentContext";
​
@@ -112,4 +114,78 @@
endSide: "additions",
});
});
+​
+ it("anchors review comments only on lines inside the host's hunks", () => {
+ const oldLines = Array.from({ length: 30 }, (_, index) => `line ${index + 1}\n`);
+ const newLines = [
+ ...oldLines.slice(0, 6),
+ ...Array.from({ length: 10 }, (_, index) => `new ${index + 1}\n`),
+ ...oldLines.slice(6),
+ ].map((line) => (line === "line 25\n" ? "line twenty-five\n" : line));
+ // What the host returns: new lines 4 to 19 and 32 to 38. The insertion shifts the new side,
+ // so new line 25 (old line 15) sits between the hunks while old line 25 is inside one.
+ const fileDiff = parsePatchFiles(
+ [