Files
paseo/packages/protocol/src/forge-manifest.ts
T
a8ebd390fa feat(forge): pluggable forge abstraction + GitLab and Gitea/Forgejo/Codeberg (#1913)
* refactor(forge): forge-neutral foundation (GitHub-only)

Decouple git-hosting from GitHub behind a neutral abstraction (issue #1616), GitHub-only for now; existing GitHub behaviour is unchanged.

- Forge manifest, neutral ForgeService contract, forge registry + resolver, and a client forge-module registry.
- GitHub code renamed to the neutral shape; PR/Issue attachment wording preserved.
- forge.search.response enums parse tolerantly (unknown kind/auth state degrade instead of breaking the client).
- createPullRequest reports typed CLI/auth errors instead of a generic message.
- forge-resolver host/remote caches are LRU-bounded.
- Forge host trust is explicit: only a known cloud host or a CLI-authenticated host is ever talked to; an unauthenticated GitHub Enterprise host fails resolution instead of routing to github.com.
- Docs: forge-providers guide, glossary and i18n forge-copy conventions, architecture and rpc-namespacing terminology.
- Vitest React Native mocks (unistyles, svg, linking, lucide) consolidated into shared aliased test-stubs.

* feat(forge): GitLab adapter, forge-aware UI, pipelines and approvals

GitLab adapter over the glab CLI on the neutral contracts: MR status, forge-aware UI, pipeline tree, and N-of-M approvals.

- threadIsResolved is part of the neutral timeline item.
- Pipeline load failures show an error instead of an empty section.
- Manual pipeline jobs render as pending.
- Fork/detached MR head pipelines are fetched by MR iid (glab ci get --merge-request).

* feat(forge): Gitea family adapter (Gitea, Forgejo, Codeberg)

One adapter over the tea CLI serving Gitea, Forgejo, and Codeberg on the neutral contracts.

- CI status aggregates commit statuses and Actions runs together.
- Gitea's terminal "warning" state maps to failure on server and client.
- Gitea Actions check details are reachable from the PR pane by workflowRunId.

* refactor(forge): localize compatibility handling

* test(forge): expect normalized GitLab facts

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
2026-07-17 15:03:26 +08:00

146 lines
5.0 KiB
TypeScript

/**
* Declarative manifest of the git forges Paseo knows how to present, mirroring
* provider-manifest.ts. Pure build-time data shared by BOTH the client (icon,
* brand label, PR↔MR relabel) and the server (registry host-matching, prompt
* branding). It is NEVER serialized over the wire, so adding a forge here is not
* a protocol change.
*
* Keep this a pure leaf: no imports, no zod, no functions with runtime deps.
* Behavioural concerns (CLI invocation, host probing, REST adapters) live in the
* server adapter keyed by {@link ForgeDefinition.id}; this file is only the
* declarative half.
*/
/**
* Declarative sign-in recipe for a forge. The client renders install/sign-in
* hints from this data alone — no per-CLI switch — so a new forge wires its auth
* UX entirely from the manifest. Behavioural auth (the actual host probe) stays
* in the server adapter; this is only what the user is told to run.
*/
export interface ForgeSignInCommand {
/** Binary the user installs, e.g. "gh" — shown in the install-CLI hint. */
cli: string;
/** Full sign-in command, e.g. "gh auth login". */
command: string;
/**
* Flag that targets a self-hosted host, e.g. "--hostname". When present and a
* host is known, the client appends `${command} ${hostnameFlag} ${host}`.
* Omit when the command already targets the right host on its own.
*/
hostnameFlag?: string;
}
export interface ForgeDefinition {
/** Registry id, matches the server adapter and the wire `forge` value. */
id: string;
/** Human brand name, e.g. for "Open on GitLab". */
displayName: string;
/** Short change-request noun: "PR" for GitHub, "MR" for GitLab. */
changeRequestAbbrev: string;
/** Full change-request noun: "pull request" vs "merge request". */
changeRequestNoun: string;
/** Prefix before a change-request number: "#" vs "!". */
changeRequestNumberPrefix: string;
/** Prefix before an issue number ("#" on every forge so far). */
issueNumberPrefix: string;
/** Icon key; the client falls back to a generic git icon for unknown values. */
iconKind: string;
/** Sign-in recipe, or null when the forge has no Paseo-driven sign-in. */
signIn: ForgeSignInCommand | null;
/**
* Public cloud hosts this forge owns exactly. A BOUNDED list, never an
* allowlist for self-hosted detection — self-hosted/Enterprise instances are
* recognized at runtime by the adapter's host probe, not by this field.
*/
cloudHosts?: string[];
}
export const FORGE_DEFINITIONS: ForgeDefinition[] = [
{
id: "github",
displayName: "GitHub",
changeRequestAbbrev: "PR",
changeRequestNoun: "pull request",
changeRequestNumberPrefix: "#",
issueNumberPrefix: "#",
iconKind: "github",
signIn: { cli: "gh", command: "gh auth login" },
cloudHosts: ["github.com", "ssh.github.com"],
},
{
id: "gitlab",
displayName: "GitLab",
changeRequestAbbrev: "MR",
changeRequestNoun: "merge request",
changeRequestNumberPrefix: "!",
issueNumberPrefix: "#",
iconKind: "gitlab",
signIn: { cli: "glab", command: "glab auth login", hostnameFlag: "--hostname" },
cloudHosts: ["gitlab.com"],
},
{
id: "gitea",
displayName: "Gitea",
changeRequestAbbrev: "PR",
changeRequestNoun: "pull request",
changeRequestNumberPrefix: "#",
issueNumberPrefix: "#",
iconKind: "gitea",
signIn: { cli: "tea", command: "tea login add" },
cloudHosts: ["gitea.com"],
},
{
id: "forgejo",
displayName: "Forgejo",
changeRequestAbbrev: "PR",
changeRequestNoun: "pull request",
changeRequestNumberPrefix: "#",
issueNumberPrefix: "#",
iconKind: "forgejo",
signIn: { cli: "tea", command: "tea login add" },
},
{
id: "codeberg",
displayName: "Codeberg",
changeRequestAbbrev: "PR",
changeRequestNoun: "pull request",
changeRequestNumberPrefix: "#",
issueNumberPrefix: "#",
iconKind: "codeberg",
signIn: { cli: "tea", command: "tea login add" },
cloudHosts: ["codeberg.org"],
},
];
/** Forge definitions only present in dev builds (none today; mirrors providers). */
export const DEV_FORGE_DEFINITIONS: ForgeDefinition[] = [];
export const FORGE_IDS: string[] = FORGE_DEFINITIONS.map((definition) => definition.id);
export function getForgeDefinition(
id: string,
definitions: ForgeDefinition[] = [...FORGE_DEFINITIONS, ...DEV_FORGE_DEFINITIONS],
): ForgeDefinition | null {
return definitions.find((definition) => definition.id === id) ?? null;
}
/**
* Resolve a forge definition, synthesizing a neutral one for a forge id the
* client has never heard of (e.g. a self-hosted forge a newer daemon reports to
* an older client). The neutral shape renders generic, never GitHub-branded.
*/
export function getForgeDefinitionOrNeutral(id: string): ForgeDefinition {
return (
getForgeDefinition(id) ?? {
id,
displayName: id,
changeRequestAbbrev: "PR",
changeRequestNoun: "pull request",
changeRequestNumberPrefix: "#",
issueNumberPrefix: "#",
iconKind: "git",
signIn: null,
}
);
}