diff --git a/plugins/stewards/app.test.tsx b/plugins/stewards/app.test.tsx index 6468f3b6..032aaa93 100644 --- a/plugins/stewards/app.test.tsx +++ b/plugins/stewards/app.test.tsx @@ -12,6 +12,7 @@ type Need = { key: string; kind: string; url: string | null; + entityUrl: string | null; escalationId: string | null; choices: string[]; lessonId: string | null; @@ -40,6 +41,7 @@ const need = (over: Partial = {}): Need => ({ key: "ENG-12", kind: "decide", url: null, + entityUrl: null, escalationId: null, choices: [], lessonId: null, @@ -147,3 +149,33 @@ describe("the Stewards page's decide items and questions (BB-20)", () => { slot.lifecycle.unmount(); }); }); + +// BB-29: an approve-pr or merge card links the pull request separately, while +// the entity key keeps opening the binding's ticket. +describe("the Stewards page's need links (BB-29)", () => { + const pr = "https://github.com/bitcomplete/bb-gate/pull/17"; + const ticket = "https://linear.app/bit-complete/issue/BB-28"; + + it("links the key to the ticket and offers Open the pull request for approve-pr and merge", async () => { + const slot = await renderBoard( + [ + need({ kind: "approve-pr", key: "BB-28", url: pr, entityUrl: ticket, what: "Approve bitcomplete/bb-gate#17 on GitHub" }), + need({ id: "need_2", kind: "merge", key: "BB-29", url: pr, entityUrl: "https://linear.app/bit-complete/issue/BB-29", what: "Merge bitcomplete/bb-gate#17" }), + ], + [], + ); + await waitFor(() => expect(slot.getAllByRole("button", { name: "Open the pull request" })).toHaveLength(2)); + fireEvent.click(slot.getByRole("button", { name: "BB-28" })); + fireEvent.click(slot.getAllByRole("button", { name: "Open the pull request" })[0]!); + await waitFor(() => expect(slot.inspection.navigateCalls).toContainEqual({ method: "openUrl", url: ticket })); + await waitFor(() => expect(slot.inspection.navigateCalls).toContainEqual({ method: "openUrl", url: pr })); + slot.lifecycle.unmount(); + }); + + it("shows no Open the pull request link for other kinds", async () => { + const slot = await renderBoard([need({ kind: "decide", url: ticket, entityUrl: ticket })], []); + await waitFor(() => expect(slot.getByRole("button", { name: "Answer" })).toBeTruthy()); + expect(slot.queryByRole("button", { name: "Open the pull request" })).toBeNull(); + slot.lifecycle.unmount(); + }); +}); diff --git a/plugins/stewards/app.tsx b/plugins/stewards/app.tsx index a97e52c0..fc82c2a7 100644 --- a/plugins/stewards/app.tsx +++ b/plugins/stewards/app.tsx @@ -587,10 +587,13 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now: // A lesson's Merge/Drop are its only choices: no free-text "Other…". const lesson = n.lessonId !== null; const freeText = choices.length === 0 || other; + // The entity link opens the binding's ticket; for approve-pr and merge the + // item's `url` is the pull request, so it gets its own link. + const prUrl = n.kind === "approve-pr" || n.kind === "merge" ? n.url : null; return (
  • - + {n.kind} asked {ago(n.createdAt, now)}

    @@ -658,6 +661,11 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now: )} {n.threadId !== null ? {n.kind === "provide-secret" ? "Open the requester" : "Open the worker"} : null} + {prUrl !== null ? ( + + ) : null} {typeof state === "object" ? {state.error} : null}
  • diff --git a/plugins/stewards/server.test.ts b/plugins/stewards/server.test.ts index 496fc937..159ee105 100644 --- a/plugins/stewards/server.test.ts +++ b/plugins/stewards/server.test.ts @@ -2242,6 +2242,10 @@ describe("needs you items", () => { const need = t.hooks.store.openNeeds(b.id).find((n) => n.kind === "approve-pr")!; expect(need).toMatchObject({ what: "Approve acme/web#7 on GitHub", filedBy: "plugin" }); expect(t.hooks.store.openNeeds(b.id).some((n) => n.kind === "merge")).toBe(false); + // BB-29: the board's `url` is the pull request and `entityUrl` the ticket, + // so the page can link the PR separately from the entity key. + const board = async () => ((await t.harness.callRpc("stewardsBoard", { projectId: "p1" })) as { board: { needs: Array<{ kind: string; url: string | null; entityUrl: string | null }> } }).board; + expect((await board()).needs.find((n) => n.kind === "approve-pr")).toMatchObject({ url: "https://github.com/acme/web/pull/7", entityUrl: "https://linear.app/acme/issue/ENG-12" }); const res = await t.harness.callRpc("stewardsNeedAction", { needId: need.id, action: "approve" }, client); expect(res).toMatchObject({ ok: true }); expect(t.githubComments).toEqual([{ repo: "acme/web", number: 7, body: "Approved aaaaaaa1 from the Stewards page" }]); @@ -2252,6 +2256,7 @@ describe("needs you items", () => { await t.flush(); expect(t.hooks.store.openNeeds(b.id).find((n) => n.kind === "approve-pr")).toBeUndefined(); expect(t.hooks.store.openNeeds(b.id).find((n) => n.kind === "merge")).toBeDefined(); + expect((await board()).needs.find((n) => n.kind === "merge")).toMatchObject({ url: "https://github.com/acme/web/pull/7", entityUrl: "https://linear.app/acme/issue/ENG-12" }); }); it("refuses an approve-pr the gate cannot hold, names the missing step and files nothing (BB-21)", async () => { @@ -2550,7 +2555,7 @@ describe("needs you items", () => { it("shows the items on the board with their actionability", async () => { const t = await withPull([marker]); - const board = async () => ((await t.harness.callRpc("stewardsBoard", { projectId: "p1" })) as { board: { needs: Array<{ kind: string; key: string; url: string | null; actionable: boolean; why: string | null }> } }).board; + const board = async () => ((await t.harness.callRpc("stewardsBoard", { projectId: "p1" })) as { board: { needs: Array<{ kind: string; key: string; url: string | null; entityUrl: string | null; actionable: boolean; why: string | null }> } }).board; const first = await board(); expect(first.needs).toEqual([expect.objectContaining({ kind: "approve-pr", key: "ENG-12", url: "https://github.com/acme/web/pull/7", actionable: true, why: null })]); // Once the owner approves, a merge item appears; a running worker makes it not actionable. diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index 381ceaf5..2f4dbb91 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -278,6 +278,8 @@ export const rpcContract = defineRpcContract({ key: z.string(), kind: z.string(), url: z.string().nullable(), + /** The binding's own link (its ticket or pull request), so the key opens the entity, not the item's `url`. */ + entityUrl: z.string().nullable(), /** The escalation this item answers, when the project steward forwarded one. */ escalationId: z.string().nullable(), /** Fixed choices the user picks from, for a `decide` item; empty otherwise. */ @@ -4282,7 +4284,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P }); /** One open "needs you" item, with whether its button can act now and why not when it cannot. */ - function needView(n: Need, b: Binding): { id: string; bindingId: string; key: string; kind: string; url: string | null; escalationId: string | null; choices: string[]; lessonId: string | null; what: string; how: string | null; destination: string | null; threadId: string | null; createdAt: number; actionable: boolean; why: string | null } { + function needView(n: Need, b: Binding): { id: string; bindingId: string; key: string; kind: string; url: string | null; entityUrl: string | null; escalationId: string | null; choices: string[]; lessonId: string | null; what: string; how: string | null; destination: string | null; threadId: string | null; createdAt: number; actionable: boolean; why: string | null } { let actionable = true; let why: string | null = null; let threadId: string | null = null; @@ -4303,7 +4305,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P // appears in its first turn. Link the thread once one has been spawned. threadId = store.secretRequesterForNeed(n.id)?.threadId ?? null; } - return { id: n.id, bindingId: b.id, key: b.entityKey, kind: n.kind, url: /^https?:\/\//iu.test(n.url) ? n.url : null, escalationId: typeof n.data.escalationId === "string" ? n.data.escalationId : null, choices: needChoices(n), lessonId: typeof n.data.lessonId === "string" ? n.data.lessonId : null, what: n.what, how: n.how, destination: n.kind === "provide-secret" ? secretDestination(n) : null, threadId, createdAt: n.createdAt, actionable, why }; + return { id: n.id, bindingId: b.id, key: b.entityKey, kind: n.kind, url: /^https?:\/\//iu.test(n.url) ? n.url : null, entityUrl: b.url, escalationId: typeof n.data.escalationId === "string" ? n.data.escalationId : null, choices: needChoices(n), lessonId: typeof n.data.lessonId === "string" ? n.data.lessonId : null, what: n.what, how: n.how, destination: n.kind === "provide-secret" ? secretDestination(n) : null, threadId, createdAt: n.createdAt, actionable, why }; } function formatBindings(rows: Binding[]): string {