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:
co-authored by
Mohamed Boudra
parent
04d1ebdce0
commit
a8ebd390fa
@@ -0,0 +1,205 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildForgeBlobUrl, buildForgeBranchTreeUrl, hasForgeWebUrls } from "./forge-url";
|
||||
|
||||
describe("buildForgeBranchTreeUrl", () => {
|
||||
it("builds a branch-specific GitHub tree URL", () => {
|
||||
expect(
|
||||
buildForgeBranchTreeUrl("github", {
|
||||
remoteUrl: "git@github.com:acme/repo.git",
|
||||
branch: "feature/workspace-button",
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/tree/feature/workspace-button");
|
||||
});
|
||||
|
||||
it("encodes reserved branch characters while preserving slash-separated branch names", () => {
|
||||
expect(
|
||||
buildForgeBranchTreeUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "feature/ship #42",
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/tree/feature/ship%20%2342");
|
||||
});
|
||||
|
||||
it("uses the GitLab /-/tree/ infix and supports subgroups", () => {
|
||||
expect(
|
||||
buildForgeBranchTreeUrl("gitlab", {
|
||||
remoteUrl: "https://gitlab.com/group/sub/repo.git",
|
||||
branch: "main",
|
||||
}),
|
||||
).toBe("https://gitlab.com/group/sub/repo/-/tree/main");
|
||||
});
|
||||
|
||||
it("uses the Gitea-family /src/branch/ infix", () => {
|
||||
expect(
|
||||
buildForgeBranchTreeUrl("gitea", {
|
||||
remoteUrl: "https://gitea.com/acme/repo.git",
|
||||
branch: "main",
|
||||
}),
|
||||
).toBe("https://gitea.com/acme/repo/src/branch/main");
|
||||
expect(
|
||||
buildForgeBranchTreeUrl("codeberg", {
|
||||
remoteUrl: "https://codeberg.org/acme/repo.git",
|
||||
branch: "main",
|
||||
}),
|
||||
).toBe("https://codeberg.org/acme/repo/src/branch/main");
|
||||
});
|
||||
|
||||
it("returns null when the current branch is unavailable", () => {
|
||||
expect(
|
||||
buildForgeBranchTreeUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "HEAD",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a forge with no known URL grammar", () => {
|
||||
expect(
|
||||
buildForgeBranchTreeUrl("bitbucket", {
|
||||
remoteUrl: "https://bitbucket.org/acme/repo.git",
|
||||
branch: "main",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildForgeBlobUrl", () => {
|
||||
it("builds a blob URL for a file path", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "git@github.com:acme/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/blob/main/src/index.ts");
|
||||
});
|
||||
|
||||
it("appends a single-line anchor", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
lineStart: 12,
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/blob/main/src/index.ts#L12");
|
||||
});
|
||||
|
||||
it("appends a GitHub line range anchor (#L12-L20)", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
lineStart: 12,
|
||||
lineEnd: 20,
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/blob/main/src/index.ts#L12-L20");
|
||||
});
|
||||
|
||||
it("uses the GitLab /-/blob/ infix and #L12-20 range anchor", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("gitlab", {
|
||||
remoteUrl: "https://gitlab.com/group/sub/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
lineStart: 12,
|
||||
lineEnd: 20,
|
||||
}),
|
||||
).toBe("https://gitlab.com/group/sub/repo/-/blob/main/src/index.ts#L12-20");
|
||||
});
|
||||
|
||||
it("uses the Gitea-family /src/branch/ blob path with a #L12-L20 anchor", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("forgejo", {
|
||||
remoteUrl: "https://codeberg.org/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
lineStart: 12,
|
||||
lineEnd: 20,
|
||||
}),
|
||||
).toBe("https://codeberg.org/acme/repo/src/branch/main/src/index.ts#L12-L20");
|
||||
});
|
||||
|
||||
it("derives the web host from a self-hosted remote (GitHub Enterprise)", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "git@github.acme.internal:team/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
}),
|
||||
).toBe("https://github.acme.internal/team/repo/blob/main/src/index.ts");
|
||||
});
|
||||
|
||||
it("canonicalizes the github.com SSH-alias host to the web host", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "ssh://git@ssh.github.com/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/blob/main/src/index.ts");
|
||||
});
|
||||
|
||||
it("strips leading slashes and encodes path segments", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "/src/a b/c#d.ts",
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/blob/main/src/a%20b/c%23d.ts");
|
||||
});
|
||||
|
||||
it("normalizes harmless dot segments in the blob path", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "./src/../index.ts",
|
||||
}),
|
||||
).toBe("https://github.com/acme/repo/blob/main/index.ts");
|
||||
});
|
||||
|
||||
it("returns null for blob paths that escape above the repo root", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "../outside.ts",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null when the path is missing", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("github", {
|
||||
remoteUrl: "https://github.com/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a forge with no known URL grammar", () => {
|
||||
expect(
|
||||
buildForgeBlobUrl("bitbucket", {
|
||||
remoteUrl: "https://bitbucket.org/acme/repo.git",
|
||||
branch: "main",
|
||||
path: "src/index.ts",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasForgeWebUrls", () => {
|
||||
it("is true for forges with a known URL grammar", () => {
|
||||
for (const forge of ["github", "gitlab", "gitea", "forgejo", "codeberg"]) {
|
||||
expect(hasForgeWebUrls(forge)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("is false for an unknown forge", () => {
|
||||
expect(hasForgeWebUrls("bitbucket")).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user