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
@@ -17,6 +17,7 @@ import {
|
||||
__resetPullRequestStatusCacheForTests,
|
||||
__setPullRequestStatusCacheTtlForTests,
|
||||
commitAll,
|
||||
createPullRequest,
|
||||
getCachedCheckoutShortstat,
|
||||
getCheckoutSnapshotFacts,
|
||||
getCurrentBranch,
|
||||
@@ -42,12 +43,10 @@ import {
|
||||
warmCheckoutShortstatInBackground,
|
||||
} from "./checkout-git.js";
|
||||
import { startGitCommandMetrics, stopGitCommandMetrics } from "./run-git-command.js";
|
||||
import {
|
||||
GitHubCommandError,
|
||||
GitHubCliMissingError,
|
||||
type GitHubCurrentPullRequestStatus,
|
||||
type GitHubService,
|
||||
} from "../services/github-service.js";
|
||||
import { createForgeResolver } from "../services/forge-resolver.js";
|
||||
import { GitHubCommandError, GitHubCliMissingError } from "../services/github-service.js";
|
||||
import type { CurrentPullRequestStatus, ForgeService } from "../services/forge-service.js";
|
||||
import { TeaAuthenticationError, TeaCliMissingError } from "../services/gitea-service.js";
|
||||
import {
|
||||
createWorktree as createWorktreePrimitive,
|
||||
type CreateWorktreeOptions,
|
||||
@@ -102,9 +101,9 @@ function sleep(ms: number): Promise<void> {
|
||||
}
|
||||
|
||||
function createGitHubServiceForStatus(
|
||||
status: GitHubCurrentPullRequestStatus | null,
|
||||
status: CurrentPullRequestStatus | null,
|
||||
options?: { onStatus?: () => void },
|
||||
): GitHubService {
|
||||
): ForgeService {
|
||||
return {
|
||||
listPullRequests: async () => [],
|
||||
listIssues: async () => [],
|
||||
@@ -120,6 +119,15 @@ function createGitHubServiceForStatus(
|
||||
labels: [],
|
||||
}),
|
||||
getPullRequestHeadRef: async () => "feature",
|
||||
getPullRequestCheckoutTarget: async ({ number }) => ({
|
||||
number,
|
||||
baseRefName: "main",
|
||||
headRefName: "feature",
|
||||
headOwnerLogin: null,
|
||||
headRepositorySshUrl: null,
|
||||
headRepositoryUrl: null,
|
||||
isCrossRepository: false,
|
||||
}),
|
||||
getCurrentPullRequestStatus: async () => {
|
||||
options?.onStatus?.();
|
||||
return status;
|
||||
@@ -134,7 +142,7 @@ function createGitHubServiceForStatus(
|
||||
};
|
||||
}
|
||||
|
||||
function createPullRequestStatus(overrides?: Partial<GitHubCurrentPullRequestStatus>) {
|
||||
function createPullRequestStatus(overrides?: Partial<CurrentPullRequestStatus>) {
|
||||
return {
|
||||
url: "https://github.com/getpaseo/paseo/pull/123",
|
||||
title: "Ship feature",
|
||||
@@ -156,12 +164,12 @@ interface RequestedPullRequestTarget {
|
||||
|
||||
interface RecordingPullRequestTargetsOptions {
|
||||
requestedTargets: RequestedPullRequestTarget[];
|
||||
statusOverrides?: Partial<GitHubCurrentPullRequestStatus>;
|
||||
statusOverrides?: Partial<CurrentPullRequestStatus>;
|
||||
}
|
||||
|
||||
function createGitHubServiceRecordingPullRequestTargets(
|
||||
options: RecordingPullRequestTargetsOptions,
|
||||
): GitHubService {
|
||||
): ForgeService {
|
||||
const github = createGitHubServiceForStatus(null);
|
||||
github.getCurrentPullRequestStatus = async (request) => {
|
||||
options.requestedTargets.push({
|
||||
@@ -245,6 +253,60 @@ describe("checkout git utilities", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("creates a pull request via the given adapter without resolving a repo slug in the shell", async () => {
|
||||
setupRemoteTrackingMain(repoDir, tempDir);
|
||||
let adapterReached = false;
|
||||
const adapter = createGitHubServiceForStatus(null);
|
||||
adapter.createPullRequest = async () => {
|
||||
adapterReached = true;
|
||||
return { url: "https://gitlab.com/group/proj/-/merge_requests/7", number: 7 };
|
||||
};
|
||||
|
||||
const result = await createPullRequest(
|
||||
repoDir,
|
||||
{ title: "Add thing", body: "desc", base: "main" },
|
||||
adapter,
|
||||
);
|
||||
|
||||
expect(adapterReached).toBe(true);
|
||||
expect(result).toEqual({
|
||||
url: "https://gitlab.com/group/proj/-/merge_requests/7",
|
||||
number: 7,
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves a gitlab remote through the resolver and creates via the gitlab adapter", async () => {
|
||||
// origin is a real local bare repo so the push succeeds; the resolver reads a
|
||||
// gitlab remote URL (injected) so it selects the gitlab adapter from the host.
|
||||
setupRemoteTrackingMain(repoDir, tempDir);
|
||||
let adapterReached = false;
|
||||
const adapter = createGitHubServiceForStatus(null);
|
||||
adapter.createPullRequest = async () => {
|
||||
adapterReached = true;
|
||||
return { url: "https://gitlab.com/group/proj/-/merge_requests/9", number: 9 };
|
||||
};
|
||||
|
||||
const resolver = createForgeResolver({
|
||||
resolveRemoteUrl: async () => "git@gitlab.com:group/proj.git",
|
||||
createService: (forge) => (forge === "gitlab" ? adapter : null),
|
||||
});
|
||||
const resolution = await resolver.resolve(repoDir);
|
||||
expect(resolution).toMatchObject({ forge: "gitlab", host: "gitlab.com" });
|
||||
expect(resolution?.service).toBe(adapter);
|
||||
|
||||
const result = await createPullRequest(
|
||||
repoDir,
|
||||
{ title: "Add thing", body: "desc", base: "main" },
|
||||
resolution?.service,
|
||||
);
|
||||
|
||||
expect(adapterReached).toBe(true);
|
||||
expect(result).toEqual({
|
||||
url: "https://gitlab.com/group/proj/-/merge_requests/9",
|
||||
number: 9,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns null for getCurrentBranch in a repo with no commits", async () => {
|
||||
const emptyRepo = join(tempDir, "empty-repo");
|
||||
mkdirSync(emptyRepo, { recursive: true });
|
||||
@@ -2199,6 +2261,7 @@ const x = 1;
|
||||
|
||||
expect(status).toEqual({
|
||||
githubFeaturesEnabled: true,
|
||||
authState: "authenticated",
|
||||
status: {
|
||||
number: 123,
|
||||
url: "https://github.com/getpaseo/paseo/pull/123",
|
||||
@@ -2593,6 +2656,7 @@ const x = 1;
|
||||
expect(fresh.status?.url).toContain("/pull/123");
|
||||
expect(cleared).toEqual({
|
||||
githubFeaturesEnabled: true,
|
||||
authState: "authenticated",
|
||||
status: null,
|
||||
});
|
||||
expect(callCount).toBe(2);
|
||||
@@ -2601,6 +2665,42 @@ const x = 1;
|
||||
}
|
||||
});
|
||||
|
||||
it("maps missing Gitea CLI PR status lookups to cli_missing auth state", async () => {
|
||||
execFileSync("git", ["checkout", "-b", "feature"], { cwd: repoDir });
|
||||
execFileSync("git", ["remote", "add", "origin", "https://gitea.example.com/acme/repo.git"], {
|
||||
cwd: repoDir,
|
||||
});
|
||||
|
||||
const service = createGitHubServiceForStatus(null);
|
||||
service.getCurrentPullRequestStatus = async () => {
|
||||
throw new TeaCliMissingError();
|
||||
};
|
||||
|
||||
await expect(getPullRequestStatus(repoDir, service)).resolves.toEqual({
|
||||
status: null,
|
||||
authState: "cli_missing",
|
||||
githubFeaturesEnabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("maps Gitea authentication PR status failures to unauthenticated auth state", async () => {
|
||||
execFileSync("git", ["checkout", "-b", "feature"], { cwd: repoDir });
|
||||
execFileSync("git", ["remote", "add", "origin", "https://gitea.example.com/acme/repo.git"], {
|
||||
cwd: repoDir,
|
||||
});
|
||||
|
||||
const service = createGitHubServiceForStatus(null);
|
||||
service.getCurrentPullRequestStatus = async () => {
|
||||
throw new TeaAuthenticationError({ stderr: "401 unauthorized" });
|
||||
};
|
||||
|
||||
await expect(getPullRequestStatus(repoDir, service)).resolves.toEqual({
|
||||
status: null,
|
||||
authState: "unauthenticated",
|
||||
githubFeaturesEnabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("dedupes concurrent PR status lookups for the same cwd", async () => {
|
||||
execFileSync("git", ["checkout", "-b", "feature"], { cwd: repoDir });
|
||||
execFileSync("git", ["remote", "add", "origin", "https://github.com/getpaseo/paseo.git"], {
|
||||
|
||||
Reference in New Issue
Block a user