Public: anyone can read this; the crew can change it.
A pull reading says approval moved in one string: approvedAt reads "head against base" beside the object it carries now #16761
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/12553-a-pull-reading-says-approval-moved-in-on → main 0 commits fork
4 files
changed +29
−1
src/contract/openapi/routes/getApiV1ReposOwnerNamePullsNumber.ts +1 −1
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | import { REPO, type Route } from "../shared.ts"; |
| 2 | 2 | |
| 3 | export const route: Route = { method: "get", path: `${REPO}/pulls/{number}`, summary: "Read one pull with its diff and review gate", detail: "Read one pull with its diff and review gate (diff=0 leaves the diff out); `check` is the word for the head's check: green, red, running or none; `checkedAgainst` is the base tip that check merged with (null before one recorded it), `checkStale` says the base has moved since, and `approvedAt` is the standing approval {at, head, base, current} or null, current false once the head or the base moved; `waitsFor` is {cause, says, action, line} for an open pull green and unlanded over six hours, else null; the 200 carries a weak etag of the exact body, cache-control private, no-cache and vary authorization, cookie, and a repeat sending If-None-Match gets 304 with no body and the same etag until the head, a check verdict, a review or the state changes", auth: false, role: "anonymous", alsoStatus: [304], query: { diff: "string" }, reply: { check: "string", checkedAgainst: "string", approvedAt: "object", waitsFor: "object" }, refuses: [404] }; | |
| 3 | export const route: Route = { method: "get", path: `${REPO}/pulls/{number}`, summary: "Read one pull with its diff and review gate", detail: "Read one pull with its diff and review gate (diff=0 leaves the diff out); `check` is the word for the head's check: green, red, running or none; `checkedAgainst` is the base tip that check merged with (null before one recorded it), `checkStale` says the base has moved since, and `approvedAt` is the standing approval {at, head, base, current} or null, current false once the head or the base moved, and `approvedAgainst` is the same approval as one string, \"<head7> against <base7>\" (the head alone for an approval from before bases were recorded, null with none); `waitsFor` is {cause, says, action, line} for an open pull green and unlanded over six hours, else null; the 200 carries a weak etag of the exact body, cache-control private, no-cache and vary authorization, cookie, and a repeat sending If-None-Match gets 304 with no body and the same etag until the head, a check verdict, a review or the state changes", auth: false, role: "anonymous", alsoStatus: [304], query: { diff: "string" }, reply: { check: "string", checkedAgainst: "string", approvedAt: "object", approvedAgainst: "string", waitsFor: "object" }, refuses: [404] }; |
src/core/approval_at.ts +12
| @@ -26,3 +26,15 @@ export function movedSinceApproval( | ||
| 26 | 26 | if (approval === null) return false; |
| 27 | 27 | return baseOid === undefined || baseOid === "" ? approval.head !== headOid : !approval.current; |
| 28 | 28 | } |
| 29 | ||
| 30 | /** | |
| 31 | * The approval in one string, "<head7> against <base7>": what it was given | |
| 32 | * for, readable in a line. An approval from before bases were recorded names | |
| 33 | * its head alone; no approval is null. `approvedAt` carries the same facts as | |
| 34 | * an object; this is the form for a line of text. | |
| 35 | */ | |
| 36 | export function approvedAgainst(approval: { head: string; base: string | null } | null | undefined): string | null { | |
| 37 | if (!approval) return null; | |
| 38 | const head = approval.head.slice(0, 7); | |
| 39 | return approval.base ? `${head} against ${approval.base.slice(0, 7)}` : head; | |
| 40 | } |
src/http/api/pulls.ts +3
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * the rules live in `actions/pulls.ts` and its neighbours. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { approvedAgainst } from "../../core/approval_at.ts"; | |
| 10 | 11 | import { reviewsDemanded } from "../../crew/review.ts"; |
| 11 | 12 | import { pullWaitsFor } from "../../flow/waits_for.ts"; |
| 12 | 13 | import { parseAttestation } from "../../core/attestation.ts"; |
| @@ -400,6 +401,8 @@ export function pullRoutes(router: Router<Handler>): void { | ||
| 400 | 401 | // The approval and what it was given for; `current` is false once the head or the base |
| 401 | 402 | // moved. |
| 402 | 403 | approvedAt: status.reviews?.approval ?? null, |
| 404 | // The same approval as one line, "<head7> against <base7>" (null with none). | |
| 405 | approvedAgainst: approvedAgainst(status.reviews?.approval), | |
| 403 | 406 | variantSiblings: variantSiblings(ctx.app.db, [found.pull])[0] ?? [], |
| 404 | 407 | ...(live ? { mergeable: status.mergeable, conflicts: status.conflicts } : {}), |
| 405 | 408 | proposal: pullProposalOf(ctx.app.db, found.pull.id) ?? null, |
test/approval-moved-inbox.test.ts +13
| @@ -74,6 +74,9 @@ describe("the inbox row of an approved pull", () => { | ||
| 74 | 74 | }; |
| 75 | 75 | const row = () => askLinesFor(app.db, alice).find((r) => r.items.includes(`look:${pull.id}`)); |
| 76 | 76 | /** The asks page: the inbox, where each ask is drawn with its short line. */ |
| 77 | let againstThen = ""; | |
| 78 | const readPull = async () => | |
| 79 | (await (await http.handle(new Request(`http://forge.test/api/v1/repos/alice/lib/pulls/${pull.number}?diff=0`))).json()) as any; | |
| 77 | 80 | const asks = async () => (await http.handle(new Request("http://forge.test/live/on-you", { headers: { cookie } }))).text(); |
| 78 | 81 | |
| 79 | 82 | beforeAll(async () => { |
| @@ -117,6 +120,11 @@ describe("the inbox row of an approved pull", () => { | ||
| 117 | 120 | expect(row()?.line).toBe(`lib: "Feat" is green, waiting for your look`); |
| 118 | 121 | expect(await asks()).toContain("ready for a look"); |
| 119 | 122 | expect(await asks()).not.toContain("moved since approval"); |
| 123 | const body = await readPull(); | |
| 124 | expect(body.approvedAgainst).toBe(`${pull.headOid.slice(0, 7)} against ${(await mainTip()).slice(0, 7)}`); | |
| 125 | expect(body.approvedAt.current).toBe(true); | |
| 126 | expect(body.approvedAt.head.slice(0, 7)).toBe(pull.headOid.slice(0, 7)); | |
| 127 | againstThen = body.approvedAgainst; | |
| 120 | 128 | }); |
| 121 | 129 | |
| 122 | 130 | test("the base moves and the pull is checked green again: the row says moved since approval", async () => { |
| @@ -125,5 +133,10 @@ describe("the inbox row of an approved pull", () => { | ||
| 125 | 133 | await sweepStaleAsks(app); |
| 126 | 134 | expect(row()?.line).toBe(`lib: "Feat" is green, waiting for your look, moved since approval`); |
| 127 | 135 | expect(await asks()).toContain("moved since approval"); |
| 136 | const body = await readPull(); | |
| 137 | expect(body.approvedAgainst).toBe(againstThen); // the approval is what it was | |
| 138 | expect(body.approvedAgainst).not.toContain(`against ${(await mainTip()).slice(0, 7)}`); | |
| 139 | expect(body.approvedAt.current).toBe(false); | |
| 140 | expect(body.approvedAt.head).toBe(pull.headOid); | |
| 128 | 141 | }, 60_000); |
| 129 | 142 | }); |
new above
offline