mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-28 20:22:45 +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>
157 lines
5.5 KiB
TypeScript
157 lines
5.5 KiB
TypeScript
/**
|
|
* Forge-neutral web URL builders for "Open on <forge>" actions (a file blob or a
|
|
* branch tree). The host comes from the workspace remote — not a hardcoded
|
|
* cloud host — so self-hosted and Enterprise instances link correctly. Each
|
|
* forge contributes a small URL grammar (the path infixes and line-anchor
|
|
* format); an unknown forge has no grammar and yields null, so the action is
|
|
* simply absent rather than wrong.
|
|
*
|
|
* URL grammar lives on each client forge module. The repo identity and host
|
|
* both ride the manifest's `cloudHosts` only to canonicalize a cloud SSH alias
|
|
* (e.g. ssh.github.com -> github.com); a self-hosted host is used as-is.
|
|
*/
|
|
import { getForgeDefinition } from "@getpaseo/protocol/forge-manifest";
|
|
import { normalizeHost, parseGitRemoteLocation } from "@getpaseo/protocol/git-remote";
|
|
import { getClientForgeLogicModule } from "@/git/forges";
|
|
|
|
export interface ForgeBlobUrlInput {
|
|
remoteUrl: string | null | undefined;
|
|
branch: string | null | undefined;
|
|
path: string | null | undefined;
|
|
lineStart?: number;
|
|
lineEnd?: number;
|
|
}
|
|
|
|
export interface ForgeBranchTreeUrlInput {
|
|
remoteUrl: string | null | undefined;
|
|
branch: string | null | undefined;
|
|
}
|
|
|
|
export function buildForgeChecksUrl(forge: string, changeRequestUrl: string): string | null {
|
|
const suffix = getClientForgeLogicModule(forge)?.urlGrammar?.changeRequestChecksSuffix;
|
|
if (!suffix) {
|
|
return null;
|
|
}
|
|
try {
|
|
const url = new URL(changeRequestUrl);
|
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
return null;
|
|
}
|
|
url.pathname = `${url.pathname.replace(/\/$/, "")}${suffix}`;
|
|
return url.toString();
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
interface ForgeWebLocation {
|
|
host: string;
|
|
/** Non-default port for a self-hosted http(s) origin, or undefined. */
|
|
port?: string;
|
|
repo: string;
|
|
}
|
|
|
|
/**
|
|
* Web host + repo path from a remote. The host is the remote's host, except a
|
|
* cloud SSH alias (a non-first entry in the forge's `cloudHosts`, e.g.
|
|
* ssh.github.com) is canonicalized to the forge's web host (`cloudHosts[0]`).
|
|
* Self-hosted hosts are returned untouched. The repo path supports nested
|
|
* groups (e.g. GitLab subgroups) since it is the full remote path.
|
|
*/
|
|
function isValidRepoPath(path: string): boolean {
|
|
const segments = path.split("/").filter((segment) => segment.length > 0);
|
|
if (segments.length === 0) {
|
|
return false;
|
|
}
|
|
return !segments.includes("..");
|
|
}
|
|
|
|
function resolveForgeWebLocation(
|
|
forge: string,
|
|
remoteUrl: string | null | undefined,
|
|
): ForgeWebLocation | null {
|
|
if (!remoteUrl) {
|
|
return null;
|
|
}
|
|
const location = parseGitRemoteLocation(remoteUrl);
|
|
if (!location || !isValidRepoPath(location.path)) {
|
|
return null;
|
|
}
|
|
const cloudHosts = (getForgeDefinition(forge)?.cloudHosts ?? []).map(normalizeHost);
|
|
const isCloudHost = cloudHosts.includes(location.host);
|
|
const webHost = isCloudHost ? cloudHosts[0] : location.host;
|
|
// Carry a non-default port only for a self-hosted http(s) origin (e.g.
|
|
// `:60443`): the web UI shares that origin. An SSH/scp remote's port is not the
|
|
// web port, and a canonicalized cloud host always serves on the default port.
|
|
const port =
|
|
!isCloudHost && (location.transport === "http" || location.transport === "https")
|
|
? location.port
|
|
: undefined;
|
|
return { host: webHost, port, repo: location.path };
|
|
}
|
|
|
|
function encodeBranch(branch: string): string {
|
|
return branch.split("/").map(encodeURIComponent).join("/");
|
|
}
|
|
|
|
/** Host, plus `:port` when the remote pins a non-default port. */
|
|
function forgeAuthority(location: ForgeWebLocation): string {
|
|
return location.port ? `${location.host}:${location.port}` : location.host;
|
|
}
|
|
|
|
function normalizeBlobPath(path: string | null | undefined): string | null {
|
|
const segments: string[] = [];
|
|
const trimmed = path?.trim().replace(/\\/g, "/").replace(/^\/+/, "");
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
for (const segment of trimmed.split("/")) {
|
|
if (!segment || segment === ".") {
|
|
continue;
|
|
}
|
|
if (segment === "..") {
|
|
if (segments.length === 0) {
|
|
return null;
|
|
}
|
|
segments.pop();
|
|
continue;
|
|
}
|
|
segments.push(segment);
|
|
}
|
|
return segments.join("/") || null;
|
|
}
|
|
|
|
export function buildForgeBranchTreeUrl(
|
|
forge: string,
|
|
input: ForgeBranchTreeUrlInput,
|
|
): string | null {
|
|
const grammar = getClientForgeLogicModule(forge)?.urlGrammar;
|
|
const location = resolveForgeWebLocation(forge, input.remoteUrl);
|
|
const branch = input.branch?.trim();
|
|
if (!grammar || !location || !branch || branch === "HEAD") {
|
|
return null;
|
|
}
|
|
return `https://${forgeAuthority(location)}/${location.repo}${grammar.treeInfix}${encodeBranch(branch)}`;
|
|
}
|
|
|
|
export function buildForgeBlobUrl(forge: string, input: ForgeBlobUrlInput): string | null {
|
|
const grammar = getClientForgeLogicModule(forge)?.urlGrammar;
|
|
const location = resolveForgeWebLocation(forge, input.remoteUrl);
|
|
const branch = input.branch?.trim();
|
|
const filePath = normalizeBlobPath(input.path);
|
|
if (!grammar || !location || !branch || branch === "HEAD" || !filePath) {
|
|
return null;
|
|
}
|
|
const encodedPath = filePath.split("/").map(encodeURIComponent).join("/");
|
|
let url = `https://${forgeAuthority(location)}/${location.repo}${grammar.blobInfix}${encodeBranch(branch)}/${encodedPath}`;
|
|
if (input.lineStart && input.lineStart > 0) {
|
|
url += grammar.lineAnchor(input.lineStart, input.lineEnd);
|
|
}
|
|
return url;
|
|
}
|
|
|
|
/** Whether the forge has web URL builders (i.e. a known URL grammar). */
|
|
export function hasForgeWebUrls(forge: string): boolean {
|
|
return getClientForgeLogicModule(forge)?.urlGrammar !== undefined;
|
|
}
|