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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12553-a-pull-reading-says-approval-moved-in-on → main 0 commits fork

  • Merged. scout/12553-a-pull-reading-says-approval-moved-in-on was merged into main as f788d21.

Review

Sign in to review this change.
4 files changed +29 −1
src/contract/openapi/routes/getApiV1ReposOwnerNamePullsNumber.ts +1 −1
@@ -1,3 +1,3 @@
11 import { REPO, type Route } from "../shared.ts";
22
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(
2626 if (approval === null) return false;
2727 return baseOid === undefined || baseOid === "" ? approval.head !== headOid : !approval.current;
2828 }
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 @@
77 * the rules live in `actions/pulls.ts` and its neighbours.
88 */
99
10 import { approvedAgainst } from "../../core/approval_at.ts";
1011 import { reviewsDemanded } from "../../crew/review.ts";
1112 import { pullWaitsFor } from "../../flow/waits_for.ts";
1213 import { parseAttestation } from "../../core/attestation.ts";
@@ -400,6 +401,8 @@ export function pullRoutes(router: Router<Handler>): void {
400401 // The approval and what it was given for; `current` is false once the head or the base
401402 // moved.
402403 approvedAt: status.reviews?.approval ?? null,
404 // The same approval as one line, "<head7> against <base7>" (null with none).
405 approvedAgainst: approvedAgainst(status.reviews?.approval),
403406 variantSiblings: variantSiblings(ctx.app.db, [found.pull])[0] ?? [],
404407 ...(live ? { mergeable: status.mergeable, conflicts: status.conflicts } : {}),
405408 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", () => {
7474 };
7575 const row = () => askLinesFor(app.db, alice).find((r) => r.items.includes(`look:${pull.id}`));
7676 /** 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;
7780 const asks = async () => (await http.handle(new Request("http://forge.test/live/on-you", { headers: { cookie } }))).text();
7881
7982 beforeAll(async () => {
@@ -117,6 +120,11 @@ describe("the inbox row of an approved pull", () => {
117120 expect(row()?.line).toBe(`lib: "Feat" is green, waiting for your look`);
118121 expect(await asks()).toContain("ready for a look");
119122 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;
120128 });
121129
122130 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", () => {
125133 await sweepStaleAsks(app);
126134 expect(row()?.line).toBe(`lib: "Feat" is green, waiting for your look, moved since approval`);
127135 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);
128141 }, 60_000);
129142 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs