refactor(web): remove obsolete pull request link opener (#9983)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-05 00:22:17 -07:00
1 parent 3fedf52467
commit ba873b8181
2 files changed
+1 -67

No files matched your search

+1 -30
View File
@@ -1,14 +1,12 @@
import { describe, expect, it, vi } from "vite-plus/test";
import { describe, expect, it } from "vite-plus/test";
import {
changeRequestRepositoryUrl,
findProjectForChangeRequest,
gitHubPullRequestBrowserUrl,
matchesLinkedPullRequestUrl,
openPullRequestLink,
parseChangeRequestUrl,
pullRequestCandidateUrlFromReferenceAutolink,
PullRequestLinkOpenError,
shouldOpenPullRequestExternally,
} from "./openPullRequestLink";
import { ProjectId, type RepositoryIdentity } from "@t3tools/contracts";
@@ -184,33 +182,6 @@ describe("matchesLinkedPullRequestUrl", () => {
});
});
describe("openPullRequestLink", () => {
it("opens the requested pull request URL", async () => {
const openExternal = vi.fn(async () => undefined);
const targetUrl = "https://github.com/pingdotgg/t3code/pull/123";
await openPullRequestLink({ openExternal }, targetUrl);
expect(openExternal).toHaveBeenCalledExactlyOnceWith(targetUrl);
});
it("reports bridge failures with a safe target origin", async () => {
const cause = new Error("desktop shell unavailable");
const targetUrl = "https://github.com/pingdotgg/t3code/pull/123?token=secret";
const openExternal = vi.fn(async () => Promise.reject(cause));
const result = openPullRequestLink({ openExternal }, targetUrl);
await expect(result).rejects.toEqual(
new PullRequestLinkOpenError({
targetOrigin: "https://github.com",
cause,
}),
);
await expect(result).rejects.not.toHaveProperty("message", expect.stringContaining("secret"));
});
});
describe("shouldOpenPullRequestExternally", () => {
it("uses the browser for command-click and control-click", () => {
expect(shouldOpenPullRequestExternally({ metaKey: true, ctrlKey: false })).toBe(true);
-37
View File
@@ -1,12 +1,10 @@
import type {
EnvironmentId,
LocalApi,
RepositoryIdentity,
ScopedThreadRef,
ThreadLinkedPullRequest,
} from "@t3tools/contracts";
import { useNavigate } from "@tanstack/react-router";
import * as Schema from "effect/Schema";
import { type MouseEvent, useCallback } from "react";
import { pullRequestHostOf, type SourceControlProviderKind } from "@t3tools/contracts";
@@ -19,41 +17,6 @@ import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import { useProjects, useServerConfigs } from "../state/entities";
import { usePrimaryEnvironmentId } from "../state/environments";
export class PullRequestLinkOpenError extends Schema.TaggedErrorClass<PullRequestLinkOpenError>()(
"PullRequestLinkOpenError",
{
targetOrigin: Schema.NullOr(Schema.String),
cause: Schema.Defect(),
},
) {
static fromCause(targetUrl: string, cause: unknown): PullRequestLinkOpenError {
let targetOrigin: string | null = null;
try {
targetOrigin = new URL(targetUrl).origin;
} catch {
// Keep malformed URLs out of diagnostics while preserving the open failure below.
}
return new PullRequestLinkOpenError({ targetOrigin, cause });
}
override get message(): string {
return this.targetOrigin === null
? "Unable to open pull request link."
: `Unable to open pull request link at ${this.targetOrigin}.`;
}
}
export async function openPullRequestLink(
shell: Pick<LocalApi["shell"], "openExternal">,
targetUrl: string,
): Promise<void> {
try {
await shell.openExternal(targetUrl);
} catch (cause) {
throw PullRequestLinkOpenError.fromCause(targetUrl, cause);
}
}
/** Builds a GitHub URL that remains available when the pull request API cannot be read. */
export function gitHubPullRequestBrowserUrl(
identity: RepositoryIdentity | null | undefined,