mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-19 23:05:21 +00:00
* fix(forge): build web links from the host and repository the daemon resolves The app built forge links by parsing the origin remote itself, so an SSH config alias (git@github.com-work:...) produced https://github.com-work/... and a fork checkout sent #123 to the fork instead of the repository that owns the numbers. The daemon now publishes `forgeWeb` { host, referenceRepository? } on the workspace descriptor and on checkout status, and the app builds every forge URL from it. The host is the ssh -G resolved cloud host. referenceRepository is the fork's parent, read through an optional ForgeService.getReferenceRepository (GitHub, GitLab, Gitea family). Branch and file links stay on the origin repository because a feature branch usually exists only on the fork. Old daemons omit the field and the app derives links from the remote as before (tagged COMPAT(forgeWeb)). * fix(forge): keep the published web location tied to its remote and retry failed parent lookups - A web location resolved for one origin remote is no longer published after `git remote set-url`; it returns when the next forge refresh resolves the new remote. - The GitHub parent lookup rejects on a gh failure instead of returning null, so a network error is retried rather than cached as "this repository has no parent". - The pull request status poll retries a due lookup, so an idle workspace recovers without waiting for a forced refresh. - Workspace snapshot fixtures now expect `forgeWeb` for github.com remotes. * fix(forge): look up a fork's parent once per remote, on any checkout - A successful parent lookup is kept for the life of the remote instead of being repeated by every forced refresh (each push, fetch and branch switch). - The lookup no longer waits on the pull request status's auth state, which is "no_remote" on a detached HEAD; a failed or signed-out lookup is retried on the next forced refresh or poll. * fix(forge): resolve the new remote's web location when origin changes `git remote set-url` reaches the daemon as a git-only refresh, which stopped publishing the old remote's forgeWeb but never resolved the new one, so links fell back to parsing the remote. A git refresh that finds the remote changed since the last forge refresh now runs a forced forge refresh, which also probes a newly seen SSH alias. * fix(forge): keep the alias-resolved host when a failed parent lookup is retried The poll's retry resolved the forge with the synchronous resolver, which reports the raw SSH alias as the host. A lookup that settled on retry then published and kept `github.com-work` as the web host. The retry now uses the async resolver, like the forge refresh, so the host means the same thing on both paths. * fix(forge): treat a Gitea or GitLab API error body as a failed parent lookup `tea api` exits 0 on HTTP errors, so an error body parsed as a repository without a parent and was cached as "not a fork". The repository schemas now require the repository's own name, so an error body rejects and the lookup is retried. The shorthand provider also keys its context on the forgeWeb strings, so unrelated workspace updates no longer re-render every Markdown message. * fix(forge): keep the parent lookup off the workspace refresh path * fix(forge): keep a parent answer that lands during a refresh * test(forge): make the parent lookup tests Windows-safe * fix(forge): drain the background parent lookup on dispose * test(forge): retry temp cleanup after the poll lookup on Windows
140 lines
4.7 KiB
TypeScript
140 lines
4.7 KiB
TypeScript
import { getForgeDefinition } from "./forge-manifest.js";
|
|
|
|
const GITHUB_HOSTS = new Set(getForgeDefinition("github")?.cloudHosts ?? []);
|
|
|
|
const TRANSPORT_BY_PROTOCOL: Record<string, GitRemoteLocation["transport"]> = {
|
|
"https:": "https",
|
|
"http:": "http",
|
|
"ssh:": "ssh",
|
|
};
|
|
|
|
const DEFAULT_PORT_BY_PROTOCOL: Record<string, string> = {
|
|
"https:": "443",
|
|
"http:": "80",
|
|
"ssh:": "22",
|
|
};
|
|
|
|
export interface GitRemoteLocation {
|
|
transport: "scp" | "ssh" | "http" | "https";
|
|
host: string;
|
|
/**
|
|
* Explicit non-default port from the remote (e.g. a self-hosted forge on
|
|
* `:60443`), or undefined for a default-port or scp-form remote. Kept separate
|
|
* from `host` so host-identity matching (forge detection, cloud-host checks)
|
|
* stays port-agnostic; only consumers that reconstruct a URL (web links) use it.
|
|
*/
|
|
port?: string;
|
|
path: string;
|
|
}
|
|
|
|
export interface GitHubRemoteIdentity {
|
|
owner: string;
|
|
name: string;
|
|
repo: string;
|
|
}
|
|
|
|
export function parseGitHubRemoteUrl(remoteUrl: string): GitHubRemoteIdentity | null {
|
|
const location = parseGitRemoteLocation(remoteUrl);
|
|
if (!location || !isGitHubHost(location.host)) return null;
|
|
return parseGitHubRemoteIdentity(location.path);
|
|
}
|
|
|
|
/**
|
|
* Whether `repo` is already a complete git remote (a URL or scp-like address)
|
|
* rather than `owner/repo` shorthand that still needs a clone protocol picked.
|
|
*
|
|
* Clients (app + CLI) and the daemon must agree on this classification: the
|
|
* daemon treats `parseGitRemoteLocation(repo) !== null` as "complete remote"
|
|
* and everything else as shorthand, so reuse the same parser here instead of a
|
|
* separate regex that would drift (e.g. accepting `git://` the parser rejects).
|
|
*/
|
|
export function isCompleteGitRemote(repo: string): boolean {
|
|
return parseGitRemoteLocation(repo) !== null;
|
|
}
|
|
|
|
export function parseGitRemoteLocation(remoteUrl: string): GitRemoteLocation | null {
|
|
const trimmed = remoteUrl.trim();
|
|
if (!trimmed) return null;
|
|
|
|
// scp form has no scheme. Testing it first would match `ssh://git@host:22/x`
|
|
// — `[^@]+` happily eats `ssh://git` — and swallow the port into the path.
|
|
const scpLike = trimmed.includes("://") ? null : trimmed.match(/^[^@]+@([^:]+):(.+)$/u);
|
|
if (scpLike) {
|
|
const host = normalizeHost(scpLike[1] ?? "");
|
|
const path = normalizeRemotePath(scpLike[2] ?? "");
|
|
if (!isValidRemoteHost(host) || !path) return null;
|
|
return { transport: "scp", host, path };
|
|
}
|
|
|
|
let parsed: URL;
|
|
try {
|
|
parsed = new URL(trimmed);
|
|
} catch {
|
|
return null;
|
|
}
|
|
|
|
const transport = TRANSPORT_BY_PROTOCOL[parsed.protocol.toLowerCase()];
|
|
if (!transport) return null;
|
|
|
|
const host = normalizeHost(parsed.hostname);
|
|
let path: string;
|
|
try {
|
|
path = decodeURIComponent(parsed.pathname);
|
|
} catch {
|
|
return null;
|
|
}
|
|
const normalizedPath = normalizeRemotePath(path);
|
|
if (!isValidRemoteHost(host) || !normalizedPath) return null;
|
|
|
|
const protocol = parsed.protocol.toLowerCase();
|
|
const port =
|
|
parsed.port && parsed.port !== DEFAULT_PORT_BY_PROTOCOL[protocol] ? parsed.port : undefined;
|
|
return { transport, host, port, path: normalizedPath };
|
|
}
|
|
|
|
export function parseGitHubRemoteIdentity(path: string): GitHubRemoteIdentity | null {
|
|
const segments = path.split("/").filter(Boolean);
|
|
if (segments.length !== 2) return null;
|
|
const [owner, name] = segments;
|
|
if (!owner || !name) return null;
|
|
return { owner, name, repo: `${owner}/${name}` };
|
|
}
|
|
|
|
export function isGitHubHost(host: string): boolean {
|
|
return GITHUB_HOSTS.has(host);
|
|
}
|
|
|
|
export function normalizeHost(host: string): string {
|
|
return host.trim().replace(/\.+$/u, "").toLowerCase();
|
|
}
|
|
|
|
/** Whether `host` is one of the forge's public cloud hosts, SSH aliases included. */
|
|
export function isForgeCloudHost(forge: string, host: string): boolean {
|
|
const cloudHosts = (getForgeDefinition(forge)?.cloudHosts ?? []).map(normalizeHost);
|
|
return cloudHosts.includes(normalizeHost(host));
|
|
}
|
|
|
|
/**
|
|
* Web host for a remote host of `forge`. A cloud SSH alias (a non-first entry
|
|
* in the forge's `cloudHosts`, e.g. ssh.github.com) maps to the forge's web
|
|
* host (`cloudHosts[0]`); any other host, self-hosted included, is returned
|
|
* as is.
|
|
*/
|
|
export function forgeWebHost(forge: string, host: string): string {
|
|
const normalized = normalizeHost(host);
|
|
if (!isForgeCloudHost(forge, normalized)) {
|
|
return normalized;
|
|
}
|
|
return normalizeHost(getForgeDefinition(forge)?.cloudHosts?.[0] ?? normalized);
|
|
}
|
|
|
|
function normalizeRemotePath(path: string): string | null {
|
|
let normalized = path.trim().replace(/^\/+|\/+$/gu, "");
|
|
if (normalized.endsWith(".git")) normalized = normalized.slice(0, -4);
|
|
return normalized || null;
|
|
}
|
|
|
|
function isValidRemoteHost(host: string): boolean {
|
|
return /^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/u.test(host);
|
|
}
|