Skip to content

Commit ed62957

Browse files
matt2eclaude
andauthored
fix(github): stop claiming PR links the pane cannot show (#920)
Signed-off-by: Matt Toohey <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 96f1c21 commit ed62957

5 files changed

Lines changed: 49 additions & 5 deletions

File tree

‎src/bundled/github/GitHubPanel.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ it.each([
315315
it.each([500])(
316316
"keeps the PR title and prominent external recovery action usable after API failure %s",
317317
async (status) => {
318-
const target = "https://github.com/block/buzz-app/pull/629#discussion_r1";
318+
const target = "https://github.com/block/buzz-app/pull/629#issuecomment-1";
319319
let finish!: (response: Response) => void;
320320
const response = new Promise<Response>((resolve) => {
321321
finish = resolve;

‎src/bundled/github/data.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { parseGitHubReference } from "./references";
44

55
afterEach(() => vi.unstubAllGlobals());
66
const reference = parseGitHubReference(
7-
"https://github.com/block/buzz/pull/23#discussion_r1",
7+
"https://github.com/block/buzz/pull/23#issuecomment-1",
88
);
99
assert.exists(reference);
1010
it("loads PR details and preserves merged state, branches, and change counts", async () => {

‎src/bundled/github/references.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,35 @@ it("recognizes typed GitHub references while refusing lookalike hosts and invali
2121
])
2222
expect(parseGitHubReference(url)).toBeUndefined();
2323
});
24+
25+
it("claims only PR and issue links whose target the pane can show", () => {
26+
const pull = "https://github.com/block/buzz-app/pull/838";
27+
for (const fragment of ["", "#issuecomment-123", "#pullrequestreview-456"])
28+
expect(parseGitHubReference(`${pull}${fragment}`)?.url).toBe(
29+
`${pull}${fragment}`,
30+
);
31+
expect(
32+
parseGitHubReference("https://github.com/block/buzz-app/issues/12")?.url,
33+
).toBe("https://github.com/block/buzz-app/issues/12");
34+
for (const url of [
35+
`${pull}#discussion_r4240253516`,
36+
`${pull}#event-987`,
37+
`${pull}#partial-timeline`,
38+
`${pull}#issuecomment-`,
39+
`${pull}#pullrequestreview-abc`,
40+
`${pull}/files`,
41+
`${pull}/files#diff-0123abcd`,
42+
`${pull}/files#r4240253516`,
43+
`${pull}/files/abcdef1..0123456`,
44+
`${pull}/commits`,
45+
`${pull}/commits/abcdef1`,
46+
`${pull}/commits/abcdef1#r4240253516`,
47+
`${pull}/checks`,
48+
`${pull}/checks?check_run_id=1`,
49+
`${pull}/conflicts`,
50+
`${pull}/changes`,
51+
`${pull}/activity`,
52+
"https://github.com/block/buzz-app/issues/12#issuecomment-123",
53+
])
54+
expect(parseGitHubReference(url), url).toBeUndefined();
55+
});

‎src/bundled/github/references.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ export type GitHubReference = Readonly<{
44
kind: "repository" | "pull" | "issue" | "commit";
55
label: string;
66
}>;
7+
/**
8+
* Fragments the pane can show. The PR Discussion tab lists conversation
9+
* comments and submitted reviews; review-thread (`discussion_r…`), timeline
10+
* event and other anchors fall through to the browser instead of opening a
11+
* pane that cannot show them. Issues render only their body, so no fragment
12+
* qualifies.
13+
*/
14+
const displayableFragments = {
15+
pull: /^(?:#(?:issuecomment|pullrequestreview)-\d+)?$/,
16+
issues: /^$/,
17+
};
718
/** Exact host parsing: a lookalike domain or credentials can never become a GitHub card. */
819
export function parseGitHubReference(
920
value: string,
@@ -30,7 +41,8 @@ export function parseGitHubReference(
3041
if (
3142
(surface === "pull" || surface === "issues") &&
3243
rest.length === 1 &&
33-
/^[1-9]\d*$/.test(target)
44+
/^[1-9]\d*$/.test(target) &&
45+
displayableFragments[surface].test(url.hash)
3446
) {
3547
return {
3648
url: `${base}/${surface}/${target}${url.hash}`,

‎tests/browser/external-links.spec.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ test("GitHub API errors offer prominent external opening before retry", async ({
106106
context,
107107
app,
108108
}, testInfo) => {
109-
const target = `${github}#discussion_r1`;
109+
const target = `${github}#issuecomment-1`;
110110
const detailsUrl = "https://api.github.com/repos/block/buzz/pulls/1";
111111
// Permit only this injected response's engine console report, once by exact URL.
112112
app.report.githubFailures = [detailsUrl];
@@ -198,7 +198,7 @@ test("message link context menus bypass the pane and return keyboard focus", asy
198198
context,
199199
app,
200200
}, testInfo) => {
201-
const target = `${github}?view=all#discussion_r1`;
201+
const target = `${github}?view=all#issuecomment-1`;
202202
for (const destination of [github, ordinary]) {
203203
await context.route(`${destination}**`, (route) =>
204204
route.fulfill({

0 commit comments

Comments
 (0)