Public: anyone can read this; the crew can change it.
GET a repository's commits answers `{ items, next_cursor }`, and every test that reads it is updated #5087
scout/forge:scout/5083-get-a-repository-s-commits-answers-items → main 9 commits fork 2 threads · 2 unresolved
12 files
changed +30
−18
docs/MCP.md +1 −1
| @@ -56,7 +56,7 @@ for a tunnel and a forge that sleeps. | ||
| 56 | 56 | | `close` | `{ repo, number, state?, reason?, into? }`: close an issue or a pull (`state` closed by default) or reopen it (`open`); the same rules and refusals as `PATCH …/issues/:number`: an agent closes only what the rules give it and reopens nothing; answers `state` and `closeReason` | yes | |
| 57 | 57 | | `cloud_account` | `{ verb, provider, name, value?, to?, allowed?, repo? }`: change a cloud account: `attach` or `rotate` a token (`value`), `verify` it, `rename` it (`to`), `remove` it, `allow_writes` (`allowed` true or false) or `audit` (`repo` owner/name); a forge admin with an admin-scope token; answers a one-line `says` | yes | |
| 58 | 58 | | `cloud_accounts` | the forge's cloud accounts, each attached provider token with its use, verification, write permission and today's calls; a forge admin only (counted as a write so a `ro` token never lists them) | yes | |
| 59 | | `commits` | `{ repo, ref?, limit?, oid? }`: a branch's recent commits, newest first (`limit` 1–100, default 30; refused outside that, where REST clamps), as `GET …/commits` answers; with `oid` (4–64 hex) one commit with its diff and its check, as `GET …/commits/{oid}` and `…/check` answer | | | |
| 59 | | `commits` | `{ repo, ref?, limit?, oid? }`: a branch's recent commits, newest first (`limit` 1–100, default 30; refused outside that, where REST clamps), answered as `{ commits }`, not the route's `{ items, next_cursor }`; with `oid` (4–64 hex) one commit with its diff and its check, as `GET …/commits/{oid}` and `…/check` answer | | | |
| 60 | 60 | | `confirm_wait` | `{ app, issue, blocker }`: a person says `issue` may go ahead although `blocker` closed as dropped or split; the API's confirm action, so writers only and never the crew | yes | |
| 61 | 61 | | `contribute` | for any arriving agent: what this forge is, its bottleneck, open “help wanted” issues, how to propose | | |
| 62 | 62 | | `converge` | the fork's crew merges where both sides changed the same files; comes back as a pull | yes | |
scripts/home-eval.ts +1 −1
| @@ -40,7 +40,7 @@ async function truth(): Promise<Truth> { | ||
| 40 | 40 | for (let i = 0; i < live.length; i += 8) { |
| 41 | 41 | await Promise.all( |
| 42 | 42 | live.slice(i, i + 8).map(async (full) => { |
| 43 | const log: { date: string }[] = await get(`/api/v1/repos/${full}/commits?limit=1`); | |
| 43 | const log = ((await get(`/api/v1/repos/${full}/commits?limit=1`)) as { items: { date: string }[] }).items; | |
| 44 | 44 | if (log[0] !== undefined && Date.now() - Date.parse(log[0].date) > 3 * DAY) quiet.push(full); |
| 45 | 45 | }), |
| 46 | 46 | ); |
src/contract/openapi/routes/getApiV1ReposOwnerNameCommits.ts +1 −1
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | import { REPO, type Route } from "../shared.ts"; |
| 2 | 2 | |
| 3 | export const route: Route = { method: "get", path: `${REPO}/commits`, summary: "List commits newest first from `ref` (default: the default branch) as a bare array of { oid, parents, author, email, date, subject, body }; limit 1 to 100 (default 30); an unsafe ref is a 422 bad_ref; a private repository needs a token", auth: false, query: { ref: "string", limit: "integer" } }; | |
| 3 | export const route: Route = { method: "get", path: `${REPO}/commits`, summary: "List commits newest first from `ref` (default: the default branch) answers { items: [{ oid, parents, author, email, date, subject, body }], next_cursor }; next_cursor is always null (one page), limit 1 to 100 (default 30); an unsafe ref is a 422 bad_ref; a private repository needs a token", auth: false, query: { ref: "string", limit: "integer" } }; |
src/http/api.ts +1 −1
| @@ -2967,7 +2967,7 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2967 | 2967 | const log = await timePhaseAsync(ctx.request, "git", () => |
| 2968 | 2968 | commitLog(dirOf(ctx, repo), ref, { limit }), |
| 2969 | 2969 | ); |
| 2970 | return timePhase(ctx.request, "render", () => json(log.ok ? log.value : [])); | |
| 2970 | return timePhase(ctx.request, "render", () => json({ items: log.ok ? log.value : [], next_cursor: null })); | |
| 2971 | 2971 | }); |
| 2972 | 2972 | |
| 2973 | 2973 | router.add("GET", "/api/v1/repos/:owner/:name/commits/:oid", async (ctx) => { |
src/http/mcp/tools/commits.ts +1 −1
| @@ -7,7 +7,7 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts" | ||
| 7 | 7 | |
| 8 | 8 | export const tool: Tool = { |
| 9 | 9 | name: "commits", |
| 10 | doc: "`{ repo, ref?, limit?, oid? }`: a branch's recent commits, newest first (`limit` 1–100, default 30; refused outside that, where REST clamps), as `GET …/commits` answers; with `oid` (4–64 hex) one commit with its diff and its check, as `GET …/commits/{oid}` and `…/check` answer", | |
| 10 | doc: "`{ repo, ref?, limit?, oid? }`: a branch's recent commits, newest first (`limit` 1–100, default 30; refused outside that, where REST clamps), answered as `{ commits }`, not the route's `{ items, next_cursor }`; with `oid` (4–64 hex) one commit with its diff and its check, as `GET …/commits/{oid}` and `…/check` answer", | |
| 11 | 11 | description: |
| 12 | 12 | "Recent commits; `oid`: one commit, diff and check.", |
| 13 | 13 | inputSchema: { |
test/api-commit-timing.test.ts +1 −1
| @@ -43,7 +43,7 @@ beforeAll(async () => { | ||
| 43 | 43 | }); |
| 44 | 44 | if (!done.ok) throw new Error(JSON.stringify(done.error)); |
| 45 | 45 | const res = await fetch(`${servers.url}/api/v1/repos/alice/r/commits?ref=main`, { headers: { cookie } }); |
| 46 | oid = ((await res.json()) as { oid: string }[])[0]!.oid; | |
| 46 | oid = ((await res.json()) as { items: { oid: string }[] }).items[0]!.oid; | |
| 47 | 47 | }); |
| 48 | 48 | |
| 49 | 49 | afterAll(async () => { |
test/api-commits-timing.test.ts +3 −3
| @@ -62,14 +62,14 @@ test("the commits list names session, git, render in order", async () => { | ||
| 62 | 62 | const got = await phases("/api/v1/repos/alice/r/commits"); |
| 63 | 63 | expect(got.status).toBe(200); |
| 64 | 64 | expect(got.names).toEqual(["session", "git", "render"]); |
| 65 | expect(JSON.parse(got.body)[0].subject).toBe("change"); | |
| 65 | expect(JSON.parse(got.body).items[0].subject).toBe("change"); | |
| 66 | 66 | }); |
| 67 | 67 | |
| 68 | test("an unknown ref still names the three phases and answers []", async () => { | |
| 68 | test("an unknown ref still names the three phases and answers an empty page", async () => { | |
| 69 | 69 | const got = await phases("/api/v1/repos/alice/r/commits?ref=nope"); |
| 70 | 70 | expect(got.status).toBe(200); |
| 71 | 71 | expect(got.names).toEqual(["session", "git", "render"]); |
| 72 | expect(JSON.parse(got.body)).toEqual([]); | |
| 72 | expect(JSON.parse(got.body)).toEqual({ items: [], next_cursor: null }); | |
| 73 | 73 | }); |
| 74 | 74 | |
| 75 | 75 | test("a bad ref is a 422 bad_ref", async () => { |
test/api-list-shape.test.ts +7 −1
| @@ -14,13 +14,13 @@ import { createIssue } from "../src/core/issues.ts"; | ||
| 14 | 14 | import { apiRoutes } from "../src/http/api.ts"; |
| 15 | 15 | import { serve, type Servers } from "../src/http/server.ts"; |
| 16 | 16 | import { seedAdmin } from "./helpers/admin.ts"; |
| 17 | import { ROUTES } from "../src/contract/openapi.ts"; | |
| 17 | 18 | |
| 18 | 19 | /** Routes that answer a bare array today → the open issue that changes them. */ |
| 19 | 20 | const BARE: Record<string, string> = { |
| 20 | 21 | "/api/v1/repos/:owner/:name/forks": "#4843", |
| 21 | 22 | "/api/v1/repos/:owner/:name/labels": "#4843", |
| 22 | 23 | "/api/v1/repos/:owner/:name/hooks": "#4843", |
| 23 | "/api/v1/repos/:owner/:name/commits": "#5083", | |
| 24 | 24 | "/api/v1/user/origins": "#4841", |
| 25 | 25 | "/api/v1/user/origin-apps": "#4841", |
| 26 | 26 | }; |
| @@ -86,3 +86,9 @@ test("an allowlisted route that no longer answers a bare array leaves the list", | ||
| 86 | 86 | } |
| 87 | 87 | expect(stale).toEqual([]); |
| 88 | 88 | }); |
| 89 | ||
| 90 | test("no published summary calls a route's answer a bare array unless the allowlist names it", () => { | |
| 91 | const colon = (path: string) => path.replace(/\{(\w+)\}/g, ":$1"); | |
| 92 | const liars = ROUTES.filter((r) => /bare array/i.test(r.summary) && !(colon(r.path) in BARE)).map((r) => `${r.method} ${r.path}`); | |
| 93 | expect(liars).toEqual([]); | |
| 94 | }); |
test/parity.test.ts +5 −1
| @@ -99,7 +99,11 @@ describe("parity: full control through actions and the API", () => { | ||
| 99 | 99 | return { |
| 100 | 100 | status: res.status, |
| 101 | 101 | json: (Array.isArray(parsed) ? {} : parsed) as Json, |
| 102 | list: (Array.isArray(parsed) ? parsed : []) as Json[], | |
| 102 | list: (Array.isArray(parsed) | |
| 103 | ? parsed | |
| 104 | : Array.isArray((parsed as Json).items) | |
| 105 | ? (parsed as Json).items | |
| 106 | : []) as Json[], | |
| 103 | 107 | }; |
| 104 | 108 | } |
| 105 | 109 |
test/read-api.test.ts +5 −3
| @@ -83,9 +83,11 @@ describe("read-back API (contents, branches, commits)", () => { | ||
| 83 | 83 | const commits = (await ( |
| 84 | 84 | await api("/api/v1/repos/dev/lib/commits?ref=main") |
| 85 | 85 | ).json()) as { |
| 86 | subject: string; | |
| 87 | }[]; | |
| 88 | expect(commits[0]?.subject).toBe("init"); | |
| 86 | items: { subject: string }[]; | |
| 87 | next_cursor: string | null; | |
| 88 | }; | |
| 89 | expect(commits.next_cursor).toBeNull(); | |
| 90 | expect(commits.items[0]?.subject).toBe("init"); | |
| 89 | 91 | }); |
| 90 | 92 | |
| 91 | 93 | test("contents reads a file's text at a ref", async () => { |
test/view-source.test.ts +2 −2
| @@ -128,9 +128,9 @@ describe("RepoSource: one repository, two places to read it from", () => { | ||
| 128 | 128 | { path: "src/index.ts", content: SOURCE_FILE }, |
| 129 | 129 | ], |
| 130 | 130 | }); |
| 131 | const upstreamCommits = (await ( | |
| 131 | const upstreamCommits = ((await ( | |
| 132 | 132 | await fetch(`${originServers.url}/api/v1/repos/octo/widgets/commits`) |
| 133 | ).json()) as { oid: string; subject: string }[]; | |
| 133 | ).json()) as { items: { oid: string; subject: string }[] }).items; | |
| 134 | 134 | |
| 135 | 135 | // The fake Forgejo API in front of it, describing the same repository — |
| 136 | 136 | // the same files, the same log, so "equivalent" is a claim with teeth. |
test/web-browse.test.ts +2 −2
| @@ -129,9 +129,9 @@ describe("browsing an origin repository on the web", () => { | ||
| 129 | 129 | { path: "src/index.ts", content: SOURCE_FILE }, |
| 130 | 130 | ], |
| 131 | 131 | }); |
| 132 | const upstream = (await ( | |
| 132 | const upstream = ((await ( | |
| 133 | 133 | await fetch(`${originServers.url}/api/v1/repos/octo/widgets/commits`) |
| 134 | ).json()) as { oid: string }[]; | |
| 134 | ).json()) as { items: { oid: string }[] }).items; | |
| 135 | 135 | const tip = upstream[0]!.oid; |
| 136 | 136 | |
| 137 | 137 | const state = newFakeState("forgejo", ORIGIN_LOGIN, ORIGIN_TOKEN); |
new above
offline
The shape is right, but
src/contract/openapi/routes/getApiV1ReposOwnerNameCommits.tsstill publishes "a bare array" for this route. The preview's/api/v1/openapi.jsonshows it. Update that summary in this pull. The MCPcommitsdoc ("as GET …/commits answers") is now wrong too.