Public: anyone can read this; the crew can change it.

A fork's offers to upstream are listed on its page newest first with each one's state #15884

Merged opened this

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

Merged

scout/forge:scout/15859-a-fork-s-offers-to-upstream-are-listed-o → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/15859-a-fork-s-offers-to-upstream-are-listed-o was merged into main as 2b12672.

Review

Sign in to review this change.
4 files changed +141 −6
docs/features/fork-offers-sent.md +1 −1
@@ -6,7 +6,7 @@ row: A fork lists the offers it sent upstream, and where each stands
66
77 A fork's page shows what it has offered its upstream, so the maker sees where each offer stands without asking.
88
9 - **Page:** the fork's home has a "Sent upstream" section: up to 20 pulls into the parent whose head is this fork, newest first, each with title, state and age, linking to the pull. The state is `waiting` (open), `taken` (merged) or `declined` (closed without a merge). No offers, or an upstream the viewer cannot read, shows nothing.
9 - **Page:** the fork's home has a "Sent upstream" section: up to 20 pulls into the parent whose head is this fork, newest first, each with title, state and age, linking to the pull. The state is `waiting` (open), `taken` (merged) or `declined` (closed without a merge). No offers, or an upstream the viewer cannot read, shows nothing. The heading links to `/<fork>/offers`, the same list as a page of its own (the sub line says what it is for); it says "Nothing offered yet" when empty and answers 404 for a repository that is not a fork.
1010 - **Terminal:** the fork's forks screen has one `sent #N title` row per offer, with the state and age; Enter opens the pull.
1111
1212 The rule is `sentOffers` in `src/core/fork_offers.ts`.
src/http/server.ts +2
@@ -238,6 +238,7 @@ import {
238238 branchDelete,
239239 branchesPage,
240240 } from "../web/pages/branches.ts";
241 import { sentOffersPage } from "../web/pages/fork-offers.ts";
241242 import { offerCommitPost, offerPullPost, offerWithdrawPost } from "../web/pages/offer-upstream.ts";
242243 import { offerReceiptPage } from "../web/pages/offer-receipt.ts";
243244 import { iterationsPage, noteSubmit } from "../web/pages/iterations.ts";
@@ -1736,6 +1737,7 @@ export function buildRouter(): Router<Handler> {
17361737 router.add("POST", "/:owner/:name/branches", branchCreate);
17371738 router.add("POST", "/:owner/:name/commit/:oid/offer", offerCommitPost);
17381739 router.add("POST", "/:owner/:name/pulls/:number/offer", offerPullPost);
1740 router.add("GET", "/:owner/:name/offers", sentOffersPage);
17391741 router.add("POST", "/:owner/:name/offers/:number/withdraw", offerWithdrawPost);
17401742 router.add("POST", "/:owner/:name/branches/:branch/delete", branchDelete);
17411743
src/web/pages/fork-offers.ts +36 −5
@@ -1,11 +1,14 @@
11 /** The upstream's home: open offers from forks, one line each (#13403). */
22
3 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
34 import { agoWords } from "../../actions/follow_words.ts";
4 import type { ForkOffer, SentOffer } from "../../core/fork_offers.ts";
5 import type { Repo } from "../../core/repos.ts";
5 import { sentOffers, type ForkOffer, type SentOffer } from "../../core/fork_offers.ts";
6 import { forkParentFor, type Repo } from "../../core/repos.ts";
7 import type { Ctx } from "../../http/context.ts";
68 import { sizeLine, type OfferSizeResult } from "../../git/offer_size.ts";
7 import { repoBase } from "../chrome.ts";
9 import { loadRepo, notFoundPage, pageHead, repoBase } from "../chrome.ts";
810 import { html, type Html } from "../html.ts";
11 import { page } from "../layout.ts";
912 import { confirmAction, time } from "../ui.ts";
1013
1114 export function forkOffersCard(repo: Pick<Repo, "ownerName" | "name">, offers: readonly ForkOffer[], sizes: ReadonlyMap<number, OfferSizeResult> = new Map()): Html | null {
@@ -35,10 +38,12 @@ export function sentOffersCard(
3538 fork: Pick<Repo, "ownerName" | "name">,
3639 parent: Pick<Repo, "ownerName" | "name">,
3740 offers: readonly SentOffer[],
41 /** On a fork's home the heading links to the full page; on that page itself there is none. */
42 heading: boolean = true,
3843 ): Html | null {
3944 if (offers.length === 0) return null;
40 return html`<section aria-labelledby="sent-offers-h">
41 <h2 id="sent-offers-h">Sent upstream</h2>
45 return html`<section ${heading ? html`aria-labelledby="sent-offers-h"` : html`aria-label="Sent upstream"`}>
46 ${heading ? html`<h2 id="sent-offers-h"><a href="${repoBase(fork)}/offers">Sent upstream</a></h2>` : null}

Add tests for this. Assert the fork home links /<fork>/offers from the 'Sent upstream' heading, and that /<fork>/offers has no <h2 and keeps the aria-label. Neither is asserted in test/fork-offers-list.test.ts, so reverting either change would pass.

4247 <ul class="list">${offers.map(
4348 (o) => html`<li>
4449 <a class="row" href="${repoBase(parent)}/pulls/${o.number}"
@@ -49,3 +54,29 @@ export function sentOffersCard(
4954 )}</ul>
5055 </section>`;
5156 }
57
58 // GET /:owner/:name/offers — everything this fork has offered upstream, newest first, up to 20.
59 export function sentOffersPage(ctx: Ctx): Response {
60 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
61 const fork = loadRepo(ctx);
62 if (!fork) return notFoundPage(ctx);
63 const rendering = performance.now();
64 // Not a fork: a plain page saying so, which names its render like every page.
65 const named = (response: Response): Response => {
66 notePhase(ctx.request, "render", performance.now() - rendering);
67 return response;
68 };
69 if (fork.forkParentId === null)
70 return named(page({ ctx, title: "Offers", body: html`<div class="narrow-wide">${pageHead("Offers", { sub: `${fork.ownerName}/${fork.name} is not a fork, so it has nothing to offer upstream.` })}</div>` }, 404));
71 const parent = forkParentFor(ctx.app.db, fork, ctx.auth.user);
72 const offers = parent === undefined ? [] : sentOffers(ctx.app.db, fork, ctx.auth.user);
73 const list = parent === undefined ? null : sentOffersCard(fork, parent, offers, false);
74 return named(page({
75 ctx,
76 title: "Offers",
outdated

Principle 1: this sub line and the h2 Sent upstream inside sentOffersCard say the same thing. Drop one: let the page pass no heading to the card, or drop the sub.

77 body: html`<div class="narrow-wide">
outdated

Empty state is a bare muted p; fine, but the page has no link in from the fork home, so /offers is a URL only. Link it from the fork page.

78 ${pageHead("Offers", { sub: `What ${fork.ownerName}/${fork.name} has sent upstream, newest first.` })}
79 ${list ?? html`<p class="muted">Nothing offered yet</p>`}
80 </div>`,
81 }));
82 }
test/fork-offers-list.test.ts added +102
@@ -0,0 +1,102 @@
1 /**
2 * /<fork>/offers lists what the fork sent upstream, newest first, with each one's state (#15859).
3 */
4 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
5 import { mkdtemp, rm } from "node:fs/promises";
6 import { tmpdir } from "node:os";
7 import { join } from "node:path";
8 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
9 import { mergePull, openPull } from "../src/actions/pulls.ts";
10 import { setIssueState } from "../src/actions/issues.ts";
11 import { getIssue } from "../src/core/issues.ts";
12 import { getPull } from "../src/core/pulls.ts";
13 import { createApp, type App } from "../src/app.ts";
14 import { createUser, type User } from "../src/core/users.ts";
15 import { serve, type Servers } from "../src/http/server.ts";
16 import type { Repo } from "../src/core/repos.ts";
17 import { promote } from "./helpers/members.ts";
18
19 describe("fork offers page", () => {
20 let dir: string;
21 let app: App;
22 let servers: Servers;
23 let alice: User;
24 let bob: User;
25 let up: Repo;
26 let fork: Repo;
27
28 const offer = async (branch: string, title: string) => {
29 const pushed = await commitToBranch(app, bob, fork, { branch, message: title, files: [{ path: `${branch}.txt`, content: "x\n" }] });
30 if (!pushed.ok) throw new Error(JSON.stringify(pushed.error));
31 const pull = await openPull(app, bob, up, { title, baseBranch: "main", headBranch: branch, headRepo: fork });
32 if (!pull.ok) throw new Error(JSON.stringify(pull.error));
33 return pull.value;
34 };
35
36 beforeAll(async () => {
37 dir = await mkdtemp(join(tmpdir(), "forge-offers-list-"));
38 app = createApp({ dataDir: dir, port: 0 });
39 servers = await serve(app);
40 const mk = async (username: string, first: boolean) => {
41 const made = await createUser(app.db, {
42 origin: "seed", trusted: true, username, email: `${username}@forge.local`,
43 password: "a-good-passphrase", adminIfFirst: first,
44 });
45 if (!made.ok) throw new Error(made.error);
46 return made.value;
47 };
48 alice = await mk("alice", true);
49 bob = await mk("bob", false);
50 promote(app.db, bob);
51 const made = await createRepo(app, alice, { name: "lib", visibility: "public" });
52 if (!made.ok) throw new Error(String(made.error));
53 up = made.value;
54 const seeded = await commitToBranch(app, alice, up, { message: "Start", files: [{ path: "README.md", content: "# lib\n" }] });
55 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
56 const f = await forkRepo(app, bob, up, undefined, { visibility: "public" });
57 if (!f.ok) throw new Error(String(f.error));
58 fork = f.value;
59 });
60
61 afterAll(async () => {
62 servers.stop();
63 await rm(dir, { recursive: true, force: true });
64 });
65
66 test("nothing sent says so", async () => {
67 const res = await fetch(`${servers.url}/bob/lib/offers`);
68 expect(res.status).toBe(200);
69 expect(await res.text()).toContain("Nothing offered yet");
70 });
71
72 test("a repository that is not a fork has no offers page", async () => {
73 expect((await fetch(`${servers.url}/alice/lib/offers`)).status).toBe(404);
74 });
75
76 test("three offers in three states, newest first", async () => {
77 await offer("a", "Waits");
78 const t = await offer("b", "Taken one");
79 const d = await offer("c", "Declined one");
80 const landed = await mergePull(app, alice, up, getPull(app.db, up.id, t.number)!, "merge");
81 if (!landed.ok) throw new Error(JSON.stringify(landed.error));
82 const closed = setIssueState(app, alice, up, getIssue(app.db, up.id, d.number)!, "closed");
83 if (!closed.ok) throw new Error(JSON.stringify(closed.error));
84 const body = await (await fetch(`${servers.url}/bob/lib/offers`)).text();
85 expect(body).not.toContain("Nothing offered yet");
86 expect(body).toMatch(/Declined one[\s\S]*declined[\s\S]*Taken one[\s\S]*taken[\s\S]*Waits[\s\S]*waiting/);
87 });
88
89 test("the fork home's 'Sent upstream' heading links to the offers page", async () => {
90 const body = await (await fetch(`${servers.url}/bob/lib`)).text();
91 expect(body).toMatch(/<h2 id="sent-offers-h"><a href="\/bob\/lib\/offers">Sent upstream<\/a><\/h2>/);
92 });
93
94 test("the offers page has no second heading and keeps the list's label", async () => {
95 const body = await (await fetch(`${servers.url}/bob/lib/offers`)).text();
96 // Only the page's own content: the layout's shortcuts dialog carries an h2 of its own.
97 const main = body.slice(body.indexOf("<main"), body.indexOf("</main>"));
98 expect(main).toContain("Taken one");
99 expect(main).not.toContain("<h2");
100 expect(main).toContain('<section aria-label="Sent upstream">');
101 });
102 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs