Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Need = {
key: string;
kind: string;
url: string | null;
entityUrl: string | null;
escalationId: string | null;
choices: string[];
lessonId: string | null;
Expand Down Expand Up @@ -40,6 +41,7 @@ const need = (over: Partial<Need> = {}): Need => ({
key: "ENG-12",
kind: "decide",
url: null,
entityUrl: null,
escalationId: null,
choices: [],
lessonId: null,
Expand Down Expand Up @@ -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();
});
});
10 changes: 9 additions & 1 deletion plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<li className="flex flex-col gap-2 p-3">
<p className="flex flex-wrap items-center gap-2">
<EntityLink entityKey={n.key} url={n.url} />
<EntityLink entityKey={n.key} url={n.entityUrl ?? n.url} />
<Badge tone="bad">{n.kind}</Badge>
<span className="text-xs text-muted-foreground">asked {ago(n.createdAt, now)}</span>
</p>
Expand Down Expand Up @@ -658,6 +661,11 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now:
</button>
)}
{n.threadId !== null ? <ThreadLink threadId={n.threadId}>{n.kind === "provide-secret" ? "Open the requester" : "Open the worker"}</ThreadLink> : null}
{prUrl !== null ? (
<button type="button" className="underline underline-offset-2 hover:text-foreground" onClick={() => navigate.openUrl(prUrl)}>
Open the pull request
</button>
) : null}
{typeof state === "object" ? <span className="text-destructive">{state.error}</span> : null}
</div>
</li>
Expand Down
7 changes: 6 additions & 1 deletion plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]);
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Loading