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

`here` names a person's or an organization's page, and an unknown name, instead of saying "forge" #6272

Parked opened this
Closed without merging

scout/forge:scout/6249-here-names-a-person-s-or-an-organization → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +80 −3
src/actions/here.ts +46
@@ -26,6 +26,7 @@ import {
2626 getRepo,
2727 type Repo,
2828 } from "../core/repos.ts";
29 import { getUserByName, hiddenFrom } from "../core/users.ts";
2930 import { SYSTEM_NAMES } from "../core/reserved.ts";
3031 import { scopeAllows, type TokenScope } from "../core/tokens.ts";
3132 import type { User } from "../core/users.ts";
@@ -54,6 +55,8 @@ export interface Action {
5455 export interface Manifest {
5556 readonly here:
5657 | { readonly kind: "forge" | "explore" | "search" }
58 | { readonly kind: "person"; readonly username: string }
59 | { readonly kind: "org"; readonly org: string }
5760 | {
5861 readonly kind: "repository";
5962 readonly name: string;
@@ -111,6 +114,49 @@ export function manifestFor(
111114 name === undefined && (owner === "explore" || owner === "search")
112115 ? owner
113116 : undefined;
117 // One segment, or `/:owner/-/…`, that is not a page the forge keeps for
118 // itself names an account: a person, an organization, or nobody.
119 if (
120 owner !== undefined &&
121 page === undefined &&
122 (name === undefined || name === "-") &&
123 !SYSTEM.has(owner.toLowerCase())
124 ) {
125 const account = getUserByName(app.db, owner);
126 if (account === undefined || hiddenFrom(account, viewer))
127 return err("not_found");
128 const you = youFor(viewer, scope, undefined, app);
129 const rest = forgeActions(app, viewer, scope);
130 if (account.kind === "org")
131 return ok({
132 here: { kind: "org", org: account.username },
133 you,
134 actions: [
135 {
136 do: "list the organization's teams",
137 http: `GET /api/v1/orgs/${account.username}/teams`,
138 },
139 {
140 do: "list its public repositories",
141 http: `GET /api/v1/users/${account.username}/repos`,
142 },
143 ...rest,
144 ],
145 ...common,
146 });
147 return ok({
148 here: { kind: "person", username: account.username },
149 you,
150 actions: [
151 {
152 do: "read their public repositories",
153 http: `GET /api/v1/users/${account.username}/repos`,
154 },
155 ...rest,
156 ],
157 ...common,
158 });
159 }
114160 // Two segments under a name the forge keeps for itself are its own page,
115161 // never a repository (`core/reserved.ts`).
116162 // `/:owner/-/…` is an account's or an org's own page (its teams), never
test/here-manifest.test.ts +34 −3
@@ -236,7 +236,7 @@ describe("the manifest: what you can do here, as who you are", () => {
236236 }
237237 const q = (await manifest("/search?q=a%20b%26c")).body;
238238 expect(q.actions[0].http).toBe("GET /api/v1/search?q=a%20b%26c");
239 const other = (await manifest("/elsewhere")).body;
239 const other = (await manifest("/settings")).body;
240240 expect(other.here).toEqual({ kind: "forge" });
241241 expect(other.actions[0].do).toBe("explore apps and repositories");
242242 });
@@ -307,10 +307,41 @@ describe("the manifest: what you can do here, as who you are", () => {
307307 expect(carol.actions.find((a: any) => a.do === "offer a change").verify).toBeUndefined();
308308 });
309309
310 test("an org's own pages are the forge's, not a missing repository", async () => {
310 test("an org's own pages are the org's, not a missing repository", async () => {
311311 const res = await here("/acme/-/teams/Writers", "alice");
312312 expect(res.status).toBe(200);
313 expect(((await res.json()) as any).here.kind).toBe("forge");
313 expect(((await res.json()) as any).here).toEqual({ kind: "org", org: "acme" });
314 });
315
316 test("one segment is a person, an org, nobody, or one of the forge's own names", async () => {
317 const person = (await manifest("/wes")).body;
318 expect(person.here).toEqual({ kind: "person", username: "wes" });
319 expect(person.actions[0].http).toBe("GET /api/v1/users/wes/repos");
320 const org = (await manifest("/ACME", "carol")).body;
321 expect(org.here).toEqual({ kind: "org", org: "acme" });
322 expect(org.actions[0].http).toBe("GET /api/v1/orgs/acme/teams");
323 const nobody = await here("/nope");
324 expect(nobody.status).toBe(404);
325 expect(await nobody.json()).toEqual(await (await here("/acme/nothing")).json());
326 expect((await manifest("/settings")).body.here.kind).toBe("forge");
327 expect((await manifest("/explore")).body.here.kind).toBe("explore");
328 expect((await manifest("/search?q=x")).body.here.kind).toBe("search");
329 const mcp = (await (
330 await fetch(`${base}/mcp`, {
331 method: "POST",
332 headers: {
333 "content-type": "application/json",
334 authorization: `Bearer ${tokens["carol"]}`,
335 },
336 body: JSON.stringify({
337 jsonrpc: "2.0",
338 id: 9,
339 method: "tools/call",
340 params: { name: "here", arguments: { url: `${base}/wes` } },
341 }),
342 })
343 ).json()) as any;
344 expect(JSON.parse(mcp.result.content[0].text).here.kind).toBe("person");
314345 });
315346
316347 test("a pull page says whether the pull's code runs, or waits for a writer's approval", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs