Public: anyone can read this; the crew can change it.
The /__forge/ door's "More pulls are open" line says how many and links to the repository's open pulls #6414
scout/forge:scout/6411-the-forge-door-s-more-pulls-are-open-lin → main 3 commits fork 2 threads · 2 unresolved
4 files
changed +83
−13
src/apps/door.ts +23 −5
| @@ -24,11 +24,18 @@ export type DoorFacts = { | ||
| 24 | 24 | ssh?: string | null; |
| 25 | 25 | /** Open pulls a viewer may see, each with where to go: its preview or the forge. */ |
| 26 | 26 | pulls?: DoorPullLine[] | undefined; |
| 27 | /** How many open pulls the door does not draw; `capped` when there may be more. */ | |
| 28 | morePulls?: DoorMorePulls | undefined; | |
| 27 | 29 | }; |
| 28 | 30 | |
| 29 | /** How many pulls the door lists; one more read than this means there are others. */ | |
| 31 | export type DoorMorePulls = { count: number; capped: boolean }; | |
| 32 | ||
| 33 | /** How many pulls the door lists; the rest are counted. */ | |
| 30 | 34 | export const DOOR_PULL_LIMIT = 5; |
| 31 | 35 | |
| 36 | /** How many the door reads to count them; past this the count says "N+". */ | |
| 37 | export const DOOR_PULL_READ = 50; | |
| 38 | ||
| 32 | 39 | export type DoorPullLine = { number: number; title: string; check: string; href: string }; |
| 33 | 40 | |
| 34 | 41 | const STYLE = |
| @@ -92,12 +99,23 @@ function servingHtml(facts: DoorFacts): string { | ||
| 92 | 99 | return `<p>Serving ${sha(now)} since ${stamp(now.at)}</p>${older === "" ? "" : `<h2>Before it</h2><ul>${older}</ul>`}`; |
| 93 | 100 | } |
| 94 | 101 | |
| 95 | function pullsHtml(pulls: DoorPullLine[] | undefined): string { | |
| 102 | function pullsHtml(facts: DoorFacts): string { | |
| 103 | const pulls = facts.pulls; | |
| 96 | 104 | if (pulls === undefined || pulls.length === 0) return ""; |
| 97 | const items = pulls.slice(0, DOOR_PULL_LIMIT).map((p) => | |
| 105 | const items = pulls.map((p) => | |
| 98 | 106 | link(p.href, `#${p.number} ${[...p.title].slice(0, 120).join("")} · check ${p.check}`), |
| 99 | 107 | ); |
| 100 | const more = pulls.length > DOOR_PULL_LIMIT ? "<p>More pulls are open on the forge.</p>" : ""; | |
| 108 | const rest = facts.morePulls?.count ?? 0; | |
| 109 | let more = ""; | |
| 110 | if (rest > 0) { | |
| 111 | const n = facts.morePulls?.capped === true ? `${rest}+` : `${rest}`; | |
| 112 | const words = `${n} more open ${rest === 1 ? "pull" : "pulls"}`; | |
| 113 | const repo = facts.where.repo; | |
| 114 | more = | |
| 115 | repo === undefined | |
| 116 | ? `<p>${words}</p>` | |
| 117 | : `<p><a href="${escapeAttr(new URL(`/${repo}/pulls`, facts.forgeUrl).href)}">${words}</a></p>`; | |
| 118 | } | |
| 101 | 119 | return `<h2>Open pulls</h2><ul>${items.join("")}</ul>${more}`; |
| 102 | 120 | } |
| 103 | 121 | |
| @@ -119,7 +137,7 @@ export function doorPage(facts: DoorFacts, head: boolean): Response { | ||
| 119 | 137 | : `<p>Terminal:</p><pre><code>${escapeAttr(facts.ssh)}</code></pre>`; |
| 120 | 138 | const html = `<!doctype html> |
| 121 | 139 | <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>${escapeAttr(where.app)}, ${escapeAttr(doorWhere(where))}</title><style>${STYLE}</style></head> |
| 122 | <body><main><h1>${escapeAttr(where.app)}</h1><p>${whereLine(where, forgeUrl)}</p>${servingHtml(facts)}${pullsHtml(facts.pulls)}<ul>${links.join("")}</ul>${terminal}</main></body></html> | |
| 140 | <body><main><h1>${escapeAttr(where.app)}</h1><p>${whereLine(where, forgeUrl)}</p>${servingHtml(facts)}${pullsHtml(facts)}<ul>${links.join("")}</ul>${terminal}</main></body></html> | |
| 123 | 141 | `; |
| 124 | 142 | return new Response(head ? null : html, { |
| 125 | 143 | headers: { |
src/apps/proxy.ts +16 −6
| @@ -39,7 +39,7 @@ import type { AppsRuntime, EnvStatus } from "./runtime.ts"; | ||
| 39 | 39 | import { crewNow, tellLink } from "./crew.ts"; |
| 40 | 40 | import { feedback, mintProof } from "./feedback.ts"; |
| 41 | 41 | import { clientBucket } from "../http/peer.ts"; |
| 42 | import { DOOR_PULL_LIMIT, doorPage, type DoorPullLine } from "./door.ts"; | |
| 42 | import { DOOR_PULL_LIMIT, DOOR_PULL_READ, doorPage, type DoorMorePulls, type DoorPullLine } from "./door.ts"; | |
| 43 | 43 | import { checkWord } from "./check_word.ts"; |
| 44 | 44 | import { openPulls } from "./door_pulls.ts"; |
| 45 | 45 | import { takePhases, timePhase } from "../core/route_timing.ts"; |
| @@ -446,18 +446,20 @@ function doorSsh( | ||
| 446 | 446 | /** |
| 447 | 447 | * The door's open pulls: a preview that is running or asleep links to itself, |
| 448 | 448 | * every other pull to its page on the forge. Empty for whoever may not read. |
| 449 | * Reads one more than the door draws, so it can say there are others. | |
| 449 | * Reads enough to count the ones the door does not draw. | |
| 450 | 450 | */ |
| 451 | 451 | function doorPulls( |
| 452 | 452 | runtime: AppsRuntime, |
| 453 | 453 | target: AppTarget, |
| 454 | 454 | who: GrantWho | undefined, |
| 455 | ): DoorPullLine[] { | |
| 455 | ): { pulls: DoorPullLine[]; morePulls: DoorMorePulls } { | |
| 456 | 456 | const db = runtime.app.db; |
| 457 | 457 | const repo = getRepoById(db, target.app.repoId); |
| 458 | if (repo === undefined) return []; | |
| 458 | if (repo === undefined) return { pulls: [], morePulls: { count: 0, capped: false } }; | |
| 459 | 459 | const viewer = who === undefined ? undefined : getUserById(db, who.id); |
| 460 | return openPulls(db, repo, viewer, DOOR_PULL_LIMIT + 1).map((p) => { | |
| 460 | const read = openPulls(db, repo, viewer, DOOR_PULL_READ); | |
| 461 | // Only the pulls the door draws get an env lookup; the rest are counted. | |
| 462 | const pulls = read.slice(0, DOOR_PULL_LIMIT).map((p) => { | |
| 461 | 463 | const env = previewEnv(p.number); |
| 462 | 464 | const state = runtime.envStatus(target.app, env); |
| 463 | 465 | const live = |
| @@ -477,6 +479,13 @@ function doorPulls( | ||
| 477 | 479 | ).href, |
| 478 | 480 | }; |
| 479 | 481 | }); |
| 482 | return { | |
| 483 | pulls, | |
| 484 | morePulls: { | |
| 485 | count: Math.max(read.length - DOOR_PULL_LIMIT, 0), | |
| 486 | capped: read.length >= DOOR_PULL_READ, | |
| 487 | }, | |
| 488 | }; | |
| 480 | 489 | } |
| 481 | 490 | |
| 482 | 491 | /** Whether the person a grant names may enter this app now. */ |
| @@ -733,7 +742,7 @@ export async function proxyApp( | ||
| 733 | 742 | const serving = timePhase(request, "serving", () => |
| 734 | 743 | readServing(runtime.app.db, target.app.repoId, target.env), |
| 735 | 744 | ); |
| 736 | const pulls = timePhase(request, "pulls", () => | |
| 745 | const { pulls, morePulls } = timePhase(request, "pulls", () => | |
| 737 | 746 | doorPulls(runtime, target, signed?.who), |
| 738 | 747 | ); |
| 739 | 748 | const page = timePhase(request, "render", () => |
| @@ -741,6 +750,7 @@ export async function proxyApp( | ||
| 741 | 750 | { |
| 742 | 751 | where, |
| 743 | 752 | pulls, |
| 753 | morePulls, | |
| 744 | 754 | ...(serving === undefined ? {} : { serving }), |
| 745 | 755 | forgeUrl: runtime.options.forgeUrl, |
| 746 | 756 | ...(ssh === undefined ? {} : { ssh }), |
test/apps-door.test.ts +2 −2
| @@ -416,9 +416,9 @@ test("the door links a dormant preview to itself, and says so when more than fiv | ||
| 416 | 416 | ); |
| 417 | 417 | let html = await (await door(`notes.${DOMAIN}`)).text(); |
| 418 | 418 | expect(html).toContain(`<a href="${runtime.urlFor(record, `pull-${dormant}`)}">#${dormant} quiet one`); |
| 419 | expect(html).not.toContain("More pulls are open"); | |
| 419 | expect(html).not.toContain("more open pull"); | |
| 420 | 420 | for (let i = 0; i < 5; i++) mk(`extra ${i}`); |
| 421 | 421 | html = await (await door(`notes.${DOMAIN}`)).text(); |
| 422 | expect(html).toContain("More pulls are open on the forge."); | |
| 422 | expect(html).toContain("3 more open pulls</a>"); | |
| 423 | 423 | expect((html.match(/ · check /g) ?? []).length).toBe(5); |
| 424 | 424 | }); |
test/door-more-pulls.test.ts added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { DOOR_PULL_LIMIT, DOOR_PULL_READ, doorPage, type DoorPullLine } from "../src/apps/door.ts"; | |
| 3 | ||
| 4 | const pulls = (n: number): DoorPullLine[] => | |
| 5 | Array.from({ length: n }, (_, i) => ({ | |
| 6 | number: i + 1, | |
| 7 | title: `t${i + 1}`, | |
| 8 | check: "passed", | |
| 9 | href: `https://forge.test/trevato/notes/pulls/${i + 1}`, | |
| 10 | })); | |
| 11 | ||
| 12 | const page = async (n: number, repo: string | undefined): Promise<string> => | |
| 13 | doorPage( | |
| 14 | { | |
| 15 | where: { app: "notes", env: "production", ...(repo === undefined ? {} : { repo }) }, | |
| 16 | forgeUrl: "https://forge.test", | |
| 17 | pulls: pulls(Math.min(n, DOOR_PULL_LIMIT)), | |
| 18 | morePulls: { count: Math.max(n - DOOR_PULL_LIMIT, 0), capped: n >= DOOR_PULL_READ }, | |
| 19 | }, | |
| 20 | false, | |
| 21 | ).text(); | |
| 22 | ||
| 23 | test("a reader sees how many more pulls are open, linked to the pulls list", async () => { | |
| 24 | const html = await page(8, "trevato/notes"); | |
| 25 | expect(html).toContain('<a href="https://forge.test/trevato/notes/pulls">3 more open pulls</a>'); | |
| 26 | }); | |
| 27 | ||
| 28 | test("a guest sees the count and no link or repository name", async () => { | |
| 29 | const html = await page(8, undefined); | |
| 30 | expect(html).toContain("<p>3 more open pulls</p>"); | |
| 31 | expect(html).not.toMatch(/href="[^"]*\/pulls"/); | |
| 32 | expect(html.split("3 more open pulls")[1]).not.toContain("trevato/notes"); | |
| 33 | }); | |
| 34 | ||
| 35 | test("with five or fewer the line is absent", async () => { | |
| 36 | for (const n of [0, 3, 5]) expect(await page(n, "trevato/notes")).not.toContain("more open pull"); | |
| 37 | }); | |
| 38 | ||
| 39 | test("one more says pull, and a full read says N+", async () => { | |
| 40 | expect(await page(6, "trevato/notes")).toContain("1 more open pull<"); | |
| 41 | expect(await page(50, "trevato/notes")).toContain("45+ more open pulls"); | |
| 42 | }); |
new above
offline
The count needs only the number of pulls. proxy.ts builds a full line (envStatus lookup) for up to 50 pulls to get it. Return the count separately, or resolve env state only for the first five.