feat(source-control): add Entire as a source control host #24180
Closedpeyton-alt(GitHub profile, opens in a new tab)wants to merge 20 commits into
main fromrefs/pull/24180/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- packages/source-control-entire/src/server/EntirePullRequestProvider.ts line 840OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +820,21 @@820+ .map((trail) => Json.toListChangeRequest(trail, input.repository, readiness))821+ .filter(involved),822+ );823+ const previous: string | null = cursor;824+ cursor = batch.next_cursor ?? null;825+ if (cursor === null || cursor === previous || items.length >= limit) break;826+ }827+ const rows = items.slice(0, limit);828+ const open = new Set(rows.filter((row) => row.state === "open").map((row) => row.number));829+ const verdicts =830+ open.size === 0831+ ? new Map<number, PullRequestMergeability>()832+ : yield* listMergeability(input, project, open).pipe(833+ Effect.orElseSucceed(() => new Map<number, PullRequestMergeability>()),834+ );835+ return {836+ items: rows.map((row) => {837+ const verdict = open.has(row.number) ? verdicts.get(row.number) : undefined;838+ return verdict === undefined ? row : { ...row, mergeability: verdict };839+ }),840+ truncated: cursor !== null,packages/shared/src/changeRequestUrl.ts lines 213 to 213OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -187,7 +205,9 @@187205 export function changeRequestRepositoryUrl(targetUrl: string): string | null {188206 const changeRequest = parseChangeRequestUrl(targetUrl);189207 if (changeRequest === null) return null;208+ // A change linked through its project trail has no repository prefix to cut back to.209+ if (changeRequest.host === "entire.com") return `https://entire.com/${changeRequest.repository}`;190210 const url = new URL(targetUrl);191211 const repositoryPath =192212 /^(.*?)\/-\/merge_requests\/\d+(?:\/|$)/iu.exec(url.pathname)?.[1] ??193- /^(.*?)(?:\/pulls?\/\d+|\/-\/merge_requests\/\d+|\/pull-requests\/\d+|\/pullrequest\/\d+)(?:\/|$)/iu.exec(213+ /^(.*?)(?:\/pulls?\/\d+|\/-\/merge_requests\/\d+|\/pull-requests\/\d+|\/pullrequest\/\d+|\/trails\/\d+)(?:\/|$)/iu.exec(packages/source-control-entire/src/server/EntirePullRequestProvider.ts line 958OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +938,21 @@938+ ),939+ getDiff: Effect.fn("EntirePullRequestProvider.getDiff")(function* (input) {940+ const { from, to } = yield* diffRange(input);941+ const result = yield* runGit(942+ "getDiff",943+ input.cwd,944+ ["diff", ...PATCH_OPTIONS, from, to],945+ "Could not diff the trail.",946+ );947+ return { patch: result.stdout, truncated: result.stdoutTruncated, nextCursor: null };948+ }),949+ getDiffFileContents: Effect.fn("EntirePullRequestProvider.getDiffFileContents")(950+ function* (input) {951+ const { from, to } = yield* diffRange(input);952+ const blob = (revision: string, path: string) =>953+ runGit(954+ "getDiffFileContents",955+ input.cwd,956+ ["cat-file", "blob", `${revision}:${path}`],957+ `Could not read ${path}.`,958+ ).pipe(Effect.map((result) => result.stdout));packages/source-control-entire/src/server/EntirePullRequestProvider.ts lines 257 to 257OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +237,21 @@237+ operation: "EntirePullRequestProvider.isAncestor",238+ cwd,239+ args: ["merge-base", "--is-ancestor", ancestor, descendant],240+ })241+ .pipe(242+ Effect.as(true),243+ Effect.orElseSucceed(() => false),244+ );245+246+ // A merged head is in its base and may have been fast-forwarded, so the diff starts at the247+ // parent of the first timeline commit still under the head.248+ const landedBase = Effect.fn("EntirePullRequestProvider.landedBase")(function* (249+ input: TrailRef,250+ head: string,251+ ) {252+ const timeline = yield* read(253+ "getDiff",254+ input,255+ { path: `${trailPath(input)}/timeline?pageSize=100` },256+ Json.EntireTimeline,257+ );packages/source-control-entire/src/server/EntireSourceControlProvider.ts lines 247 to 247OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +227,21 @@227+ mergedAt: trail.merged_at ?? null,228+ updatedAt: DateTime.make(trail.updated_at),229+ isCrossRepository: false,230+ headRepositoryNameWithOwner: target.repository,231+ };232+ };233+234+ return SourceControlProvider.SourceControlProvider.of({235+ kind: KIND,236+ repositoryNameFromRemoteUrl: (url) => EntireUrls.parseEntireRemote(url)?.repository ?? null,237+ getChangeRequest: (input) =>238+ getTrail(input).pipe(Effect.map(({ trail, target }) => toChangeRequest(trail, target))),239+ listChangeRequests: Effect.fn("EntireSourceControlProvider.listChangeRequests")(240+ function* (input) {241+ const target = yield* resolveTarget("listChangeRequests", input);242+ const branch = SourceControlProvider.sourceBranch(input);243+ const limit = input.limit ?? 20;244+ const items: Array<ChangeRequest> = [];245+ // The trail list has no branch filter, so the branch's trails are picked from its pages.246+ let cursor: string | null = null;247+ for (let page = 0; page < MAX_BRANCH_PAGES && items.length < limit; page++) {packages/source-control-entire/src/server/entireTrailBody.ts line 120OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +100,21 @@100+ .map((line) => `> ${line}`)101+ .join("\n");102+ case "horizontalRule":103+ return "---";104+ default:105+ return children(node).length > 0106+ ? children(node).map(renderBlock).filter(Boolean).join("\n\n")107+ : renderText(node);108+ }109+}110+111+export function trailBodyMarkdown(document: {112+ readonly text_snapshot: string;113+ readonly content_json?: unknown;114+}): string {115+ const doc = document.content_json;116+ const rendered = isNode(doc) && doc.type === "doc" ? renderBlock(doc) : "";117+ const body = rendered.trim() === "" ? document.text_snapshot : rendered;118+ return body119+ .replace(TRAIL_LINK, "")120+ .replace(/\n{3,}/gu, "\n\n")packages/source-control-entire/src/server/entireTrailBody.ts line 31OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +11,21 @@11+ readonly text?: unknown;12+ readonly attrs?: Record<string, unknown> | null;13+ readonly marks?: ReadonlyArray<ProseMirrorMark> | null;14+ readonly content?: ReadonlyArray<ProseMirrorNode> | null;15+}16+17+/** Entire's self-link at the top of a trail body is noise inside the trail itself. */18+const TRAIL_LINK =19+ /<!--\s*entire-trail-link-start\s*-->[\s\S]*?<!--\s*entire-trail-link-end\s*-->/gu;20+21+const isNode = (value: unknown): value is ProseMirrorNode =>22+ typeof value === "object" && value !== null && !Array.isArray(value);23+24+const children = (node: ProseMirrorNode): ReadonlyArray<ProseMirrorNode> =>25+ Array.isArray(node.content) ? node.content.filter(isNode) : [];26+27+const safeHref = (href: unknown): string | null =>28+ typeof href === "string" && /^(https?:|mailto:)/iu.test(href) ? href : null;29+30+function renderText(node: ProseMirrorNode): string {31+ let text = typeof node.text === "string" ? node.text : "";packages/source-control-entire/src/server/entireTrailBody.ts line 35OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +15,21 @@15+}16+17+/** Entire's self-link at the top of a trail body is noise inside the trail itself. */18+const TRAIL_LINK =19+ /<!--\s*entire-trail-link-start\s*-->[\s\S]*?<!--\s*entire-trail-link-end\s*-->/gu;20+21+const isNode = (value: unknown): value is ProseMirrorNode =>22+ typeof value === "object" && value !== null && !Array.isArray(value);23+24+const children = (node: ProseMirrorNode): ReadonlyArray<ProseMirrorNode> =>25+ Array.isArray(node.content) ? node.content.filter(isNode) : [];26+27+const safeHref = (href: unknown): string | null =>28+ typeof href === "string" && /^(https?:|mailto:)/iu.test(href) ? href : null;29+30+function renderText(node: ProseMirrorNode): string {31+ let text = typeof node.text === "string" ? node.text : "";32+ if (text === "") return "";33+ const marks = Array.isArray(node.marks) ? node.marks : [];34+ const has = (type: string) => marks.some((mark) => mark?.type === type);35+ if (has("code")) return `\`${text}\``;packages/source-control-entire/src/server/entireTrailJson.ts lines 454 to 454OutdatedResolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +434,21 @@434+ repository: string,435+): ReadonlyArray<PullRequestCheck> {436+ const runs = runsRead(detail) ? (detail.mergeability?.checks?.runs ?? []) : [];437+ return sortChecks([438+ ...runs439+ .filter((run) => run.name)440+ .map((run) => ({441+ name: run.name,442+ status: checkStatus(run),443+ description: run.app_name ?? null,444+ url: run.details_url ?? null,445+ })),446+ ...gateChecks(detail, repository),447+ ]);448+}449+450+export function toChecksState(451+ checks: ReadonlyArray<PullRequestCheck>,452+): PullRequestChecksState | undefined {453+ if (checks.length === 0) return undefined;454+ if (checks.some((check) => check.status === "failure" || check.status === "action-required"))
- packages/source-control-entire/src/server/EntireSourceControlProvider.ts lines 322 to 331Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +301,21 @@301+ Effect.map((repository) => repository.body.owning_project_id?.trim() || null),302+ ));303+ if (projectId === null)304+ return yield* error(305+ operation,306+ input.cwd,307+ `Entire did not say which project owns ${target.repository}.`,308+ );309+ const branch = SourceControlProvider.sourceBranch(input);310+ const description = body.trim().length === 0 ? {} : { body };311+ // A trail belongs to the project; the branch is linked to it as this repository's change.312+ const created = yield* requestJson(313+ {314+ ...located,315+ scope: "project",316+ method: "POST",317+ path: `?${new URLSearchParams({ project_id: projectId })}`,318+ body: { title: input.title, ...description, repoIds: [coordinates.repoId] },319+ },320+ CreatedProjectTrail,321+ );packages/source-control-entire/src/server/EntireSourceControlProvider.ts lines 422 to 465Resolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +417,21 @@417+ "This trail has no branch to check out yet.",418+ );419+ if (!remoteName)420+ return yield* error(421+ "checkoutChangeRequest",422+ input.cwd,423+ "Check out a trail from a clone of its Entire repository.",424+ );425+ const git = host.git;426+ yield* Effect.gen(function* () {427+ const branches = yield* git.listLocalBranchNames(input.cwd);428+ const remoteBranch = { cwd: input.cwd, remoteName, remoteBranch: branch };429+ if (input.force !== true && !branches.includes(branch))430+ yield* git.fetchRemoteBranch({ ...remoteBranch, localBranch: branch });431+ else yield* git.fetchRemoteTrackingBranch(remoteBranch);432+ if (input.force === true)433+ yield* git.execute({434+ operation: "EntireSourceControlProvider.checkoutChangeRequest",435+ cwd: input.cwd,436+ args: ["checkout", "-B", branch, `refs/remotes/${remoteName}/${branch}`, "--"],437+ });
t3dotgg(GitHub profile, opens in a new tab) reopened this
- apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx line 582Resolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -505,4 +509,7 @@505509 const result = await update({ environmentId, input: { ...reference, body } });506510 setBodySaving(false);507511 if (result._tag === "Failure") {508- toastManager.add({ type: "error", title: "Could not save the description" });512+ toastManager.add({513+ type: "error",514+ title: "Could not save the description",515+ description: readableFailure(squashAtomCommandFailure(result), SAVE_FAILURE_HINT),packages/source-control-entire/src/server/entireTrailBody.ts lines 27 to 28Resolvedby peyton-alt(GitHub profile, opens in a new tab)@@ -0,0 +8,21 @@8+9+interface ProseMirrorNode {10+ readonly type?: unknown;11+ readonly text?: unknown;12+ readonly attrs?: Record<string, unknown> | null;13+ readonly marks?: ReadonlyArray<ProseMirrorMark> | null;14+ readonly content?: ReadonlyArray<ProseMirrorNode> | null;15+}16+17+/** Entire's self-link at the top of a trail body is noise inside the trail itself. */18+const TRAIL_LINK =19+ /<!--\s*entire-trail-link-start\s*-->[\s\S]*?<!--\s*entire-trail-link-end\s*-->/gu;20+21+const isNode = (value: unknown): value is ProseMirrorNode =>22+ typeof value === "object" && value !== null && !Array.isArray(value);23+24+const children = (node: ProseMirrorNode): ReadonlyArray<ProseMirrorNode> =>25+ Array.isArray(node.content) ? node.content.filter(isNode) : [];26+27+const safeHref = (href: unknown): string | null =>28+ typeof href === "string" && /^(https?:|mailto:)/iu.test(href) ? href : null;
tanstack-source added labelsfeature
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.










macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed