Skip to content

Commit 0e21bfd

Browse files
refactor(web): remove obsolete pull request link opener
1 parent d2c3e2e commit 0e21bfd

2 files changed

Lines changed: 1 addition & 67 deletions

File tree

‎apps/web/src/lib/openPullRequestLink.test.ts‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { describe, expect, it, vi } from "vite-plus/test";
1+
import { describe, expect, it } from "vite-plus/test";
22

33
import {
44
changeRequestRepositoryUrl,
55
findProjectForChangeRequest,
66
gitHubPullRequestBrowserUrl,
77
matchesLinkedPullRequestUrl,
8-
openPullRequestLink,
98
parseChangeRequestUrl,
109
pullRequestCandidateUrlFromReferenceAutolink,
11-
PullRequestLinkOpenError,
1210
shouldOpenPullRequestExternally,
1311
} from "./openPullRequestLink";
1412
import { ProjectId, type RepositoryIdentity } from "@t3tools/contracts";
@@ -184,33 +182,6 @@ describe("matchesLinkedPullRequestUrl", () => {
184182
});
185183
});
186184

187-
describe("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-
214185
describe("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‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import type {
22
EnvironmentId,
3-
LocalApi,
43
RepositoryIdentity,
54
ScopedThreadRef,
65
ThreadLinkedPullRequest,
76
} from "@t3tools/contracts";
87
import { useNavigate } from "@tanstack/react-router";
9-
import * as Schema from "effect/Schema";
108
import { type MouseEvent, useCallback } from "react";
119

1210
import { pullRequestHostOf, type SourceControlProviderKind } from "@t3tools/contracts";
@@ -19,41 +17,6 @@ import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
1917
import { useProjects, useServerConfigs } from "../state/entities";
2018
import { usePrimaryEnvironmentId } from "../state/environments";
2119

22-
export 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-
46-
export 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. */
5821
export function gitHubPullRequestBrowserUrl(
5922
identity: RepositoryIdentity | null | undefined,

0 commit comments

Comments
 (0)