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
@@ -2,11 +2,9 @@ import type { ReactElement } from "react";
|
||||
|
||||
import type { ActionStatus } from "@/components/ui/dropdown-menu";
|
||||
import { i18n } from "@/i18n/i18next";
|
||||
import type {
|
||||
CheckoutPrMergeMethod,
|
||||
CheckoutPrStatusResponse,
|
||||
PullRequestMergeable,
|
||||
} from "@getpaseo/protocol/messages";
|
||||
import type { CheckoutPrMergeMethod, PullRequestMergeable } from "@getpaseo/protocol/messages";
|
||||
|
||||
import type { MergeCapability } from "./merge-capability";
|
||||
|
||||
export type GitActionId =
|
||||
| "commit"
|
||||
@@ -55,6 +53,10 @@ interface GitActionRuntimeState {
|
||||
export interface BuildGitActionsInput {
|
||||
isGit: boolean;
|
||||
githubFeaturesEnabled: boolean;
|
||||
/** Forge brand label (e.g. "GitHub", "GitLab") for forge-neutral unavailable copy. */
|
||||
forgeBrandLabel: string;
|
||||
/** Short change-request noun label (e.g. "PR", "MR") for forge-neutral unavailable copy. */
|
||||
forgeChangeRequestNoun: string;
|
||||
githubAutoMergeActionsEnabled: boolean;
|
||||
hasPullRequest: boolean;
|
||||
pullRequestUrl: string | null;
|
||||
@@ -62,7 +64,7 @@ export interface BuildGitActionsInput {
|
||||
pullRequestIsDraft: boolean;
|
||||
pullRequestIsMerged: boolean;
|
||||
pullRequestMergeable: PullRequestMergeable;
|
||||
pullRequestGithub: PullRequestGithubStatus | null;
|
||||
mergeCapability: MergeCapability | null;
|
||||
hasRemote: boolean;
|
||||
isPaseoOwnedWorktree: boolean;
|
||||
isOnBaseBranch: boolean;
|
||||
@@ -98,7 +100,6 @@ type PullRequestAutoMergeEnableActionId = Extract<
|
||||
"enable-pr-auto-merge-squash" | "enable-pr-auto-merge-merge" | "enable-pr-auto-merge-rebase"
|
||||
>;
|
||||
type PullRequestActionRole = "status" | "direct" | "auto";
|
||||
type PullRequestGithubStatus = NonNullable<CheckoutPrStatusResponse["payload"]["status"]>["github"];
|
||||
|
||||
interface PullRequestActionModel {
|
||||
readonly id: PullRequestActionId;
|
||||
@@ -180,7 +181,6 @@ const PULL_REQUEST_ACTION_MODELS: readonly PullRequestActionModel[] = [
|
||||
];
|
||||
|
||||
const REMOTE_ACTION_IDS: GitActionId[] = ["pull", "push", "pull-and-push"];
|
||||
const GITHUB_DIRECT_MERGE_STATE_ALLOWLIST = new Set(["CLEAN", "HAS_HOOKS"]);
|
||||
|
||||
export function narrowPullRequestState(state: string | null | undefined): "open" | "closed" | null {
|
||||
if (state === "open") return "open";
|
||||
@@ -403,7 +403,10 @@ function buildPrAction(input: BuildGitActionsInput): GitAction {
|
||||
unavailableMessage:
|
||||
input.runtime.pr.disabled || input.githubFeaturesEnabled
|
||||
? undefined
|
||||
: i18n.t("workspace.git.actions.unavailable.viewPrNoGithub"),
|
||||
: i18n.t("workspace.git.actions.unavailable.viewPrNoForge", {
|
||||
brand: input.forgeBrandLabel,
|
||||
noun: input.forgeChangeRequestNoun,
|
||||
}),
|
||||
icon: input.runtime.pr.icon,
|
||||
startsGroup: false,
|
||||
handler: input.runtime.pr.handler,
|
||||
@@ -467,7 +470,7 @@ function buildEnablePullRequestAutoMergeAction(
|
||||
function buildDisablePullRequestAutoMergeAction(input: BuildGitActionsInput): GitAction {
|
||||
const runtime = input.runtime["disable-pr-auto-merge"];
|
||||
const unavailableMessage =
|
||||
input.pullRequestGithub?.viewerCanDisableAutoMerge === true
|
||||
input.mergeCapability?.canDisableAutoMerge === true
|
||||
? undefined
|
||||
: i18n.t("workspace.git.actions.unavailable.autoMergeCannotDisable");
|
||||
return {
|
||||
@@ -475,7 +478,7 @@ function buildDisablePullRequestAutoMergeAction(input: BuildGitActionsInput): Gi
|
||||
label: i18n.t("workspace.git.actions.autoMerge.enabled"),
|
||||
pendingLabel: i18n.t("workspace.git.actions.autoMerge.disabling"),
|
||||
successLabel: i18n.t("workspace.git.actions.autoMerge.disabled"),
|
||||
disabled: runtime.disabled || input.pullRequestGithub?.viewerCanDisableAutoMerge !== true,
|
||||
disabled: runtime.disabled || input.mergeCapability?.canDisableAutoMerge !== true,
|
||||
status: runtime.status,
|
||||
unavailableMessage: runtime.disabled ? undefined : unavailableMessage,
|
||||
icon: runtime.icon,
|
||||
@@ -543,7 +546,7 @@ function canUsePullRequestActionAsShipDefault(input: BuildGitActionsInput): bool
|
||||
}
|
||||
|
||||
function canMergePr(input: BuildGitActionsInput): boolean {
|
||||
const github = input.pullRequestGithub;
|
||||
const capability = input.mergeCapability;
|
||||
const canMergeFromPullRequestStatus =
|
||||
input.githubFeaturesEnabled &&
|
||||
input.hasPullRequest &&
|
||||
@@ -558,7 +561,7 @@ function canMergePr(input: BuildGitActionsInput): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hasPullRequestGithubFacts(github)) {
|
||||
if (capability === null) {
|
||||
return (
|
||||
input.pullRequestMergeable === "MERGEABLE" &&
|
||||
input.behindOfOrigin === 0 &&
|
||||
@@ -568,16 +571,15 @@ function canMergePr(input: BuildGitActionsInput): boolean {
|
||||
}
|
||||
|
||||
return (
|
||||
GITHUB_DIRECT_MERGE_STATE_ALLOWLIST.has(github.mergeStateStatus ?? "") &&
|
||||
github.autoMergeRequest === null &&
|
||||
!github.isMergeQueueEnabled &&
|
||||
!github.isInMergeQueue &&
|
||||
capability.directMergeReady &&
|
||||
!capability.autoMergeEnabled &&
|
||||
!capability.mergeBlockedByQueue &&
|
||||
getAllowedDirectPullRequestMergeActionModels(input).length > 0
|
||||
);
|
||||
}
|
||||
|
||||
function canEnablePrAutoMerge(input: BuildGitActionsInput): boolean {
|
||||
const github = input.pullRequestGithub;
|
||||
const capability = input.mergeCapability;
|
||||
return (
|
||||
input.githubFeaturesEnabled &&
|
||||
input.githubAutoMergeActionsEnabled &&
|
||||
@@ -586,13 +588,10 @@ function canEnablePrAutoMerge(input: BuildGitActionsInput): boolean {
|
||||
!input.pullRequestIsDraft &&
|
||||
!input.pullRequestIsMerged &&
|
||||
input.pullRequestMergeable !== "CONFLICTING" &&
|
||||
hasPullRequestGithubFacts(github) &&
|
||||
github.autoMergeRequest === null &&
|
||||
github.mergeStateStatus === "BLOCKED" &&
|
||||
github.repository.autoMergeAllowed &&
|
||||
github.viewerCanEnableAutoMerge &&
|
||||
!github.isMergeQueueEnabled &&
|
||||
!github.isInMergeQueue &&
|
||||
capability !== null &&
|
||||
!capability.autoMergeEnabled &&
|
||||
capability.canEnableAutoMerge &&
|
||||
!capability.mergeBlockedByQueue &&
|
||||
getAllowedAutoMergeEnableActionModels(input).length > 0
|
||||
);
|
||||
}
|
||||
@@ -602,8 +601,7 @@ function hasEnabledPrAutoMerge(input: BuildGitActionsInput): boolean {
|
||||
input.githubFeaturesEnabled &&
|
||||
input.hasPullRequest &&
|
||||
input.pullRequestUrl !== null &&
|
||||
hasPullRequestGithubFacts(input.pullRequestGithub) &&
|
||||
input.pullRequestGithub.autoMergeRequest !== null
|
||||
input.mergeCapability?.autoMergeEnabled === true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -615,7 +613,7 @@ function getPullUnavailableMessage(input: BuildGitActionsInput): string | undefi
|
||||
return i18n.t("workspace.git.actions.unavailable.pullDirty");
|
||||
}
|
||||
if (input.behindOfOrigin === null) {
|
||||
return "Pull isn't available here because this branch is not connected to a remote yet";
|
||||
return i18n.t("workspace.git.actions.unavailable.pullNoRemote");
|
||||
}
|
||||
if (input.behindOfOrigin === 0) {
|
||||
return i18n.t("workspace.git.actions.unavailable.pullUpToDate");
|
||||
@@ -644,23 +642,26 @@ function getPullAndPushUnavailableMessage(input: BuildGitActionsInput): string |
|
||||
return i18n.t("workspace.git.actions.unavailable.pullAndPushDirty");
|
||||
}
|
||||
if (input.behindOfOrigin === null) {
|
||||
return "Pull and push isn't available because there are no incoming changes to pull first";
|
||||
return i18n.t("workspace.git.actions.unavailable.pullAndPushNoIncoming");
|
||||
}
|
||||
if (input.behindOfOrigin === 0 && input.aheadOfOrigin === 0) {
|
||||
return i18n.t("workspace.git.actions.unavailable.pullAndPushInSync");
|
||||
}
|
||||
if (input.behindOfOrigin === 0) {
|
||||
return "Pull and push isn't available because there are no incoming changes to pull first";
|
||||
return i18n.t("workspace.git.actions.unavailable.pullAndPushNoIncoming");
|
||||
}
|
||||
if ((input.aheadOfOrigin ?? 0) === 0) {
|
||||
return "Pull and push isn't available because there is nothing new to send after pulling";
|
||||
return i18n.t("workspace.git.actions.unavailable.pullAndPushNothingToPush");
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getCreatePrUnavailableMessage(input: BuildGitActionsInput): string | undefined {
|
||||
if (!input.githubFeaturesEnabled) {
|
||||
return i18n.t("workspace.git.actions.unavailable.createPrNoGithub");
|
||||
return i18n.t("workspace.git.actions.unavailable.createPrNoForge", {
|
||||
brand: input.forgeBrandLabel,
|
||||
noun: input.forgeChangeRequestNoun,
|
||||
});
|
||||
}
|
||||
if (input.aheadCount === 0) {
|
||||
return i18n.t("workspace.git.actions.unavailable.createPrNoCommits");
|
||||
@@ -698,7 +699,10 @@ function getMergeFromBaseUnavailableMessage(input: BuildGitActionsInput): string
|
||||
|
||||
function getMergePrUnavailableMessage(input: BuildGitActionsInput): string | undefined {
|
||||
if (!input.githubFeaturesEnabled) {
|
||||
return i18n.t("workspace.git.actions.unavailable.mergePrNoGithub");
|
||||
return i18n.t("workspace.git.actions.unavailable.mergePrNoForge", {
|
||||
brand: input.forgeBrandLabel,
|
||||
noun: input.forgeChangeRequestNoun,
|
||||
});
|
||||
}
|
||||
if (!input.hasPullRequest) {
|
||||
return i18n.t("workspace.git.actions.unavailable.mergePrMissing");
|
||||
@@ -715,14 +719,17 @@ function getMergePrUnavailableMessage(input: BuildGitActionsInput): string | und
|
||||
if (input.pullRequestMergeable === "CONFLICTING") {
|
||||
return i18n.t("workspace.git.actions.unavailable.mergePrConflicts");
|
||||
}
|
||||
if (!hasPullRequestGithubFacts(input.pullRequestGithub)) {
|
||||
if (input.mergeCapability === null) {
|
||||
return undefined;
|
||||
}
|
||||
if (input.pullRequestGithub?.isMergeQueueEnabled || input.pullRequestGithub?.isInMergeQueue) {
|
||||
if (input.mergeCapability.mergeBlockedByQueue) {
|
||||
return i18n.t("workspace.git.actions.unavailable.mergePrQueue");
|
||||
}
|
||||
if (!GITHUB_DIRECT_MERGE_STATE_ALLOWLIST.has(input.pullRequestGithub?.mergeStateStatus ?? "")) {
|
||||
return i18n.t("workspace.git.actions.unavailable.mergePrNotReady");
|
||||
if (!input.mergeCapability.directMergeReady) {
|
||||
return i18n.t("workspace.git.actions.unavailable.mergePrNotReady", {
|
||||
brand: input.forgeBrandLabel,
|
||||
noun: input.forgeChangeRequestNoun,
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -739,11 +746,7 @@ function shouldShowPullRequestAction(
|
||||
return true;
|
||||
}
|
||||
if (id === "disable-pr-auto-merge") {
|
||||
return (
|
||||
input.githubAutoMergeActionsEnabled &&
|
||||
hasPullRequestGithubFacts(input.pullRequestGithub) &&
|
||||
input.pullRequestGithub.autoMergeRequest !== null
|
||||
);
|
||||
return input.githubAutoMergeActionsEnabled && input.mergeCapability?.autoMergeEnabled === true;
|
||||
}
|
||||
if (isDirectPullRequestMergeActionId(id)) {
|
||||
return canMergePr(input) && getAllowedDirectPullRequestMergeActionIds(input).includes(id);
|
||||
@@ -798,9 +801,7 @@ function getPreferredDirectPullRequestMergeActionModel(
|
||||
input: BuildGitActionsInput,
|
||||
): PullRequestDirectMergeActionModel | null {
|
||||
const allowed = getAllowedDirectPullRequestMergeActionModels(input);
|
||||
const preferred = normalizeGithubMergeMethod(
|
||||
input.pullRequestGithub?.repository.viewerDefaultMergeMethod ?? null,
|
||||
);
|
||||
const preferred = input.mergeCapability?.preferredMethod ?? null;
|
||||
return allowed.find((model) => model.method === preferred) ?? allowed[0] ?? null;
|
||||
}
|
||||
|
||||
@@ -808,9 +809,7 @@ function getPreferredEnablePullRequestAutoMergeActionModel(
|
||||
input: BuildGitActionsInput,
|
||||
): PullRequestAutoMergeEnableActionModel | null {
|
||||
const allowed = getAllowedAutoMergeEnableActionModels(input);
|
||||
const preferred = normalizeGithubMergeMethod(
|
||||
input.pullRequestGithub?.repository.viewerDefaultMergeMethod ?? null,
|
||||
);
|
||||
const preferred = input.mergeCapability?.preferredMethod ?? null;
|
||||
return allowed.find((model) => model.method === preferred) ?? allowed[0] ?? null;
|
||||
}
|
||||
|
||||
@@ -818,28 +817,9 @@ function isPullRequestMergeMethodAllowed(
|
||||
input: BuildGitActionsInput,
|
||||
method: CheckoutPrMergeMethod,
|
||||
): boolean {
|
||||
const repository = input.pullRequestGithub?.repository;
|
||||
if (!repository) {
|
||||
const capability = input.mergeCapability;
|
||||
if (capability === null) {
|
||||
return true;
|
||||
}
|
||||
if (method === "squash") {
|
||||
return repository.squashMergeAllowed;
|
||||
}
|
||||
if (method === "merge") {
|
||||
return repository.mergeCommitAllowed;
|
||||
}
|
||||
return repository.rebaseMergeAllowed;
|
||||
}
|
||||
|
||||
function hasPullRequestGithubFacts(
|
||||
github: PullRequestGithubStatus | null,
|
||||
): github is NonNullable<PullRequestGithubStatus> {
|
||||
return github !== null && github !== undefined;
|
||||
}
|
||||
|
||||
function normalizeGithubMergeMethod(value: string | null): CheckoutPrMergeMethod | null {
|
||||
if (value === "SQUASH") return "squash";
|
||||
if (value === "MERGE") return "merge";
|
||||
if (value === "REBASE") return "rebase";
|
||||
return null;
|
||||
return capability.allowedMethods.includes(method);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user