authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 00:22:17-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 00:22:17-07:00
logba873b8181c3741603a365e75785457064a52ffd
treeb8410d88010ab21cf0fd76cf2697c4960c609a4f
parent3fedf52467dd8d2734a7aca4c6c7da421c12474f
signature Signed by PGP key B5690EEEBB952194

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


2 files changed, 1 insertions(+), 67 deletions(-)

apps/web/src/lib/openPullRequestLink.test.ts+1-30
......@@ -1,14 +1,12 @@
1import { describe, expect, it, vi } from "vite-plus/test";
1import { describe, expect, it } from "vite-plus/test";
22
33import {
44 changeRequestRepositoryUrl,
55 findProjectForChangeRequest,
66 gitHubPullRequestBrowserUrl,
77 matchesLinkedPullRequestUrl,
8 openPullRequestLink,
98 parseChangeRequestUrl,
109 pullRequestCandidateUrlFromReferenceAutolink,
11 PullRequestLinkOpenError,
1210 shouldOpenPullRequestExternally,
1311} from "./openPullRequestLink";
1412import { ProjectId, type RepositoryIdentity } from "@t3tools/contracts";
......@@ -184,33 +182,6 @@ describe("matchesLinkedPullRequestUrl", () => {
184182 });
185183});
186184
187describe("openPullRequestLink", () => {
188 it("opens the requested pull request URL", async () => {
189 const openExternal = vi.fn(async () => undefined);
190 const targetUrl = "https://github.com/pingdotgg/t3code/pull/123";
191
192 await openPullRequestLink({ openExternal }, targetUrl);
193
194 expect(openExternal).toHaveBeenCalledExactlyOnceWith(targetUrl);
195 });
196
197 it("reports bridge failures with a safe target origin", async () => {
198 const cause = new Error("desktop shell unavailable");
199 const targetUrl = "https://github.com/pingdotgg/t3code/pull/123?token=secret";
200 const openExternal = vi.fn(async () => Promise.reject(cause));
201
202 const result = openPullRequestLink({ openExternal }, targetUrl);
203
204 await expect(result).rejects.toEqual(
205 new PullRequestLinkOpenError({
206 targetOrigin: "https://github.com",
207 cause,
208 }),
209 );
210 await expect(result).rejects.not.toHaveProperty("message", expect.stringContaining("secret"));
211 });
212});
213
214185describe("shouldOpenPullRequestExternally", () => {
215186 it("uses the browser for command-click and control-click", () => {
216187 expect(shouldOpenPullRequestExternally({ metaKey: true, ctrlKey: false })).toBe(true);
apps/web/src/lib/openPullRequestLink.ts-37
......@@ -1,12 +1,10 @@
11import type {
22 EnvironmentId,
3 LocalApi,
43 RepositoryIdentity,
54 ScopedThreadRef,
65 ThreadLinkedPullRequest,
76} from "@t3tools/contracts";
87import { useNavigate } from "@tanstack/react-router";
9import * as Schema from "effect/Schema";
108import { type MouseEvent, useCallback } from "react";
119
1210import { pullRequestHostOf, type SourceControlProviderKind } from "@t3tools/contracts";
......@@ -19,41 +17,6 @@ import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
1917import { useProjects, useServerConfigs } from "../state/entities";
2018import { usePrimaryEnvironmentId } from "../state/environments";
2119
22export class PullRequestLinkOpenError extends Schema.TaggedErrorClass<PullRequestLinkOpenError>()(
23 "PullRequestLinkOpenError",
24 {
25 targetOrigin: Schema.NullOr(Schema.String),
26 cause: Schema.Defect(),
27 },
28) {
29 static fromCause(targetUrl: string, cause: unknown): PullRequestLinkOpenError {
30 let targetOrigin: string | null = null;
31 try {
32 targetOrigin = new URL(targetUrl).origin;
33 } catch {
34 // Keep malformed URLs out of diagnostics while preserving the open failure below.
35 }
36 return new PullRequestLinkOpenError({ targetOrigin, cause });
37 }
38
39 override get message(): string {
40 return this.targetOrigin === null
41 ? "Unable to open pull request link."
42 : `Unable to open pull request link at ${this.targetOrigin}.`;
43 }
44}
45
46export async function openPullRequestLink(
47 shell: Pick<LocalApi["shell"], "openExternal">,
48 targetUrl: string,
49): Promise<void> {
50 try {
51 await shell.openExternal(targetUrl);
52 } catch (cause) {
53 throw PullRequestLinkOpenError.fromCause(targetUrl, cause);
54 }
55}
56
5720/** Builds a GitHub URL that remains available when the pull request API cannot be read. */
5821export function gitHubPullRequestBrowserUrl(
5922 identity: RepositoryIdentity | null | undefined,