Public: anyone can read this; the crew can change it.
A note's status says "Shipped in <release>", or "Shipped on <date>" until a release includes it #5392
scout/forge:scout/5221-a-note-s-status-says-shipped-in-release → main 1 commit fork
5 files
changed +111
−12
src/actions/app_notes.ts +42 −7
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | import type { App } from "../app.ts"; |
| 9 | 9 | import { banVisitor, bannedNotes, unbanVisitor, markSender, getNote, hideNote, insertNote, isBanned, notesOf, notesOfApp, type AppNote } from "../core/app_notes.ts"; |
| 10 | 10 | import type { AppRecord } from "../core/apps.ts"; |
| 11 | import { mergedPullsClosing } from "../core/pulls.ts"; | |
| 11 | 12 | import { createLabel, getIssue, getLabel } from "../core/issues.ts"; |
| 12 | 13 | import { RateLimiter } from "../core/ratelimit.ts"; |
| 13 | 14 | import { canAdmin, type Repo } from "../core/repos.ts"; |
| @@ -15,7 +16,9 @@ import { plainText } from "../core/reports.ts"; | ||
| 15 | 16 | import { workingAgentRuns } from "../core/runs.ts"; |
| 16 | 17 | import { getUserById, isActive, type User } from "../core/users.ts"; |
| 17 | 18 | import { unadoptedAmong } from "../crew/direct.ts"; |
| 19 | import { repoDir } from "../git/repos.ts"; | |
| 18 | 20 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 21 | import { readWaves } from "../story/waves.ts"; | |
| 19 | 22 | import { openIssueThrough, setIssueLabelsThrough, setIssueStateThrough } from "./issues.ts"; |
| 20 | 23 | |
| 21 | 24 | export const FROM_APP_LABEL = "from-app"; |
| @@ -94,15 +97,44 @@ export interface NoteView { | ||
| 94 | 97 | readonly url?: string; |
| 95 | 98 | } |
| 96 | 99 | |
| 100 | /** Pull number to the version of the wave that lists it (`waves/*.md` on the default branch). */ | |
| 101 | type Released = ReadonlyMap<number, string>; | |
| 102 | const PULL_URL = /\/pulls\/(\d+)\/?$/; | |
| 103 | ||
| 104 | async function releasedPulls(app: App, repo: Repo): Promise<Released> { | |
| 105 | const out = new Map<number, string>(); | |
| 106 | try { | |
| 107 | for (const e of await readWaves(repoDir(app.reposRoot, repo.ownerName, repo.name), repo.defaultBranch)) | |
| 108 | if (e.ok) | |
| 109 | for (const p of e.wave.pulls) { | |
| 110 | const n = Number(PULL_URL.exec(p.url)?.[1]); | |
| 111 | if (Number.isInteger(n) && !out.has(n)) out.set(n, e.wave.version); | |
| 112 | } | |
| 113 | } catch { | |
| 114 | // No readable repository: every merge reads as unreleased. | |
| 115 | } | |
| 116 | return out; | |
| 117 | } | |
| 118 | ||
| 119 | /** "Shipped in <version>" when a release lists the merged pull that closed the issue, else "Shipped on <date>". */ | |
| 120 | function shippedLabel(app: App, repo: Repo, number: number, closed: string, released: Released): string { | |
| 121 | const merges = mergedPullsClosing(app.db, repo.id, number); | |
| 122 | for (const m of merges) { | |
| 123 | const version = released.get(m.number); | |
| 124 | if (version !== undefined) return `Shipped in ${version}`; | |
| 125 | } | |
| 126 | return `Shipped on ${(merges[0]?.mergedAt ?? closed).slice(0, 10)}`; | |
| 127 | } | |
| 128 | ||
| 97 | 129 | /** Where a note stands, read from the issue as it moves. */ |
| 98 | export function statusOf(app: App, repo: Repo, number: number): { status: NoteStatus; title: string } | undefined { | |
| 130 | export function statusOf(app: App, repo: Repo, number: number, released: Released = new Map()): { status: NoteStatus; title: string } | undefined { | |
| 99 | 131 | const issue = getIssue(app.db, repo.id, number); |
| 100 | 132 | if (issue === undefined) return undefined; |
| 101 | 133 | if (issue.state === "closed") { |
| 102 | 134 | const when = (issue.closedAt ?? issue.updatedAt).slice(0, 10); |
| 103 | 135 | // Only "done" is a promise kept; the other reasons say what they are. |
| 104 | 136 | if (issue.closeReason === "done" || issue.closeReason === null) |
| 105 | return { title: issue.title, status: { state: "shipped", label: `Shipped on ${when}` } }; | |
| 137 | return { title: issue.title, status: { state: "shipped", label: shippedLabel(app, repo, number, issue.closedAt ?? issue.updatedAt, released) } }; | |
| 106 | 138 | const label = issue.closeReason === "parked" ? "Set aside for now" : issue.closeReason === "split" ? "Split into smaller pieces" : "Closed without a change"; |
| 107 | 139 | return { title: issue.title, status: { state: "closed", label: `${label} (${when})` } }; |
| 108 | 140 | } |
| @@ -117,8 +149,8 @@ export function statusOf(app: App, repo: Repo, number: number): { status: NoteSt | ||
| 117 | 149 | return { title: issue.title, status: { state: "queued", label: "In the queue for a builder" } }; |
| 118 | 150 | } |
| 119 | 151 | |
| 120 | function view(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, note: AppNote): NoteView | undefined { | |
| 121 | const found = statusOf(app, repo, note.issueNumber); | |
| 152 | function view(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, note: AppNote, released: Released): NoteView | undefined { | |
| 153 | const found = statusOf(app, repo, note.issueNumber, released); | |
| 122 | 154 | if (found === undefined) return undefined; |
| 123 | 155 | const open = forgeUrl !== undefined && record.access === "public" && repo.visibility === "public"; |
| 124 | 156 | return { |
| @@ -132,9 +164,12 @@ function view(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefi | ||
| 132 | 164 | } |
| 133 | 165 | |
| 134 | 166 | /** A sender's own notes; an admin of the repository may ask for every sender's. */ |
| 135 | export function notesFor(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, sender: Sender, everyone = false): NoteView[] { | |
| 167 | export async function notesFor(app: App, record: AppRecord, repo: Repo, forgeUrl: string | undefined, sender: Sender, everyone = false): Promise<NoteView[]> { | |
| 136 | 168 | const rows = everyone ? notesOfApp(app.db, record.id) : notesOf(app.db, record.id, sender.key); |
| 137 | return rows.map((n) => view(app, record, repo, forgeUrl, n)).filter((n): n is NoteView => n !== undefined); | |
| 169 | // The waves are read from git once per list, and only when a note could be shipped. | |
| 170 | const anyDone = rows.some((n) => getIssue(app.db, repo.id, n.issueNumber)?.state === "closed"); | |
| 171 | const released = anyDone ? await releasedPulls(app, repo) : new Map<number, string>(); | |
| 172 | return rows.map((n) => view(app, record, repo, forgeUrl, n, released)).filter((n): n is NoteView => n !== undefined); | |
| 138 | 173 | } |
| 139 | 174 | |
| 140 | 175 | /** The longest run of backticks in `text`, so the fence can be longer. */ |
| @@ -231,7 +266,7 @@ export async function sendNote( | ||
| 231 | 266 | visitor: sender.key, |
| 232 | 267 | name: sender.name, |
| 233 | 268 | }); |
| 234 | return ok(view(app, record, repo, forgeUrl, note)!); | |
| 269 | return ok(view(app, record, repo, forgeUrl, note, new Map())!); | |
| 235 | 270 | } |
| 236 | 271 | |
| 237 | 272 | /** The owner's: hide a note (closing its issue), or ban its sender too. */ |
src/apps/feedback.ts +2 −2
| @@ -154,9 +154,9 @@ async function send(ask: FeedbackAsk, door: Door): Promise<Response> { | ||
| 154 | 154 | return json(201, { note: sent.value, name: sender.name }, cookies); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | function list(ask: FeedbackAsk, door: Door): Response { | |
| 157 | async function list(ask: FeedbackAsk, door: Door): Promise<Response> { | |
| 158 | 158 | const { sender, fresh } = senderOf(ask, door); |
| 159 | const notes = notesFor(ask.app, ask.record, door.repo, ask.forgeUrl, sender); | |
| 159 | const notes = await notesFor(ask.app, ask.record, door.repo, ask.forgeUrl, sender); | |
| 160 | 160 | return json( |
| 161 | 161 | 200, |
| 162 | 162 | { name: sender.name, notes, admin: door.viewer !== undefined && canAdmin(ask.app.db, door.repo, door.viewer) }, |
src/core/pulls.ts +23
| @@ -1041,6 +1041,29 @@ export function openPullsClosing( | ||
| 1041 | 1041 | return out; |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | /** | |
| 1045 | * The merged pulls whose description closes issue `number`, newest merge | |
| 1046 | * first: `{ number, mergedAt }` each. The LIKE only narrows; the words are | |
| 1047 | * checked by `closesFromBody`. | |
| 1048 | */ | |
| 1049 | export function mergedPullsClosing( | |
| 1050 | db: Database, | |
| 1051 | repoId: string, | |
| 1052 | number: number, | |
| 1053 | ): { number: number; mergedAt: string }[] { | |
| 1054 | const rows = db | |
| 1055 | .query<{ number: number; body: string; merged_at: string }, [string, string]>( | |
| 1056 | `SELECT issue.number, issue.body, pull.merged_at FROM pull | |
| 1057 | JOIN issue ON issue.id = pull.issue_id | |
| 1058 | WHERE issue.repo_id = ?1 AND pull.merged_at IS NOT NULL AND issue.body LIKE ?2 | |
| 1059 | ORDER BY pull.merged_at DESC LIMIT 50`, | |
| 1060 | ) | |
| 1061 | .all(repoId, `%#${number}%`); | |
| 1062 | return rows | |
| 1063 | .filter((r) => closesFromBody(r.body).includes(number)) | |
| 1064 | .map((r) => ({ number: r.number, mergedAt: r.merged_at })); | |
| 1065 | } | |
| 1066 | ||
| 1044 | 1067 | /** |
| 1045 | 1068 | * The person whose words a pull answers: the author of the issue it closes |
| 1046 | 1069 | * (or continues), when that is a person. Derived from the body and the issue |
src/tui/screens/notes.ts +2 −1
| @@ -83,7 +83,7 @@ export function noteCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 83 | 83 | title: `${name} — Notes from the app`, |
| 84 | 84 | hint: admin ? "every sender's; hide or ban" : "yours, with their status", |
| 85 | 85 | run: () => { |
| 86 | const notes = notesFor(f.app, record, repo, undefined, sender, admin); | |
| 86 | void notesFor(f.app, record, repo, undefined, sender, admin).then((notes) => { | |
| 87 | 87 | if (notes.length === 0) return ctx.toast("No notes yet."); |
| 88 | 88 | ctx.push( |
| 89 | 89 | pickerScreen(ctx, parent(), { |
| @@ -109,6 +109,7 @@ export function noteCommands(f: Session, ctx: Ctx, parent: () => Screen, repo: R | ||
| 109 | 109 | }, |
| 110 | 110 | }), |
| 111 | 111 | ); |
| 112 | }); | |
| 112 | 113 | }, |
| 113 | 114 | }, |
| 114 | 115 | ...unban, |
test/apps-feedback.test.ts +42 −2
| @@ -15,9 +15,11 @@ import { toolbarJs } from "../src/apps/toolbar.ts"; | ||
| 15 | 15 | import { filtered, moderateNote, noteClock, PER_APP_DAY, PER_SENDER, PER_SOURCE, saysFromApp } from "../src/actions/app_notes.ts"; |
| 16 | 16 | import { feedback, REQUEST_MAX } from "../src/apps/feedback.ts"; |
| 17 | 17 | import { getAppBySlug } from "../src/core/apps.ts"; |
| 18 | import { getNote, isBanned } from "../src/core/app_notes.ts"; | |
| 18 | import { getNote, insertNote, isBanned } from "../src/core/app_notes.ts"; | |
| 19 | 19 | import { grantedCookie } from "./helpers/identity.ts"; |
| 20 | import { getIssue, labelsFor, setIssueState } from "../src/core/issues.ts"; | |
| 20 | import { createIssue, getIssue, labelsFor, setIssueState } from "../src/core/issues.ts"; | |
| 21 | import { commitToBranch } from "../src/actions/repos.ts"; | |
| 22 | import { writeWave } from "../src/story/wave.ts"; | |
| 21 | 23 | import { getRepo } from "../src/core/repos.ts"; |
| 22 | 24 | import { createUser, type User } from "../src/core/users.ts"; |
| 23 | 25 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -128,6 +130,44 @@ describe("the forge button takes notes from anyone", () => { | ||
| 128 | 130 | expect(other.notes).toEqual([]); |
| 129 | 131 | }); |
| 130 | 132 | |
| 133 | test("a shipped note names the release that lists its pull, or the day it merged", async () => { | |
| 134 | const repo = getRepo(app.db, "alice", "notes")!; | |
| 135 | const shipped = async (ask: string, ip: string, pullBody: string, mergedAt: string) => { | |
| 136 | // Filed straight in, so the app's per-minute bound is left to the tests after this one. | |
| 137 | const value = ip.replace(/\D/g, "").padEnd(32, "c"); | |
| 138 | const cookie = `forge_visitor=${value}`; | |
| 139 | const filed = createIssue(app.db, { repoId: repo.id, authorId: alice.id, title: `From the app: ${ask}` }); | |
| 140 | if (!filed.ok) throw new Error(String(filed.error)); | |
| 141 | const n = filed.value.number; | |
| 142 | insertNote(app.db, { appId: getAppBySlug(app.db, "notes")!.id, repoId: repo.id, issueNumber: n, visitor: `v:${value}`, name: "visitor-x" }); | |
| 143 | const made = createIssue(app.db, { repoId: repo.id, authorId: alice.id, title: `Fix ${ask}`, body: pullBody.replace("N", String(n)), kind: "pull" }); | |
| 144 | if (!made.ok) throw new Error(String(made.error)); | |
| 145 | const pull = made.value; | |
| 146 | app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', 'x', 'a', 'b', ?2)").run(pull.id, mergedAt); | |
| 147 | setIssueState(app.db, getIssue(app.db, repo.id, n)!.id, "closed", "done"); | |
| 148 | return { cookie, pull: pull.number }; | |
| 149 | }; | |
| 150 | const unreleased = await shipped("not in a wave", "10.7.0.1", "Closes #N", "2026-09-03T10:00:00.000Z"); | |
| 151 | const released = await shipped("in a wave", "10.7.0.2", "Fixes #N", "2026-09-04T10:00:00.000Z"); | |
| 152 | const label = async (cookie: string) => | |
| 153 | ((await (await at("notes", "/__forge/notes", {}, cookie)).json()) as { notes: { status: { label: string } }[] }).notes[0]!.status.label; | |
| 154 | // No wave lists either yet. | |
| 155 | expect(await label(unreleased.cookie)).toBe("Shipped on 2026-09-03"); | |
| 156 | expect(await label(released.cookie)).toBe("Shipped on 2026-09-04"); | |
| 157 | const wave = writeWave({ | |
| 158 | version: "1.2.3", | |
| 159 | date: "2026-09-05", | |
| 160 | headline: "h", | |
| 161 | highlights: [1, 2, 3].map((i) => ({ title: `t${i}`, why: "w" })), | |
| 162 | pulls: [{ title: `#${released.pull} Fix`, url: `https://f.test/alice/notes/pulls/${released.pull}` }], | |
| 163 | }); | |
| 164 | if (!wave.ok) throw wave.error; | |
| 165 | const put = await commitToBranch(app, alice, repo, { message: "wave", files: [{ path: "waves/1.2.3.md", content: wave.value }] }); | |
| 166 | expect(put.ok).toBe(true); | |
| 167 | expect(await label(released.cookie)).toBe("Shipped in 1.2.3"); | |
| 168 | expect(await label(unreleased.cookie)).toBe("Shipped on 2026-09-03"); | |
| 169 | }); | |
| 170 | ||
| 131 | 171 | test("only a finished note reads as shipped; the others say what they are", async () => { |
| 132 | 172 | const repo = getRepo(app.db, "alice", "notes")!; |
| 133 | 173 | for (const [reason, label] of [["dropped", /^Closed without a change/], ["parked", /^Set aside/], ["split", /^Split into/], ["done", /^Shipped on/]] as const) { |
new above
offline