Public: anyone can read this; the crew can change it.
/changelog lists the last 30 releases, newest first, each with its date and its pulls, readable by anyone #6966
scout/forge:scout/6917-changelog-lists-the-last-30-releases-new → main 4 commits fork
8 files
changed +218
−2
docs/design/audit.md +2 −1
| @@ -33,7 +33,7 @@ their own vocabulary instead of composing the named one. | ||
| 33 | 33 | |
| 34 | 34 | ## Finding 2 — the pages, and what each is for |
| 35 | 35 | |
| 36 | There are 62 top-level pages, one entry each: every static `GET` route in `src/http/server.ts` | |
| 36 | There are 63 top-level pages, one entry each: every static `GET` route in `src/http/server.ts` | |
| 37 | 37 | that returns a page (`test/design-audit.test.ts` holds this list to the router, |
| 38 | 38 | both ways). Each entry reads `route` — module · what it is for · what |
| 39 | 39 | duplicates it · what breaks `docs/DESIGN.md`. "Breaks" counts colour literals |
| @@ -62,6 +62,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 62 | 62 | - `/map` — `pages/map.ts` (1,806 lines) · the dependency map of work across the forge · `/board`, issue dependency lists, `/:owner/:name/map` · colours 3, sizes 12: the largest private vocabulary. |
| 63 | 63 | - `/audit` — `pages/audit.ts` · every app's contract, who can do what · the app page's one-line policy · none seen. Names the audit of apps, not this document. |
| 64 | 64 | - `/releases` — `pages/releases.ts` · the forge's kept releases and rollback · `/settings/backups` (both are "go back") · none seen. |
| 65 | - `/changelog` — `pages/changelog.ts` · the last 30 releases with their dates and pulls, public · `/releases` (the signed-in kept releases) · none seen. | |
| 65 | 66 | - `/contribute` — `pages/contribute.ts` · what this forge is and where outside work is welcome, open to anyone · `/llms.txt`, MCP `contribute` tool · none seen. |
| 66 | 67 | - `/search` — `pages/search.ts` · find across what I can read · the palette (`palette.ts`) · none seen. |
| 67 | 68 | - `/-/confirm` — `pages/search.ts` (`confirmPage`) · the "are you sure" step for a destructive action · none · none seen. |
docs/features/changelog.md added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | # Changelog | |
| 2 | ||
| 3 | `GET /changelog` is public. It lists the last 30 `Release <version>: …` commits on the default branch of the forge's own repository (`FORGE_REPO`), newest first. Each has a heading anchored `#<version>`, its date, and one link per pull named in the subject (`title (#N);title (#N)`). When `FORGE_REPO` is unset or its repository is private, the page answers 200 with "No releases yet". The footer links to it. | |
| 4 | ||
| 5 | One bounded `git log` read, cached per head oid; Server-Timing names `releases` and `render`. |
forge.json +1 −1
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | "api.anthropic.com" |
| 4 | 4 | ], |
| 5 | 5 | "app": { |
| 6 | "looks": ["/", "/forges", "/family", "/front", "/explore", "/board", "/boards", "/asked", "/review", "/search", "/new", "/audit", "/releases", "/apps", "/migrate", "/map", "/system", "/contribute", "/resilience", "/settings"], | |
| 6 | "looks": ["/", "/forges", "/family", "/front", "/explore", "/board", "/boards", "/asked", "/review", "/search", "/new", "/audit", "/releases", "/changelog", "/apps", "/migrate", "/map", "/system", "/contribute", "/resilience", "/settings"], | |
| 7 | 7 | "run": "bun run src/main.ts", |
| 8 | 8 | "install": "", |
| 9 | 9 | "health": "/healthz", |
src/core/reserved.ts +1
| @@ -121,6 +121,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 121 | 121 | "git", |
| 122 | 122 | "ssh", |
| 123 | 123 | "status", |
| 124 | "changelog", | |
| 124 | 125 | "docs", |
| 125 | 126 | "open-platform", |
| 126 | 127 | ]; |
src/http/server.ts +2
| @@ -159,6 +159,7 @@ import { | ||
| 159 | 159 | backupsTest, |
| 160 | 160 | domainsMoved, |
| 161 | 161 | } from "../web/pages/backups.ts"; |
| 162 | import { changelogPage } from "../web/pages/changelog.ts"; | |
| 162 | 163 | import { releasesPage, rollbackSubmit } from "../web/pages/releases.ts"; |
| 163 | 164 | import { |
| 164 | 165 | cloudAdd, |
| @@ -774,6 +775,7 @@ export function buildRouter(): Router<Handler> { | ||
| 774 | 775 | router.add("GET", "/new", newRepoPage); |
| 775 | 776 | router.add("GET", "/audit", auditPage); |
| 776 | 777 | router.add("GET", "/releases", releasesPage); |
| 778 | router.add("GET", "/changelog", changelogPage); | |
| 777 | 779 | router.add("POST", "/releases/:sha/rollback", rollbackSubmit); |
| 778 | 780 | router.add("GET", "/audit.csv", auditCsv); |
| 779 | 781 | router.add("POST", "/audit/:owner/:name/probe", auditProbeSubmit); |
src/web/layout.ts +1
| @@ -491,6 +491,7 @@ function footer(ctx: Ctx): Html { | ||
| 491 | 491 | >${reduced}</span |
| 492 | 492 | >`} |
| 493 | 493 | <span class="spacer"></span> |
| 494 | <a href="/changelog">Changelog</a> | |
| 494 | 495 | <button |
| 495 | 496 | class="btn js-only" |
| 496 | 497 | data-variant="link" |
src/web/pages/changelog.ts added +102
| @@ -0,0 +1,102 @@ | ||
| 1 | /** | |
| 2 | * The changelog: the last 30 `Release <version>: …` commits on the forge's | |
| 3 | * own default branch, newest first, each with its date and the pulls it | |
| 4 | * carried. Public and server-rendered; one bounded `git log` read, kept per | |
| 5 | * head oid so a request between releases touches git only for `rev-parse`. | |
| 6 | */ | |
| 7 | ||
| 8 | import { getRepo } from "../../core/repos.ts"; | |
| 9 | import { notePhase, takeSessionTime, timePhaseAsync } from "../../core/route_timing.ts"; | |
| 10 | import { runGit } from "../../git/env.ts"; | |
| 11 | import { repoDir } from "../../git/repos.ts"; | |
| 12 | import type { Ctx } from "../../http/context.ts"; | |
| 13 | import { html, type Html } from "../html.ts"; | |
| 14 | import { page } from "../layout.ts"; | |
| 15 | import { card, empty, time } from "../ui.ts"; | |
| 16 | ||
| 17 | export const CHANGELOG_LIMIT = 30; | |
| 18 | ||
| 19 | export interface ReleasePull { | |
| 20 | readonly number: number; | |
| 21 | readonly title: string; | |
| 22 | } | |
| 23 | export interface ReleaseEntry { | |
| 24 | readonly version: string; | |
| 25 | readonly date: string; | |
| 26 | readonly pulls: readonly ReleasePull[]; | |
| 27 | } | |
| 28 | ||
| 29 | const SUBJECT = /^Release (\d+(?:\.\d+)*[0-9A-Za-z.+-]*): ?(.*)$/; | |
| 30 | const PULL = /\s*(.*?)\s*\(#(\d+)\)\s*(?:;|$)/gy; | |
| 31 | ||
| 32 | /** `Release 0.7.9: a (#1);b (#2)` → version and its pulls; anything else → undefined. */ | |
| 33 | export function parseRelease(subject: string, date: string): ReleaseEntry | undefined { | |
| 34 | const m = SUBJECT.exec(subject); | |
| 35 | if (m === null) return undefined; | |
| 36 | const pulls: ReleasePull[] = []; | |
| 37 | PULL.lastIndex = 0; | |
| 38 | for (let p = PULL.exec(m[2]!); p !== null; p = PULL.exec(m[2]!)) { | |
| 39 | pulls.push({ number: Number(p[2]), title: p[1]! }); | |
| 40 | } | |
| 41 | return { version: m[1]!, date, pulls }; | |
| 42 | } | |
| 43 | ||
| 44 | const cache = new Map<string, { oid: string; entries: ReleaseEntry[] }>(); | |
| 45 | ||
| 46 | /** The newest releases on `branch`, read once per head oid. */ | |
| 47 | export async function readChangelog(dir: string, branch: string): Promise<ReleaseEntry[]> { | |
| 48 | const head = await runGit(["rev-parse", "--verify", "-q", `refs/heads/${branch}`], { cwd: dir }); | |
| 49 | if (!head.ok) return []; | |
| 50 | const cached = cache.get(dir); | |
| 51 | if (cached?.oid === head.value) return cached.entries; | |
| 52 | const log = await runGit( | |
| 53 | [ | |
| 54 | "log", | |
| 55 | "--extended-regexp", | |
| 56 | "--grep=^Release [0-9]", | |
| 57 | `-n${CHANGELOG_LIMIT}`, | |
| 58 | "--format=%cI%x1f%s%x1e", | |
| 59 | head.value, | |
| 60 | ], | |
| 61 | { cwd: dir }, | |
| 62 | ); | |
| 63 | if (!log.ok) return []; | |
| 64 | const entries: ReleaseEntry[] = []; | |
| 65 | for (const record of log.value.split("\x1e")) { | |
| 66 | const [date, subject] = record.trim().split("\x1f"); | |
| 67 | const entry = date === undefined || subject === undefined ? undefined : parseRelease(subject, date); | |
| 68 | if (entry !== undefined) entries.push(entry); | |
| 69 | } | |
| 70 | cache.set(dir, { oid: head.value, entries }); | |
| 71 | return entries; | |
| 72 | } | |
| 73 | ||
| 74 | // GET /changelog | |
| 75 | export async function changelogPage(ctx: Ctx): Promise<Response> { | |
| 76 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 77 | const [owner = "", name = ""] = (ctx.app.config.forgeRepo ?? "").split("/"); | |
| 78 | const repo = owner === "" || name === "" ? undefined : getRepo(ctx.app.db, owner, name); | |
| 79 | const shown = repo !== undefined && repo.visibility === "public" ? repo : undefined; | |
| 80 | const entries = shown === undefined | |
| 81 | ? [] | |
| 82 | : await timePhaseAsync(ctx.request, "releases", () => | |
| 83 | readChangelog(repoDir(ctx.app.reposRoot, shown.ownerName, shown.name), shown.defaultBranch), | |
| 84 | ); | |
| 85 | const rendering = performance.now(); | |
| 86 | const sections: Html[] = entries.map( | |
| 87 | (e) => html`<section class="changelog-release"> | |
| 88 | <h2 id="${e.version}"><a href="#${e.version}">${e.version}</a> <small class="muted">${time(e.date)}</small></h2> | |
| 89 | <ul> | |
| 90 | ${e.pulls.map( | |
| 91 | (p) => html`<li><a href="/${owner}/${name}/pulls/${p.number}">${p.title} (#${p.number})</a></li>`, | |
| 92 | )} | |
| 93 | </ul> | |
| 94 | </section>`, | |
| 95 | ); | |
| 96 | const body = html`<div class="page-head"><h1>Changelog</h1></div>${entries.length === 0 | |
| 97 | ? empty({ title: "No releases yet", note: "Each release lands here with its pulls." }) | |
| 98 | : card(html`${sections}`)}`; | |
| 99 | const response = page({ ctx, title: "Changelog", body }); | |
| 100 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 101 | return response; | |
| 102 | } |
test/changelog.test.ts added +104
| @@ -0,0 +1,104 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createUser, type User } from "../src/core/users.ts"; | |
| 8 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 9 | import { parseRelease } from "../src/web/pages/changelog.ts"; | |
| 10 | ||
| 11 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 12 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 13 | return r.value; | |
| 14 | }; | |
| 15 | ||
| 16 | describe("parseRelease", () => { | |
| 17 | test("reads the version and each pull", () => { | |
| 18 | const e = parseRelease("Release 0.7.9: Fix a; b (#12);Other thing (#13)", "2026-01-01T00:00:00Z"); | |
| 19 | expect(e?.version).toBe("0.7.9"); | |
| 20 | expect(e?.pulls).toEqual([ | |
| 21 | { number: 12, title: "Fix a; b" }, | |
| 22 | { number: 13, title: "Other thing" }, | |
| 23 | ]); | |
| 24 | }); | |
| 25 | test("a subject that is not a release is nothing", () => { | |
| 26 | expect(parseRelease("Fix Release 1.0: x (#1)", "2026-01-01T00:00:00Z")).toBeUndefined(); | |
| 27 | }); | |
| 28 | }); | |
| 29 | ||
| 30 | describe("changelog page", () => { | |
| 31 | let dataDir: string; | |
| 32 | let app: App; | |
| 33 | let servers: Servers; | |
| 34 | let alice: User; | |
| 35 | ||
| 36 | const commit = async (repo: Awaited<ReturnType<typeof createRepo>> extends infer R ? (R extends { ok: true; value: infer V } ? V : never) : never, message: string, n: number) => | |
| 37 | must(await commitToBranch(app, alice, repo, { message, files: [{ path: `f${n}.txt`, content: `${n}\n` }] })); | |
| 38 | ||
| 39 | beforeAll(async () => { | |
| 40 | dataDir = await mkdtemp(join(tmpdir(), "forge-changelog-")); | |
| 41 | app = createApp({ dataDir, port: 0 }); | |
| 42 | servers = await serve(app); | |
| 43 | alice = must( | |
| 44 | await createUser(app.db, { | |
| 45 | origin: "seed", | |
| 46 | trusted: true, | |
| 47 | username: "alice", | |
| 48 | email: "[email protected]", | |
| 49 | password: "a-good-passphrase", | |
| 50 | adminIfFirst: true, | |
| 51 | }), | |
| 52 | ); | |
| 53 | const repo = must(await createRepo(app, alice, { name: "forge", visibility: "public" })); | |
| 54 | app.config.forgeRepo = "alice/forge"; | |
| 55 | await commit(repo, "Release 0.1.0: First <b>thing</b> (#1)", 1); | |
| 56 | await commit(repo, "unrelated work", 2); | |
| 57 | await commit(repo, "Release 0.2.0: Second (#2);Third (#3)", 3); | |
| 58 | await commit(repo, "Release 0.3.0: Fourth (#4)", 4); | |
| 59 | }, 60_000); | |
| 60 | ||
| 61 | afterAll(async () => { | |
| 62 | servers.stop(); | |
| 63 | app.close(); | |
| 64 | await rm(dataDir, { recursive: true, force: true }); | |
| 65 | }); | |
| 66 | ||
| 67 | test("lists releases newest first with anchors, dates and escaped pull links, to anyone", async () => { | |
| 68 | const res = await fetch(`${servers.url}/changelog`); | |
| 69 | expect(res.status).toBe(200); | |
| 70 | expect(res.headers.get("server-timing")).toContain("releases"); | |
| 71 | const body = await res.text(); | |
| 72 | const at = (s: string) => body.indexOf(s); | |
| 73 | expect(at('id="0.3.0"')).toBeGreaterThan(-1); | |
| 74 | expect(at('id="0.3.0"')).toBeLessThan(at('id="0.2.0"')); | |
| 75 | expect(at('id="0.2.0"')).toBeLessThan(at('id="0.1.0"')); | |
| 76 | expect(body).toContain('href="/alice/forge/pulls/2"'); | |
| 77 | expect(body).toContain('href="/alice/forge/pulls/3"'); | |
| 78 | expect(body).toContain("<time"); | |
| 79 | expect(body).toContain("First <b>thing</b>"); | |
| 80 | expect(body).not.toContain("<b>thing</b>"); | |
| 81 | expect(body).not.toContain("unrelated work"); | |
| 82 | }); | |
| 83 | ||
| 84 | test("the footer links to it", async () => { | |
| 85 | const body = await (await fetch(`${servers.url}/changelog`)).text(); | |
| 86 | expect(body).toContain('href="/changelog"'); | |
| 87 | }); | |
| 88 | ||
| 89 | test("with no forge repository it answers 200 and says there are no releases", async () => { | |
| 90 | const kept = app.config.forgeRepo; | |
| 91 | delete app.config.forgeRepo; | |
| 92 | const res = await fetch(`${servers.url}/changelog`); | |
| 93 | if (kept !== undefined) app.config.forgeRepo = kept; | |
| 94 | expect(res.status).toBe(200); | |
| 95 | expect(await res.text()).toContain("No releases yet"); | |
| 96 | }); | |
| 97 | ||
| 98 | test("a new release shows after the head moves", async () => { | |
| 99 | const repo = must((await import("../src/core/repos.ts")).getRepo(app.db, "alice", "forge") ? { ok: true as const, value: (await import("../src/core/repos.ts")).getRepo(app.db, "alice", "forge")! } : { ok: false as const, error: "gone" }); | |
| 100 | await commit(repo, "Release 0.4.0: Fifth (#5)", 5); | |
| 101 | const body = await (await fetch(`${servers.url}/changelog`)).text(); | |
| 102 | expect(body.indexOf('id="0.4.0"')).toBeGreaterThan(-1); | |
| 103 | }); | |
| 104 | }); |
new above
offline