Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apps/loopover-extension/content.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
const target = matchGitHubPageTarget(location.pathname);

if (target?.kind === "pull_request") {
if (target) {
mountOverlay(target);
}

// #7462: pull-request pages only — issue classification was dead (manifest matched issues/*
// but nothing consumed kind:"issue", and there is no issue-context backend route).
function matchGitHubPageTarget(pathname) {
const match = String(pathname ?? "").match(/^\/([^/]+)\/([^/]+)\/(pull|issues)\/(\d+)(?:\/|$)/);
const match = String(pathname ?? "").match(/^\/([^/]+)\/([^/]+)\/pull\/(\d+)(?:\/|$)/);
if (!match) return null;
const [, owner, repo, surface, number] = match;
if (surface === "pull") return { kind: "pull_request", owner, repo, pullNumber: Number(number) };
return { kind: "issue", owner, repo, issueNumber: Number(number) };
const [, owner, repo, number] = match;
return { kind: "pull_request", owner, repo, pullNumber: Number(number) };
}

function matchPullRequestTarget(pathname) {
const target = matchGitHubPageTarget(pathname);
if (target?.kind !== "pull_request") return null;
if (!target) return null;
return { owner: target.owner, repo: target.repo, pullNumber: target.pullNumber };
}

Expand Down
2 changes: 1 addition & 1 deletion apps/loopover-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"content_scripts": [
{
"matches": ["https://github.com/*/*/pull/*", "https://github.com/*/*/issues/*"],
"matches": ["https://github.com/*/*/pull/*"],
"js": ["content.js"],
"css": ["styles.css"],
"run_at": "document_idle"
Expand Down
20 changes: 12 additions & 8 deletions test/unit/extension-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import { Script, createContext } from "node:vm";
import { describe, expect, it, vi } from "vitest";

const contentScript = readFileSync("apps/loopover-extension/content.js", "utf8");
const manifest = JSON.parse(readFileSync("apps/loopover-extension/manifest.json", "utf8")) as {
content_scripts: Array<{ matches: string[] }>;
};

describe("extension content script", () => {
it("detects GitHub pull request and issue routes while only mounting pull overlays", () => {
it("declares content-script matches for pull pages only (#7462)", () => {
expect(manifest.content_scripts[0]?.matches).toEqual(["https://github.com/*/*/pull/*"]);
expect(manifest.content_scripts[0]?.matches.join("\n")).not.toContain("issues");
});

it("detects GitHub pull request routes and treats issue pages as out of scope", () => {
const internals = loadContentInternals();

expect(internals.matchGitHubPageTarget("/JSONbored/loopover/pull/146")).toEqual({
Expand All @@ -14,12 +22,8 @@ describe("extension content script", () => {
repo: "loopover",
pullNumber: 146,
});
expect(internals.matchGitHubPageTarget("/JSONbored/loopover/issues/145")).toEqual({
kind: "issue",
owner: "JSONbored",
repo: "loopover",
issueNumber: 145,
});
// Issue pages are out of scope — no kind:"issue" classification, and no match.
expect(internals.matchGitHubPageTarget("/JSONbored/loopover/issues/145")).toBeNull();
expect(internals.matchGitHubPageTarget("/JSONbored/loopover/pulls")).toBeNull();
expect(internals.matchPullRequestTarget("/JSONbored/loopover/pull/146")).toEqual({
owner: "JSONbored",
Expand Down Expand Up @@ -91,7 +95,7 @@ function loadContentInternals() {
return vmContext.__loopoverContentInternals as {
matchGitHubPageTarget: (
pathname: string,
) => { kind: "pull_request"; owner: string; repo: string; pullNumber: number } | { kind: "issue"; owner: string; repo: string; issueNumber: number } | null;
) => { kind: "pull_request"; owner: string; repo: string; pullNumber: number } | null;
matchPullRequestTarget: (pathname: string) => { owner: string; repo: string; pullNumber: number } | null;
renderPullContext: (payload: unknown) => string;
};
Expand Down
Loading