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>
This commit is contained in:
nllptrx
2026-07-17 15:03:26 +08:00
committed by GitHub
co-authored by Mohamed Boudra
parent 04d1ebdce0
commit a8ebd390fa
187 changed files with 20988 additions and 2907 deletions
@@ -7,10 +7,57 @@ import {
CheckoutGithubSetAutoMergeResponseSchema,
CheckoutPrMergeRequestSchema,
CheckoutPrStatusSchema,
ForgeSearchResponseSchema,
GitHubSearchResponseSchema,
ServerInfoStatusPayloadSchema,
} from "./messages.js";
describe("checkout PR schemas", () => {
test("defaults missing forge identity for old daemon payloads", () => {
const parsed = CheckoutPrStatusSchema.parse({
url: "https://github.com/getpaseo/paseo/pull/42",
title: "Ship it",
state: "open",
baseRefName: "main",
headRefName: "feature/ship-it",
isMerged: false,
});
expect(parsed.forge).toBe("github");
});
test("round-trips forge and neutral project identity", () => {
const payload = {
forge: "github",
projectPath: "getpaseo/paseo",
url: "https://github.com/getpaseo/paseo/pull/42",
title: "Ship it",
state: "open",
baseRefName: "main",
headRefName: "feature/ship-it",
isMerged: false,
isDraft: false,
mergeable: "UNKNOWN" as const,
checks: [],
};
expect(CheckoutPrStatusSchema.parse(payload)).toEqual(payload);
});
test("accepts unknown future forge identities", () => {
const parsed = CheckoutPrStatusSchema.parse({
forge: "someforge",
url: "https://someforge.example/getpaseo/paseo/pulls/42",
title: "Ship it",
state: "open",
baseRefName: "main",
headRefName: "feature/ship-it",
isMerged: false,
});
expect(parsed.forge).toBe("someforge");
});
test("parses PR status payloads without mergeability", () => {
expect(
CheckoutPrStatusSchema.parse({
@@ -89,6 +136,248 @@ describe("checkout PR schemas", () => {
});
});
test("keeps forgeSpecific absent for old daemons that only send github facts", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 42,
url: "https://github.com/getpaseo/paseo/pull/42",
title: "Ship it",
state: "open",
baseRefName: "main",
headRefName: "feature/ship-it",
isMerged: false,
github: {
mergeStateStatus: "CLEAN",
autoMergeRequest: null,
repository: {
autoMergeAllowed: false,
mergeCommitAllowed: true,
squashMergeAllowed: true,
rebaseMergeAllowed: false,
viewerDefaultMergeMethod: "MERGE",
},
},
});
expect(parsed.github?.mergeStateStatus).toBe("CLEAN");
expect(parsed.forgeSpecific).toBeUndefined();
});
test("preserves a github forgeSpecific envelope", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 7,
url: "https://github.com/getpaseo/paseo/pull/7",
title: "Ship it",
state: "open",
baseRefName: "main",
headRefName: "feature/ship-it",
isMerged: false,
github: {
mergeStateStatus: "CLEAN",
autoMergeRequest: null,
repository: {
autoMergeAllowed: false,
mergeCommitAllowed: true,
squashMergeAllowed: true,
rebaseMergeAllowed: false,
viewerDefaultMergeMethod: "MERGE",
},
},
forgeSpecific: {
forge: "github",
mergeStateStatus: "CLEAN",
autoMergeRequest: null,
repository: {
autoMergeAllowed: false,
mergeCommitAllowed: true,
squashMergeAllowed: true,
rebaseMergeAllowed: false,
viewerDefaultMergeMethod: "MERGE",
},
},
});
expect(parsed.forgeSpecific).toMatchObject({ forge: "github", mergeStateStatus: "CLEAN" });
});
test("preserves a gitlab forgeSpecific envelope without protocol-side defaults", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 1,
url: "https://gitlab.com/group/subgroup/repo/-/merge_requests/1",
title: "Add sample change",
state: "open",
baseRefName: "main",
headRefName: "feat/sample-change",
isMerged: false,
projectPath: "group/subgroup/repo",
forgeSpecific: {
forge: "gitlab",
detailedMergeStatus: "mergeable",
hasConflicts: false,
blockingDiscussionsResolved: true,
approvalsRequired: 1,
approvalsGiven: 1,
pipelineStatus: "success",
mergeWhenPipelineSucceeds: false,
},
});
expect(parsed.forgeSpecific).toEqual({
forge: "gitlab",
detailedMergeStatus: "mergeable",
hasConflicts: false,
blockingDiscussionsResolved: true,
approvalsRequired: 1,
approvalsGiven: 1,
pipelineStatus: "success",
mergeWhenPipelineSucceeds: false,
});
expect(parsed.github).toBeUndefined();
});
test("preserves a gitea forgeSpecific envelope", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 5,
url: "https://codeberg.org/example/repo/pulls/5",
title: "Add sample change",
state: "open",
baseRefName: "main",
headRefName: "feat/sample-change",
isMerged: false,
forgeSpecific: {
forge: "gitea",
mergeable: true,
hasMerged: false,
ciStatus: "success",
},
});
expect(parsed.forgeSpecific).toEqual({
forge: "gitea",
mergeable: true,
hasMerged: false,
ciStatus: "success",
});
});
test("preserves an unknown forgeSpecific envelope without failing the parse", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 9,
url: "https://example.com/forge/9",
title: "Future forge",
state: "open",
baseRefName: "main",
headRefName: "feature/future",
isMerged: false,
forgeSpecific: { forge: "bitbucket", somethingNew: true },
});
expect(parsed.forgeSpecific).toEqual({ forge: "bitbucket", somethingNew: true });
});
test("preserves forgejo-specific facts as runtime-owned facts", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 10,
url: "https://codeberg.org/example/repo/pulls/10",
title: "Future Forgejo facts",
state: "open",
baseRefName: "main",
headRefName: "feature/forgejo",
isMerged: false,
forgeSpecific: { forge: "forgejo", approvalsRequired: 2 },
});
expect(parsed.forgeSpecific).toEqual({ forge: "forgejo", approvalsRequired: 2 });
});
test("preserves malformed known-family facts for runtime validation", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 11,
url: "https://gitlab.com/group/repo/-/merge_requests/11",
title: "Runtime facts",
state: "open",
baseRefName: "main",
headRefName: "feature/runtime-facts",
isMerged: false,
forgeSpecific: {
forge: "gitlab",
pipelineId: "not-a-number",
approvalsRequired: "also-runtime-owned",
},
});
expect(parsed.forgeSpecific).toEqual({
forge: "gitlab",
pipelineId: "not-a-number",
approvalsRequired: "also-runtime-owned",
});
});
test("keeps forge-specific facts structural for feature-owned interpretation", () => {
const parsed = CheckoutPrStatusSchema.parse({
number: 12,
url: "https://example.com/forge/12",
title: "Missing facts tag",
state: "open",
baseRefName: "main",
headRefName: "feature/missing-tag",
isMerged: false,
forgeSpecific: { approvalsRequired: 2 },
});
expect(parsed.forgeSpecific).toEqual({ approvalsRequired: 2 });
});
test("keeps forge search responses structural", () => {
expect(
ForgeSearchResponseSchema.parse({
type: "forge.search.response",
payload: {
items: [
{
kind: "change_request",
number: 17,
title: "Fix search",
url: "https://gitlab.com/acme/repo/-/merge_requests/17",
state: "open",
body: null,
labels: [],
},
{ kind: "future_kind", futureField: true },
],
authState: "future_auth_state",
error: null,
requestId: "search-2",
},
}).payload,
).toEqual({
items: [
{
kind: "change_request",
number: 17,
title: "Fix search",
url: "https://gitlab.com/acme/repo/-/merge_requests/17",
state: "open",
body: null,
labels: [],
},
{ kind: "future_kind", futureField: true },
],
authState: "future_auth_state",
error: null,
requestId: "search-2",
});
expect(
GitHubSearchResponseSchema.parse({
type: "github_search_response",
payload: {
items: [],
githubFeaturesEnabled: false,
error: null,
requestId: "search-legacy",
},
}).payload,
).toEqual({
items: [],
githubFeaturesEnabled: false,
error: null,
requestId: "search-legacy",
});
});
test("parses optional GitHub check identifiers on PR checks", () => {
expect(
CheckoutPrStatusSchema.parse({
@@ -287,6 +576,83 @@ describe("checkout PR schemas", () => {
});
});
test("accepts a GitLab pipeline through the existing check-details response", () => {
expect(
CheckoutGithubGetCheckDetailsRequestSchema.parse({
type: "checkout.github.get_check_details.request",
cwd: "/tmp/repo",
checkRunId: 306,
requestId: "request-pipeline",
}),
).toEqual({
type: "checkout.github.get_check_details.request",
cwd: "/tmp/repo",
checkRunId: 306,
requestId: "request-pipeline",
});
const details = CheckoutGithubGetCheckDetailsResponseSchema.parse({
type: "checkout.github.get_check_details.response",
payload: {
cwd: "/tmp/repo",
success: true,
details: {
checkRunId: 306,
name: "Pipeline (feat/x)",
annotations: [],
failedJobs: [],
truncated: false,
pipeline: {
id: 306,
status: "future_pipeline_status",
rawStatus: "future_pipeline_status",
stages: [
{
name: "test",
status: "future_stage_status",
jobs: [
{
id: 929,
name: "unit",
stage: "test",
status: "future_job_status",
rawStatus: "future_job_status",
},
],
},
],
},
},
error: null,
requestId: "request-pipeline",
},
}).payload.details;
expect(details?.pipeline).toMatchObject({
id: 306,
status: "future_pipeline_status",
stages: [{ jobs: [{ status: "future_job_status", allowFailure: false }] }],
});
});
test("keeps pipeline absent for legacy and GitHub check-details responses", () => {
const details = CheckoutGithubGetCheckDetailsResponseSchema.parse({
type: "checkout.github.get_check_details.response",
payload: {
cwd: "/tmp/repo",
success: true,
details: {
checkRunId: 12345,
name: "server tests",
},
error: null,
requestId: "legacy-check-details",
},
}).payload.details;
expect(details).not.toHaveProperty("pipeline");
});
test("rejects invalid GitHub check details request identities", () => {
const request = {
type: "checkout.github.get_check_details.request",
@@ -341,6 +707,20 @@ describe("checkout PR schemas", () => {
});
});
test("accepts the forgeProviders server_info feature flag", () => {
expect(
ServerInfoStatusPayloadSchema.parse({
status: "server_info",
serverId: "srv_test",
features: {
forgeProviders: true,
},
}).features,
).toEqual({
forgeProviders: true,
});
});
test("accepts the project removal server_info feature flag", () => {
expect(
ServerInfoStatusPayloadSchema.parse({