Compare commits

...
6 changed files with 41 additions and 10 deletions

No files matched your search

+3 -1
View File
@@ -229,7 +229,9 @@ describe("SessionAssets component", () => {
vi.spyOn(ipc, "call").mockImplementation(async (promise) => {
return promise;
});
vi.spyOn(ipc.commands, "vcsConfigGet").mockResolvedValue("git@github-personal:acme/monorepo.git" as never);
vi.spyOn(ipc.commands, "vcsRemotes").mockResolvedValue([
{ name: "origin", url: "git@github-personal:acme/monorepo.git" },
] as never);
vi.spyOn(ipc.commands, "ghPrList").mockResolvedValue([branchSummary] as never);
vi.spyOn(ipc.commands, "ghApi").mockImplementation((_repo, req) => {
if (req.endpoint === "repos/acme/monorepo/pulls/122518") {
+6 -4
View File
@@ -204,13 +204,15 @@ export function SessionAssets({ task, entries, head, onFocusComposer }: SessionA
const refsAnchor = useRef<HTMLButtonElement>(null);
const artifactsAnchor = useRef<HTMLButtonElement>(null);
// Read `remote.origin.url` so `gh pr checks 123` / `gh issue view 456` resolve to `<owner>/<repo>`.
// Read `origin` (with any `~/.ssh/config` host alias resolved) so `gh pr checks 123` /
// `gh issue view 456` resolve to `<owner>/<repo>`.
useEffect(() => {
if (!isTauri()) return;
let alive = true;
call(commands.vcsConfigGet(repoRoot, "remote.origin.url"))
.then((url) => {
if (alive) setRemoteUrl(url || null);
call(commands.vcsRemotes(repoRoot))
.then((remotes) => {
const origin = remotes.find((r) => r.name === "origin");
if (alive) setRemoteUrl(origin ? (origin.resolvedUrl ?? origin.url) : null);
})
.catch(() => {
if (alive) setRemoteUrl(null);
@@ -6,6 +6,7 @@ import type { MenuItem } from "@/ui";
const config = vi.hoisted(() => new Map<string, string>());
const configReads = vi.hoisted(() => vi.fn());
const remotes = vi.hoisted(() => new Map<string, { name: string; url: string; resolvedUrl?: string | null }[]>());
vi.mock("@/platform/ipc", async (importOriginal) => {
const real = await importOriginal<typeof import("@/platform/ipc")>();
@@ -14,6 +15,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
call: vi.fn(async (request: Promise<unknown>) => request),
commands: {
...real.commands,
vcsRemotes: async (root: string) => remotes.get(root) ?? [],
vcsConfigGet: async (root: string, key: string) => {
configReads(root, key);
return config.get(`${root} ${key}`) ?? null;
@@ -42,6 +44,7 @@ async function start() {
beforeEach(() => {
vi.clearAllMocks();
config.clear();
remotes.clear();
config.set("/p remote.origin.url", "[email protected]:group/sub/app.git");
vi.stubGlobal("navigator", { clipboard: { writeText }, userAgent: navigator.userAgent });
provideNotificationService({ notify });
@@ -113,6 +116,17 @@ describe("Copy Path/Reference… › <hosting> Link", () => {
expect(items({ paths: ["/p/a.ts"] })).toEqual([]);
});
it("builds the link on the web host behind an ~/.ssh/config host alias", async () => {
remotes.set("/p", [
{ name: "origin", url: "[email protected]:acme/app.git", resolvedUrl: "[email protected]:acme/app.git" },
]);
await start();
expect(items({ paths: ["/p/src/main.rs"], line: 9 })[0]).toMatchObject({
label: "GitHub Link",
preview: "https://github.com/acme/app/blob/feature/x/src/main.rs#L10",
});
});
it("warns instead of copying when the file has no page on a remote", async () => {
await executeAction("vcs.copyRemoteLink", { path: "/elsewhere/a.ts", line: 0 });
await vi.waitFor(() =>
+2 -1
View File
@@ -13,6 +13,7 @@ import { executeAction, registerActions, type Action } from "@/platform/actions"
import { checkoutDetached, newBranch, rebaseOnto } from "./branchOps";
import { openUrl } from "./issueLinks";
import { commitWebUrl } from "./model";
import { remoteWebSource } from "./remoteUrl";
import {
commitChangelist,
deleteChangelist,
@@ -156,7 +157,7 @@ function withCommits(fn: (cs: Commit[]) => unknown, allowReadOnly = false) {
async function openCommitInBrowser(c: Commit) {
const upstream = useVcs.getState().branch?.upstream;
const remote = upstream ? upstream.slice(0, upstream.indexOf("/")) : "origin";
const url = await call(commands.vcsConfigGet(currentRepo(), `remote.${remote}.url`)).catch(() => null);
const url = await remoteWebSource(currentRepo(), remote);
const page = url ? commitWebUrl(url, c.id) : null;
if (page) await openUrl(page);
else notifications().notify({ group: "vcs", level: "warning", title: `No web URL for remote '${remote}'` });
+4 -4
View File
@@ -3,13 +3,13 @@
* of its repository's remote, at the current branch's upstream (else the HEAD commit).
* Copy Path/Reference… › <hosting> Link copies that page's address, with the selected lines.
*/
import { call, commands } from "@/platform/ipc";
import { executeAction, type Action } from "@/platform/actions";
import { writeClipboardText } from "@/platform/clipboard";
import { tx } from "@/platform/i18n";
import { notifications, registerMenuGroup } from "@/workbench/contributions";
import { openUrl } from "./issueLinks";
import { fileWebUrl, remoteHosting, rootOf } from "./model";
import { remoteWebSource } from "./remoteUrl";
import { useVcs } from "./store";
interface Target {
@@ -30,9 +30,9 @@ function remoteName(root: string): string {
}
async function readRemoteUrl(root: string): Promise<string | null> {
const url = await call(commands.vcsConfigGet(root, `remote.${remoteName(root)}.url`)).catch(() => null);
remoteUrls.set(root, url || null);
return url || null;
const url = await remoteWebSource(root, remoteName(root));
remoteUrls.set(root, url);
return url;
}
function revision(root: string): string | null {
+12
View File
@@ -0,0 +1,12 @@
import { call, commands } from "@/platform/ipc";
/**
* The URL web pages of `remote` in `repo` are built from: its fetch URL with any `~/.ssh/config`
* host alias resolved (`[email protected]:o/r` → `[email protected]:o/r`). Null without that remote.
*/
export async function remoteWebSource(repo: string | null, remote: string): Promise<string | null> {
const remotes = await call(commands.vcsRemotes(repo)).catch(() => null);
const found = remotes?.find((r) => r.name === remote);
if (found) return found.resolvedUrl ?? found.url;
return (await call(commands.vcsConfigGet(repo, `remote.${remote}.url`)).catch(() => null)) || null;
}