mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-28 04:03:05 +00:00
* feat(protocol): add forge check presentation metadata Expose optional rawStatus, isManual, and requiresAction fields while keeping older check payloads backward-compatible. * fix(gitea): model Actions jobs as tasks Gitea's /actions/tasks endpoint returns individual jobs rather than workflow runs. Preserve sibling tasks from the latest execution, avoid collapsing same-name jobs, and enrich blocked tasks with run-level approval metadata. * feat(app): distinguish forge check presentation states * fix(gitlab): preserve pipeline job semantics * refactor(app): centralize forge check presentation policy Use one canonical category order, count shape, visual policy, and translated copy mapping across sidebar, hover-card, PR-pane, and GitLab pipeline surfaces. * refactor: consolidate forge check handling * feat(forge): auto-attach pasted forge references * docs(compat): correct forge rollout metadata * refactor(forge): model check nuances as traits * fix(forge): harden checks from branch review Structural Gitea Actions shadow dedup by run id (verified upstream), rerun grouping without workflow_id, shared trait/status constants and Gitea state mapping in the protocol package, all cloud host aliases in pasted-link matching, logged glab job-detail failures, concurrent approvals/pipeline fetch, checks aggregate from the same pipeline as the job list, and removal of the unread check-level rawStatus. The released pipeline-level rawStatus is staged for removal under COMPAT(pipelineRawStatus). * fix(gitea): detect fork-PR Actions approval hold as action_required gitea.com represents a fork PR awaiting Actions approval as a run in status "waiting" with no tasks and pending shadow commit statuses; it does not expose need_approval. The previous mapping only set action_required from a task with blocked+need_approval, so the gate never surfaced (0 tasks -> early return; need_approval absent). Detect the hold from /actions/runs: a waiting/blocked run whose PR is cross-repo (head.repo.id != base.repo.id), or one that does expose need_approval (self-hosted). Tag the run's pending shadow statuses action_required. Runs are only fetched when a pending shadow has no covering task, keeping the common path at two requests. Verified live against gitea.com fork PR (run 715170, waiting, cross-repo). * fix(gitea): resolve cross-fork PRs by head sha The current-PR matcher gated candidates on the checkout owner (giteaHeadOwner === expectedHeadOwner), which excludes every fork PR: its head carries the fork owner while the checkout is the base repo, so a fork PR - the only shape that can be approval-held on Gitea - never resolved and its checks never showed in-app. GitLab has no such gate (it resolves fork MRs from the target project by source branch). Accept a recent PR whose head sha equals the workspace head sha regardless of owner; the sha is an unambiguous identity, so the anti-collision owner gate still applies when no sha match is available. Verified live against gitea.com fork PR #6 (resolves + renders action_required). * fix: resolve forge rebase drift * fix: type forge auto-attach boundary * fix(i18n): add Korean check status copy --------- Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
179 lines
5.7 KiB
TypeScript
179 lines
5.7 KiB
TypeScript
import { z } from "zod";
|
|
import {
|
|
defineForgeFacts,
|
|
type ClientForgeLogicModule,
|
|
type MergeCapability,
|
|
} from "@/git/client-forge-module";
|
|
import type { CheckoutPipelineJob, CheckoutPrMergeMethod } from "@getpaseo/protocol/messages";
|
|
import {
|
|
CHECK_TRAIT_ACTION_REQUIRED,
|
|
CHECK_TRAIT_MANUAL,
|
|
CHECK_TRAIT_WARNING,
|
|
} from "@getpaseo/protocol/check-traits";
|
|
import { GITLAB_ACTIVE_PIPELINE_STATUS_SET } from "@getpaseo/protocol/gitlab-pipeline";
|
|
import type { CheckStatus } from "@/git/pull-request-panel/check-status";
|
|
import {
|
|
classifyCheck,
|
|
countCheckPresentations,
|
|
type CheckPresentation,
|
|
type CheckPresentationCounts,
|
|
type PresentableCheck,
|
|
} from "@/git/check-presentation";
|
|
|
|
const gitlabLineAnchor = (start: number, end?: number): string =>
|
|
end && end > start ? `#L${start}-${end}` : `#L${start}`;
|
|
|
|
export function isPipelineActiveStatus(status: string): boolean {
|
|
return GITLAB_ACTIVE_PIPELINE_STATUS_SET.has(status);
|
|
}
|
|
|
|
export function mapPipelineStatus(status: string): CheckStatus {
|
|
switch (status) {
|
|
case "success":
|
|
case "passed":
|
|
return "success";
|
|
case "failed":
|
|
return "failure";
|
|
case "canceled":
|
|
case "cancelled":
|
|
case "skipped":
|
|
return "skipped";
|
|
default:
|
|
// "manual" and every active transitional status (see
|
|
// GITLAB_ACTIVE_PIPELINE_STATUSES) render as pending.
|
|
return "pending";
|
|
}
|
|
}
|
|
|
|
type GitlabPipelineJobPresentationInput = Pick<CheckoutPipelineJob, "status" | "allowFailure">;
|
|
|
|
function toPresentableGitlabPipelineJob(job: GitlabPipelineJobPresentationInput): PresentableCheck {
|
|
const status = mapPipelineStatus(job.status);
|
|
if (job.status === "manual") {
|
|
return {
|
|
status,
|
|
traits: job.allowFailure
|
|
? [CHECK_TRAIT_MANUAL]
|
|
: [CHECK_TRAIT_MANUAL, CHECK_TRAIT_ACTION_REQUIRED],
|
|
};
|
|
}
|
|
if (status === "failure" && job.allowFailure) return { status, traits: [CHECK_TRAIT_WARNING] };
|
|
return { status };
|
|
}
|
|
|
|
export function classifyGitlabPipelineJob(
|
|
job: GitlabPipelineJobPresentationInput,
|
|
): CheckPresentation {
|
|
return classifyCheck(toPresentableGitlabPipelineJob(job));
|
|
}
|
|
|
|
export function countGitlabPipelineJobs(
|
|
jobs: readonly CheckoutPipelineJob[],
|
|
): CheckPresentationCounts {
|
|
return countCheckPresentations(jobs.map(toPresentableGitlabPipelineJob));
|
|
}
|
|
|
|
const GitlabMergeFactsSchema = z
|
|
.object({
|
|
forge: z.literal("gitlab"),
|
|
detailedMergeStatus: z.string().nullable().optional().default(null),
|
|
mergeStatus: z.string().nullable().optional().default(null),
|
|
hasConflicts: z.boolean().optional().default(false),
|
|
blockingDiscussionsResolved: z.boolean().optional().default(true),
|
|
approvalsRequired: z.number().optional().default(0),
|
|
approvalsGiven: z.number().optional().default(0),
|
|
pipelineStatus: z.string().nullable().optional().default(null),
|
|
pipelineId: z.number().nullable().optional().default(null),
|
|
pipelineUrl: z.string().nullable().optional().default(null),
|
|
mergeWhenPipelineSucceeds: z.boolean().optional().default(false),
|
|
})
|
|
.passthrough();
|
|
|
|
export type GitlabMergeFacts = z.infer<typeof GitlabMergeFactsSchema>;
|
|
|
|
export { GitlabMergeFactsSchema };
|
|
|
|
const GITLAB_MERGEABLE_STATUS = "mergeable";
|
|
const GITLAB_LEGACY_MERGEABLE_STATUS = "can_be_merged";
|
|
const GITLAB_MERGE_METHODS: CheckoutPrMergeMethod[] = ["merge", "squash", "rebase"];
|
|
|
|
/**
|
|
* Direct-merge readiness from GitLab's merge signals. `detailedMergeStatus` is
|
|
* GitLab 15.6+ only; when it is absent (older self-managed instances) fall back
|
|
* to the legacy `mergeStatus === "can_be_merged"` with no conflicts so merge is
|
|
* not silently refused everywhere.
|
|
*/
|
|
function isGitlabDirectMergeReady(gitlab: GitlabMergeFacts): boolean {
|
|
if (gitlab.detailedMergeStatus != null) {
|
|
return gitlab.detailedMergeStatus === GITLAB_MERGEABLE_STATUS;
|
|
}
|
|
return gitlab.mergeStatus === GITLAB_LEGACY_MERGEABLE_STATUS && gitlab.hasConflicts !== true;
|
|
}
|
|
|
|
function deriveGitlabMergeCapability(gitlab: GitlabMergeFacts): MergeCapability {
|
|
const autoMergeEnabled = gitlab.mergeWhenPipelineSucceeds === true;
|
|
const hasActivePipeline =
|
|
gitlab.pipelineStatus !== null && isPipelineActiveStatus(gitlab.pipelineStatus);
|
|
return {
|
|
directMergeReady: isGitlabDirectMergeReady(gitlab),
|
|
canEnableAutoMerge: !autoMergeEnabled && hasActivePipeline,
|
|
autoMergeEnabled,
|
|
canDisableAutoMerge: autoMergeEnabled,
|
|
mergeBlockedByQueue: false,
|
|
allowedMethods: GITLAB_MERGE_METHODS,
|
|
preferredMethod: null,
|
|
};
|
|
}
|
|
|
|
export interface GitlabPipelineSummary {
|
|
id: number;
|
|
status: CheckStatus;
|
|
rawStatus: string;
|
|
url: string | null;
|
|
}
|
|
|
|
export interface GitlabApprovals {
|
|
given: number;
|
|
required: number;
|
|
}
|
|
|
|
export function deriveGitlabPipelineSummary(facts: GitlabMergeFacts): GitlabPipelineSummary | null {
|
|
if (facts.pipelineId == null) {
|
|
return null;
|
|
}
|
|
const rawStatus = facts.pipelineStatus ?? "";
|
|
return {
|
|
id: facts.pipelineId,
|
|
status: mapPipelineStatus(rawStatus),
|
|
rawStatus,
|
|
url: facts.pipelineUrl ?? null,
|
|
};
|
|
}
|
|
|
|
export function deriveGitlabApprovals(facts: GitlabMergeFacts): GitlabApprovals | null {
|
|
const required = facts.approvalsRequired ?? 0;
|
|
if (required <= 0) {
|
|
return null;
|
|
}
|
|
return { given: facts.approvalsGiven ?? 0, required };
|
|
}
|
|
|
|
export const gitlabForgeLogic = {
|
|
id: "gitlab",
|
|
urlGrammar: {
|
|
treeInfix: "/-/tree/",
|
|
blobInfix: "/-/blob/",
|
|
lineAnchor: gitlabLineAnchor,
|
|
changeRequestChecksSuffix: "/pipelines",
|
|
referencePaths: [
|
|
{ kind: "change_request", infix: "/-/merge_requests/" },
|
|
{ kind: "issue", infix: "/-/issues/" },
|
|
],
|
|
},
|
|
facts: defineForgeFacts({
|
|
family: "gitlab",
|
|
schema: GitlabMergeFactsSchema,
|
|
deriveMergeCapability: deriveGitlabMergeCapability,
|
|
}),
|
|
} satisfies ClientForgeLogicModule<GitlabMergeFacts>;
|