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
@@ -1,9 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { GitHubSearchItem } from "@getpaseo/protocol/messages";
|
||||
import type { ForgeSearchItem } from "@getpaseo/protocol/messages";
|
||||
import { pickerItemToCheckoutRequest, type PickerItem } from "./new-workspace-picker-item";
|
||||
|
||||
const prItem: GitHubSearchItem = {
|
||||
kind: "pr",
|
||||
const prItem: ForgeSearchItem = {
|
||||
kind: "change_request",
|
||||
number: 42,
|
||||
title: "Add picker",
|
||||
url: "https://example.com/pull/42",
|
||||
@@ -35,6 +35,7 @@ describe("pickerItemToCheckoutRequest", () => {
|
||||
expect(pickerItemToCheckoutRequest(item)).toEqual({
|
||||
action: "checkout",
|
||||
refName: "feature/picker",
|
||||
checkoutSource: { kind: "change_request", forge: "github", number: 42 },
|
||||
githubPrNumber: 42,
|
||||
});
|
||||
});
|
||||
@@ -53,7 +54,31 @@ describe("pickerItemToCheckoutRequest", () => {
|
||||
expect(pickerItemToCheckoutRequest(item)).toEqual({
|
||||
action: "checkout",
|
||||
refName: "orphan",
|
||||
checkoutSource: { kind: "change_request", forge: "github", number: 7 },
|
||||
githubPrNumber: 7,
|
||||
});
|
||||
});
|
||||
|
||||
it("does not send the legacy githubPrNumber for non-GitHub change requests", () => {
|
||||
const item: PickerItem = {
|
||||
kind: "github-pr",
|
||||
item: {
|
||||
...prItem,
|
||||
forge: "gitlab",
|
||||
number: 21,
|
||||
projectPath: "acme/repo",
|
||||
url: "https://gitlab.example.com/acme/repo/-/merge_requests/21",
|
||||
},
|
||||
};
|
||||
expect(pickerItemToCheckoutRequest(item)).toEqual({
|
||||
action: "checkout",
|
||||
refName: "feature/picker",
|
||||
checkoutSource: {
|
||||
kind: "change_request",
|
||||
forge: "gitlab",
|
||||
number: 21,
|
||||
projectPath: "acme/repo",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import type { CreatePaseoWorktreeInput } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { GitHubSearchItem } from "@getpaseo/protocol/messages";
|
||||
import type { ForgeSearchItem } from "@getpaseo/protocol/messages";
|
||||
|
||||
export type PickerItem =
|
||||
| { kind: "branch"; name: string }
|
||||
| {
|
||||
kind: "github-pr";
|
||||
item: GitHubSearchItem;
|
||||
item: ForgeSearchItem;
|
||||
};
|
||||
|
||||
export type PickerCheckoutRequest = Pick<
|
||||
CreatePaseoWorktreeInput,
|
||||
"action" | "refName" | "githubPrNumber"
|
||||
"action" | "refName" | "checkoutSource" | "githubPrNumber"
|
||||
>;
|
||||
|
||||
export function pickerItemToCheckoutRequest(
|
||||
@@ -22,10 +22,23 @@ export function pickerItemToCheckoutRequest(
|
||||
return { action: "branch-off", refName: item.name };
|
||||
case "github-pr": {
|
||||
const headRefName = item.item.headRefName?.trim();
|
||||
const forge = item.item.forge ?? "github";
|
||||
return {
|
||||
action: "checkout",
|
||||
...(headRefName ? { refName: headRefName } : {}),
|
||||
githubPrNumber: item.item.number,
|
||||
checkoutSource: {
|
||||
kind: "change_request",
|
||||
forge,
|
||||
number: item.item.number,
|
||||
...(item.item.projectPath ? { projectPath: item.item.projectPath } : {}),
|
||||
},
|
||||
...(forge === "github"
|
||||
? {
|
||||
// COMPAT(githubPrNumber): added in v0.1.106, remove after 2026-12-28 once
|
||||
// daemon floor parses checkoutSource.
|
||||
githubPrNumber: item.item.number,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { UserComposerAttachment } from "@/attachments/types";
|
||||
import type { GitHubSearchItem } from "@getpaseo/protocol/messages";
|
||||
import {
|
||||
clearPickerPrAttachmentForTargetChange,
|
||||
findCheckoutHintPrAttachment,
|
||||
syncPickerPrAttachment,
|
||||
} from "./new-workspace-picker-state";
|
||||
import type { ForgeSearchItem } from "@getpaseo/protocol/messages";
|
||||
|
||||
function makePrItem(number: number, title: string, headRefName = "feature/x"): GitHubSearchItem {
|
||||
function makePrItem(number: number, title: string, headRefName = "feature/x"): ForgeSearchItem {
|
||||
return {
|
||||
kind: "pr",
|
||||
kind: "change_request",
|
||||
number,
|
||||
title,
|
||||
url: `https://example.com/pull/${number}`,
|
||||
@@ -22,7 +22,7 @@ function makePrItem(number: number, title: string, headRefName = "feature/x"): G
|
||||
}
|
||||
|
||||
function prAttachment(
|
||||
item: GitHubSearchItem,
|
||||
item: ForgeSearchItem,
|
||||
owner?: "new-workspace-picker",
|
||||
): Extract<UserComposerAttachment, { kind: "github_pr" }> {
|
||||
return { kind: "github_pr", item, ...(owner ? { owner } : {}) };
|
||||
|
||||
@@ -21,7 +21,10 @@ import {
|
||||
import { Composer } from "@/composer";
|
||||
import { FileDropZone } from "@/components/file-drop/file-drop-zone";
|
||||
import { DraftAgentModeControl } from "@/composer/agent-controls/mode-control";
|
||||
import { splitComposerAttachmentsForSubmit } from "@/composer/attachments/submit";
|
||||
import {
|
||||
resolveComposerAttachmentSubmitFormat,
|
||||
splitComposerAttachmentsForSubmit,
|
||||
} from "@/composer/attachments/submit";
|
||||
import { HostStatusDot } from "@/components/host-status-dot";
|
||||
import { HostPicker } from "@/components/hosts/host-picker";
|
||||
import { ProjectIconView } from "@/components/project-icon-view";
|
||||
@@ -36,7 +39,7 @@ import { ScreenHeader } from "@/components/headers/screen-header";
|
||||
import { HEADER_INNER_HEIGHT, MAX_CONTENT_WIDTH, useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { useToast } from "@/contexts/toast-context";
|
||||
import { useAgentInputDraft } from "@/composer/draft/input-draft";
|
||||
import { useGithubSearchQuery } from "@/git/use-github-search-query";
|
||||
import { useForgeSearchQuery } from "@/git/use-forge-search-query";
|
||||
import {
|
||||
useHostRuntimeClient,
|
||||
useHostRuntimeConnectionStatuses,
|
||||
@@ -63,6 +66,7 @@ import {
|
||||
import { useKeyboardShiftStyle } from "@/hooks/use-keyboard-shift-style";
|
||||
import { useFormPreferences } from "@/hooks/use-form-preferences";
|
||||
import { useShortcutKeys } from "@/hooks/use-shortcut-keys";
|
||||
import { getForgePresentation } from "@/git/forge";
|
||||
import type { CreateAgentInitialValues } from "@/hooks/use-agent-form-state";
|
||||
import { generateMessageId } from "@/types/stream";
|
||||
import { toErrorMessage } from "@/utils/error-messages";
|
||||
@@ -79,7 +83,7 @@ import { ICON_SIZE, type Theme } from "@/styles/theme";
|
||||
import type { ComposerAttachment, UserComposerAttachment } from "@/attachments/types";
|
||||
import { useDraftWorkspaceAttachmentScopeKey } from "@/attachments/workspace-attachments-store";
|
||||
import type { MessagePayload } from "@/composer/types";
|
||||
import type { AgentAttachment, GitHubSearchItem } from "@getpaseo/protocol/messages";
|
||||
import type { AgentAttachment, ForgeSearchItem } from "@getpaseo/protocol/messages";
|
||||
import type { CreatePaseoWorktreeInput } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { AgentProvider } from "@getpaseo/protocol/agent-types";
|
||||
import type { WorkspaceDraftTabSetup, WorkspaceTabTarget } from "@/stores/workspace-tabs-store";
|
||||
@@ -637,8 +641,17 @@ function AddProjectPickerAction({ onPress }: { onPress: () => void }) {
|
||||
);
|
||||
}
|
||||
|
||||
function formatPrLabel(item: { number: number; title: string }): string {
|
||||
return `#${item.number} ${item.title}`;
|
||||
function formatPrLabel(item: Pick<ForgeSearchItem, "forge" | "number" | "title">): string {
|
||||
const presentation = getForgePresentation(item.forge ?? "github");
|
||||
return `${presentation.numberPrefix}${item.number} ${item.title}`;
|
||||
}
|
||||
|
||||
function getCheckoutHintPresentation(item: ForgeSearchItem) {
|
||||
const presentation = getForgePresentation(item.forge ?? "github");
|
||||
return {
|
||||
noun: presentation.changeRequestAbbrev,
|
||||
numberPrefix: presentation.numberPrefix,
|
||||
};
|
||||
}
|
||||
|
||||
function pickerItemLabel(item: PickerItem): string {
|
||||
@@ -655,7 +668,7 @@ function newWorkspaceHostOptionTestID(serverId: string): string {
|
||||
|
||||
function computePickerOptionData(
|
||||
branchDetails: ReadonlyArray<{ name: string; committerDate: number }>,
|
||||
prItems: ReadonlyArray<GitHubSearchItem>,
|
||||
prItems: ReadonlyArray<ForgeSearchItem>,
|
||||
): PickerOptionData {
|
||||
const idMap = new Map<string, PickerItem>();
|
||||
|
||||
@@ -817,6 +830,7 @@ interface SubmitDraftInput {
|
||||
attachments: ComposerAttachment[];
|
||||
provider: AgentProvider;
|
||||
composerState: NewWorkspaceComposerState;
|
||||
supportsForgeSearch: boolean;
|
||||
}
|
||||
|
||||
type NewWorkspaceComposerState = NonNullable<
|
||||
@@ -922,6 +936,7 @@ interface CreateChatAgentInput {
|
||||
serverId: string;
|
||||
draftKey: string;
|
||||
draftId?: string;
|
||||
supportsForgeSearch: boolean;
|
||||
labels: {
|
||||
composerStateRequired: string;
|
||||
selectModel: string;
|
||||
@@ -992,7 +1007,12 @@ async function runCreateChatAgent(input: CreateChatAgentInput): Promise<void> {
|
||||
if (!provider) {
|
||||
throw new Error(input.labels.selectModel);
|
||||
}
|
||||
const { attachments: reviewAttachments } = splitComposerAttachmentsForSubmit(attachments);
|
||||
const attachmentSubmitFormat = resolveComposerAttachmentSubmitFormat({
|
||||
supportsForgeAttachments: input.supportsForgeSearch,
|
||||
});
|
||||
const { attachments: reviewAttachments } = splitComposerAttachmentsForSubmit(attachments, {
|
||||
format: attachmentSubmitFormat,
|
||||
});
|
||||
const workspaceNamingAttachments = getWorkspaceNamingAttachments(reviewAttachments);
|
||||
const ensuredWorkspace = await ensureWorkspace({
|
||||
cwd,
|
||||
@@ -1017,6 +1037,7 @@ async function runCreateChatAgent(input: CreateChatAgentInput): Promise<void> {
|
||||
attachments,
|
||||
provider,
|
||||
composerState,
|
||||
supportsForgeSearch: input.supportsForgeSearch,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1138,7 +1159,11 @@ function submitWorkspaceDraft(input: SubmitDraftInput): void {
|
||||
const draftId = draftIdInput?.trim() || generateDraftId();
|
||||
const clientMessageId = generateMessageId();
|
||||
const timestamp = Date.now();
|
||||
const wirePayload = splitComposerAttachmentsForSubmit(attachments);
|
||||
const wirePayload = splitComposerAttachmentsForSubmit(attachments, {
|
||||
format: resolveComposerAttachmentSubmitFormat({
|
||||
supportsForgeAttachments: input.supportsForgeSearch,
|
||||
}),
|
||||
});
|
||||
const submission = resolveWorkspaceDraftSubmissionConfig({
|
||||
draftId,
|
||||
workspaceDirectory,
|
||||
@@ -1616,6 +1641,7 @@ export function NewWorkspaceScreen({
|
||||
});
|
||||
// COMPAT(workspaceMultiplicity): added in v0.1.97, drop the gate when floor >= v0.1.97
|
||||
const supportsWorkspaceMultiplicity = useHostFeature(selectedServerId, "workspaceMultiplicity");
|
||||
const supportsForgeSearch = useHostFeature(selectedServerId, "forgeSearch");
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
const [createdWorkspace, setCreatedWorkspace] = useState<ReturnType<
|
||||
typeof normalizeWorkspaceDescriptor
|
||||
@@ -1753,12 +1779,13 @@ export function NewWorkspaceScreen({
|
||||
staleTime: 15_000,
|
||||
});
|
||||
|
||||
const githubPrSearchQuery = useGithubSearchQuery({
|
||||
const githubPrSearchQuery = useForgeSearchQuery({
|
||||
client,
|
||||
serverId: selectedServerId,
|
||||
cwd: selectedSourceDirectory ?? "",
|
||||
query: debouncedPickerSearchQuery,
|
||||
kinds: ["github-pr"],
|
||||
kinds: ["change_request"],
|
||||
supportsForgeSearch,
|
||||
enabled: pickerQueryEnabled,
|
||||
});
|
||||
|
||||
@@ -1766,11 +1793,12 @@ export function NewWorkspaceScreen({
|
||||
() => normalizeBranchDetails(branchSuggestionsQuery.data),
|
||||
[branchSuggestionsQuery.data],
|
||||
);
|
||||
const githubFeaturesEnabled = githubPrSearchQuery.data?.githubFeaturesEnabled !== false;
|
||||
const prItems: GitHubSearchItem[] = useMemo(() => {
|
||||
if (!githubFeaturesEnabled) return [];
|
||||
const forgeSearchAuthenticated =
|
||||
!githubPrSearchQuery.data || githubPrSearchQuery.data.authState === "authenticated";
|
||||
const prItems: ForgeSearchItem[] = useMemo(() => {
|
||||
if (!forgeSearchAuthenticated) return [];
|
||||
return githubPrSearchQuery.data?.items ?? [];
|
||||
}, [githubFeaturesEnabled, githubPrSearchQuery.data?.items]);
|
||||
}, [forgeSearchAuthenticated, githubPrSearchQuery.data?.items]);
|
||||
|
||||
const { options, itemById }: PickerOptionData = useMemo(
|
||||
() => computePickerOptionData(branchDetails, prItems),
|
||||
@@ -2059,6 +2087,7 @@ export function NewWorkspaceScreen({
|
||||
serverId: selectedServerId,
|
||||
draftKey,
|
||||
draftId,
|
||||
supportsForgeSearch,
|
||||
labels: {
|
||||
composerStateRequired: t("newWorkspace.errors.composerStateRequired"),
|
||||
selectModel: t("newWorkspace.errors.selectModel"),
|
||||
@@ -2071,7 +2100,17 @@ export function NewWorkspaceScreen({
|
||||
toast.error(message);
|
||||
}
|
||||
},
|
||||
[composerState, draftId, draftKey, ensureWorkspace, forkDraftSetup, selectedServerId, t, toast],
|
||||
[
|
||||
composerState,
|
||||
draftId,
|
||||
draftKey,
|
||||
ensureWorkspace,
|
||||
forkDraftSetup,
|
||||
selectedServerId,
|
||||
supportsForgeSearch,
|
||||
t,
|
||||
toast,
|
||||
],
|
||||
);
|
||||
|
||||
const renderPickerOption = useCallback(
|
||||
@@ -2204,12 +2243,15 @@ export function NewWorkspaceScreen({
|
||||
<CheckoutHintBadge
|
||||
label={t("newWorkspace.refPicker.checkoutHint", {
|
||||
number: checkoutHintPrAttachment.item.number,
|
||||
...getCheckoutHintPresentation(checkoutHintPrAttachment.item),
|
||||
})}
|
||||
acceptLabel={t("newWorkspace.refPicker.checkoutPr", {
|
||||
number: checkoutHintPrAttachment.item.number,
|
||||
...getCheckoutHintPresentation(checkoutHintPrAttachment.item),
|
||||
})}
|
||||
dismissLabel={t("newWorkspace.refPicker.dismissCheckoutHint", {
|
||||
number: checkoutHintPrAttachment.item.number,
|
||||
...getCheckoutHintPresentation(checkoutHintPrAttachment.item),
|
||||
})}
|
||||
onAccept={acceptCheckoutHint}
|
||||
onDismiss={dismissCheckoutHint}
|
||||
|
||||
@@ -11,7 +11,6 @@ import { useMutation } from "@tanstack/react-query";
|
||||
import { Check, ChevronDown } from "lucide-react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { EditorTargetIcon } from "@/components/icons/editor-target-icon";
|
||||
import { GitHubIcon } from "@/components/icons/github-icon";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -20,6 +19,7 @@ import {
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { useToast } from "@/contexts/toast-context";
|
||||
import { useCheckoutStatusQuery } from "@/git/use-status-query";
|
||||
import { useCheckoutPrStatusQuery } from "@/git/use-pr-status-query";
|
||||
import { useIsLocalDaemon } from "@/hooks/use-is-local-daemon";
|
||||
import { useHostRuntimeIsConnected } from "@/runtime/host-runtime";
|
||||
import { resolvePreferredEditorId, usePreferredEditor } from "@/hooks/use-preferred-editor";
|
||||
@@ -30,6 +30,8 @@ import { openDesktopTarget, useDesktopOpenTargets } from "@/workspace/desktop-op
|
||||
import { resolveWorkspaceFilePaths, type WorkspaceFileLocation } from "@/workspace/file-open";
|
||||
import { planWorkspaceOpenTargets } from "@/workspace/open-target-planner";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import { ForgeBrandIcon } from "@/git/forge-icon";
|
||||
import { getForgePresentation } from "@/git/forge";
|
||||
|
||||
interface WorkspaceOpenInEditorButtonProps {
|
||||
serverId: string;
|
||||
@@ -47,13 +49,16 @@ interface OpenTarget {
|
||||
|
||||
const ThemedActivityIndicator = withUnistyles(ActivityIndicator);
|
||||
const ThemedEditorTargetIcon = withUnistyles(EditorTargetIcon);
|
||||
const ThemedGitHubIcon = withUnistyles(GitHubIcon);
|
||||
const ThemedChevronDown = withUnistyles(ChevronDown);
|
||||
const ThemedCheckIcon = withUnistyles(Check);
|
||||
|
||||
const foregroundColorMapping = (theme: Theme) => ({ color: theme.colors.foreground });
|
||||
const mutedColorMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
|
||||
|
||||
function renderForgeOpenTargetIcon(icon: string): ReactElement {
|
||||
return <ForgeBrandIcon iconKind={icon} size={16} uniProps={mutedColorMapping} />;
|
||||
}
|
||||
|
||||
interface OpenTargetMenuItemProps {
|
||||
target: OpenTarget;
|
||||
isPreferred: boolean;
|
||||
@@ -111,6 +116,10 @@ export function WorkspaceOpenInEditorButton({
|
||||
serverId,
|
||||
cwd: shouldQueryCheckout ? cwd : "",
|
||||
});
|
||||
const { resolvedForge } = useCheckoutPrStatusQuery({
|
||||
serverId,
|
||||
cwd: shouldQueryCheckout ? cwd : "",
|
||||
});
|
||||
|
||||
const targets = useMemo<OpenTarget[]>(
|
||||
() =>
|
||||
@@ -122,12 +131,14 @@ export function WorkspaceOpenInEditorButton({
|
||||
canUseDesktopBridge: isDesktopOpenAvailable,
|
||||
isLocalExecution: isLocalDaemon,
|
||||
checkoutStatus,
|
||||
forge: resolvedForge,
|
||||
}).map((target) => {
|
||||
if (target.source === "github") {
|
||||
if (target.source === "forge") {
|
||||
const presentation = getForgePresentation(target.forge);
|
||||
return {
|
||||
id: target.id,
|
||||
label: target.label,
|
||||
icon: <ThemedGitHubIcon size={16} uniProps={mutedColorMapping} />,
|
||||
icon: renderForgeOpenTargetIcon(presentation.icon),
|
||||
onOpen: () => openExternalUrl(target.url),
|
||||
};
|
||||
}
|
||||
@@ -145,6 +156,7 @@ export function WorkspaceOpenInEditorButton({
|
||||
checkoutStatus,
|
||||
cwd,
|
||||
desktopOpenTargets,
|
||||
resolvedForge,
|
||||
isDesktopOpenAvailable,
|
||||
isLocalDaemon,
|
||||
resolvedFile,
|
||||
|
||||
Reference in New Issue
Block a user