gitoria
All repositories: gitoria
18.3 KB
# Gitoria apps API: the contract (gitoria#38, children #40–#47)Version 1.5.1, 2026-11-05. Open points decided by Vinzenz (the reference for open questions, review: docs/apps-api-review-vinzenz.md). v1.2.1 is live (#40–#44, #46); the v1.3 additions come with #47. This file is the contract that gitoria is built against and Kunibert codes against.Marks: **[OPEN]** = the name or value may still change; everything else is fixed. Any change comes as a new versionof this file with a changelog line at the bottom, announced to Kunibert.## 0. Words- **App**: an outside program connected to ONE repo by that repo's owner. It acts under its own bot name and never as a person.- **Key** `gak_` + 40 hex: long-lived, given once at connect time, kept by the app. It is used only to get tokens.- **Token** `gat_` + 40 hex: short-lived (1 hour), used for every API call and for git fetch.- **Secret**: 64 hex, given once at connect time. It signs the events. Gitoria never sends it again.- **API base** `{api}`: comes in the connect answer and in every event (`repo.api`). Never build it yourself.Today it is `https://<slug>.gitoria.worldapi.org/api`; for an organization repo it is `https://<org>.gitoria.worldapi.org/api/<repo>`.- **PR number** `N`: 1, 2, 3 … per repo. It never changes and is never reused (#40).## 1. Connecting (#41)Two ways. Both end with the app holding `key`, `secret` and `api`.**A. Connect flow** (the tickets connect shape, with gitoria as the server):1. The app sends the owner's browser to`https://<repo host>/settings/apps/connect?app=<name>&hook=<receiver URL>&return=<URL>&state=<random>`.`<repo host>` is the repo's address; an organization repo uses `/<repo>/settings/apps/connect`.2. Gitoria signs the person in, checks that they own the repo, shows "Connect <name> to <repo>?", and on Yesredirects to `return?code=<one-time code>&state=<same state>`. The code works once and for 5 minutes.3. The app's SERVER calls `POST {repo address}/api/apps/exchange` with `{"code":"…"}` (no auth). The answer:`{"key":"gak_…","secret":"<64 hex>","api":"https://…/api","repo":{"id":"…","full":"kunibert-test"},"app":{"id":"…","name":"Kunibert"}}`.4. Gitoria sends a `ping` event at once.**B. Manual**: the owner opens Settings → Apps → Add, types a name and the receiver URL, and sees the key and thesecret once. This is the way for a conductor chat (`https://<hyperconductor>/api/push/<chatId>`).**Allowed URLs** (`hook` and `return`), no redirects followed: `https://` with host `worldapi.org` or one of its subdomains, or a URLthat starts with one of the HyperConductor bases configured in gitoria, exactly as written there, plain `http` included(the same list tickets uses in `TICKETS_PUSH_ALLOWED`, e.g. `http://100.77.141.84:8100`). The configured bases are listed in README.Anything else → 400 `invalid_url`.Re-connecting the same app name to the same repo replaces the old key and secret. The owner can remove an app (key andtokens die at once) or rotate its secret (Settings → Apps).## 2. Tokens (#42)`POST {api}/apps/token` with `Authorization: Bearer gak_…` → `200 {"token":"gat_…","expires":"2026-11-02T07:00:00Z"}`.The token lives 1 hour. Get a new one whenever you need it; old ones keep working until they expire.- API: `Authorization: Bearer gat_…`.- git over HTTPS: Basic auth, user `app` (any name is accepted), password `gat_…`.Example: `git -c http.extraHeader="Authorization: Basic $(printf 'app:%s' "$TOKEN" | base64 -w0)" fetch <clone URL> …`The token is **read-only**: fetch and clone work, a push is refused (403).- A token works for its own repo only. For any other repo every route answers 404, the same as for a repo that does not exist.## 3. Git (#40, #42)- Clone URL: `repo.clone` in every event (today `https://<slug>.gitoria.worldapi.org/<slug>.git`).- PR head: **`refs/pull/N/head`**. Gitoria keeps it pointing at the PR's head commit.- Base: **`refs/heads/<target>`** (`pull.baseRef`). `pull.mergeBase` is the merge-base sha at the time of the event.- Shallow fetch works: protocol v2 (`git -c protocol.version=2`) with `--depth` and `--deepen` (checked live 2026-11-02).- An event is sent only after `refs/pull/N/head` points at `pull.head`, so a fetch right after the event finds the commit.- What a PR is in gitoria: a commit whose subject starts `|||PR ` (target = main branch) or `|||PR|<branch>] ` on a source branch.Title = the rest of the subject; body = the rest of that commit's message.## 4. Events (#43)`POST <receiver URL>`, body = JSON (UTF-8), headers:| header | value ||---|---|| `Content-Type` | `application/json` || `User-Agent` | `gitoria` || `X-Push-Event` | the event name below || `X-Push-Delivery` | uuid; the SAME on a retry or redelivery || `X-Push-Signature-256` | `sha256=` + hex HMAC-SHA256(key = the secret's 64 hex characters as ASCII bytes, raw body bytes) |Delivery: any 2xx within 10 seconds counts as delivered. Otherwise gitoria retries after 1 min, 5 min, 30 min, 2 h and 6 h,then marks the delivery `failed`. Redirects are not followed. Order is not guaranteed: trust `pull.head`and the `time` field, and treat a repeated `X-Push-Delivery` as already handled. A receiver should answer at once and work afterwards.Common body for every event:```json{ "event": "pull_request", "action": "opened", "delivery": "<uuid>", "time": "2026-11-02T06:00:00Z","repo": { "id": "…", "full": "kunibert-test", "private": false, "api": "https://…/api", "clone": "https://…/kunibert-test.git" },"app": { "id": "…", "name": "Kunibert" },"sender": { "id": "…", "name": "Caramboleyo" } }````sender` = the gitoria user who caused the event (the pusher, the commenter, the person who merged); `null` if gitoria itself caused it.The **pull** object (in every PR event, and from `GET {api}/pulls/N`):```json{ "number": 3, "title": "…", "body": "…", "draft": false, "state": "open","author": { "id": "…", "name": "…" }, "source": "feature-x", "target": "main","head": "<40 hex>", "ref": "refs/pull/3/head", "baseRef": "refs/heads/main", "base": "<target tip sha>", "mergeBase": "<sha>","tickets": ["gitoria.worldapi.org#12"], "url": "https://…/pulls/3", "created": "…", "updated": "…","statuses": [status…], "required": [{"app":{"id":"…","name":"Kunibert"},"context":"kunibert"}] }```- `statuses` (v1.3): every status on the CURRENT `head`, from every app (see `status` in §5).- `required` (v1.4): what the owner marked "required before merge", each as app + context. For reading only: it explains why Merge is off.- `state`: `open` | `closed` | `merged`.- `draft`: gitoria has no drafts, so it is always `false`.- `author`: the gitoria user who pushed the `|||PR` commit; `id` is `null` and `name` is the commit author when gitoria cannot tell.- `tickets`: the tickets this PR names in its title or body, as `project#n`. An explicit `project#12` is always listed.A bare `#12` is listed only when the repo is connected to tickets, because only then does gitoria know the project.Read the tickets from tickets with your own token. Gitoria serves no ticket content.Events:| `X-Push-Event` | `action` | extra fields | when ||---|---|---|---|| `ping` | — | — | right after connecting, and on "Send ping" in Settings || `pull_request` | `opened` | `pull` | a new `|||PR` commit appears || `pull_request` | `reopened` | `pull` | a closed PR's branch comes back with its `|||PR` commit || `pull_request` | `synchronize` | `pull`, `before`, `after`, `forced` (bool) | the PR's branch moves (new commits or a force-push) || `pull_request` | `closed` | `pull` (state `closed`) | branch deleted, or the `|||PR` commit gone from it || `pull_request` | `merged` | `pull` (state `merged`), `mergeCommit` | Merge button, or a push that puts the PR into its target || `review_requested` | `requested` | `pull` | a person clicks "Review again" on the PR page || `review_comment` | `created` | `pull`, `thread`, `comment` | a person replies in one of YOUR threads || `pull_comment` | `created` | `pull`, `comment` | a person writes in the PR's conversation (for example `@kunibert reset`) || `review_thread` | `resolved` / `unresolved` | `pull`, `thread` | a person resolves or reopens one of YOUR threads || `pull_request` | `ready` | `pull` | reserved, only once drafts exist |An app gets no events about its own actions. The common body (with `repo.api`, `repo.clone` and `app`) comes with EVERY event, `ping` included.## 5. Back-channel (#44, #46). Every route: `Authorization: Bearer gat_…`; answers are JSON| route | request | answer ||---|---|---|| `GET {api}/pulls?state=open\|all&cursor=&limit=` | — | `{"pulls":[pull…],"next":"<cursor>"\|null}` || `GET {api}/pulls/N` | — | `pull` || `POST {api}/pulls/N/reviews` | `{"head":"<sha>","verdict":"approve"\|"request_changes"\|"comment","body":"…","comments":[{"path":"lib/a.hl","line":42,"body":"…"}]}` | `201 {"review":{"id","verdict","head","created"},"threads":[{"id","path","line"}]}` || `GET {api}/pulls/N/reviews?cursor=&limit=` | — | `{"reviews":[{"id","verdict","head","body","created"}…],"next":…}` (your own reviews, newest first) || `GET {api}/pulls/N/threads?cursor=&limit=` | — | `{"threads":[thread…],"next":…}` (your own threads only) || `POST {api}/pulls/N/threads/:id/replies` | `{"body":"…"}` | `201 {"comment":comment}` || `POST {api}/pulls/N/threads/:id/resolve` | `{"resolved":true\|false}` | `200 {"thread":thread}` || `GET {api}/pulls/N/comments?cursor=&limit=` | — | `{"comments":[comment…],"next":…}` (the PR's conversation, oldest first) || `POST {api}/pulls/N/comments` | `{"body":"…"}` | `201 {"comment":comment}` (in the PR's conversation) || `PUT {api}/statuses/<sha>` | `{"context":"kunibert","state":"pending"\|"success"\|"failure"\|"error","title":"…","summary":"…","url":null}` | `200 {"status":{…,"updated"}}` || `GET {api}/statuses/<sha>` (v1.3) | — | `{"statuses":[status…]}`: every context on that sha, from every app; 404 for a sha this repo does not have || `GET {api}/deliveries?cursor=` | — | `{"deliveries":[{"id","event","action","time","status":"delivered"\|"pending"\|"failed","tries","lastCode"}],"next":…}` || `POST {api}/deliveries/:id/redeliver` | — | `202` |- `status` = `{"context","state","title","summary","url","head","updated","app":{"id","name"}}`. Reading shows all apps' statuses; an app writes only its own.- `outdated` = the thread was written on an older head than the PR's current one (`thread.head != pull.head`), even when itsfile and line did not change. It is not line tracking; an app that wants that compares the file itself.- `thread` = `{"id","path","line","head":"<sha it was written on>","outdated":bool,"resolved":bool,"comments":[comment…]}`.- `comment` = `{"id","seq","author":{"type":"app"\|"user","id","name"},"body","created"}`. `seq` is an integer that grows strictlywithin a repo (over all comments of all PRs), so it works as a watermark. `id` is an opaque string: do not compare it.`created` has milliseconds (`2026-11-02T06:00:00.123Z`). Lists are ordered by `seq`.- **Review**: `head` may be the PR's current head or ANY earlier head of this PR. The line check uses the diff of that `head`;if it is not the current head, the review's threads are `outdated` at once. Only a sha that was never a head of this PRgets `409 stale_head` (nothing stored). Your current verdict on a PR is your latest review; a `comment` review does notclear an earlier `request_changes`. `line` is a line number on the NEW side (the file at `head`) that lies inside a hunk of `git diff -M -U3 <mergeBase> <head>` (an added line or acontext line). `path` is the new-side path, after a rename. `<mergeBase>` is computed when the review arrives:`git merge-base <current target tip> <head>`, not the value from an older event.If any inline comment points at another line, the WHOLE review is refused: `422 invalid` with`details: [{"index":2,"path":"…","line":7,"reason":"line_not_in_diff"\|"no_such_file"}]`. Send it again without those comments,or put them in the body. At most 100 inline comments per review. Gitoria shows the review under the app's name with an "app" mark.- **Status**: one status per (head sha, app, context): an app writes and replaces only its own; another app may use the same context name without touching it. `error` = the app could not do its check (shown apart from `failure`;it does not count as `success`). Setting no status at all is allowed too. A newer PUT replaces the older one. If the owner set "required before merge"for that app + context, the Merge button stays off until that status is `success` on the PR's current head (#46).- Bodies (review, comment, status summary) are Markdown, up to 65,536 characters. Gitoria shows them escaped (no raw HTML).- Paging: pass `next` as `cursor`. `limit` defaults to 50 and is at most 100.## 6. Errors and limits (#47)Every error: `{"error":{"code":"…","message":"…","details":…}}`.| HTTP | code ||---|---|| 400 | `invalid_json`, `invalid_url` || 401 | `unauthorized` (missing, unknown or expired token: get a new token) || 403 | `app_token_required` (valid user token on an app-only route), `forbidden` (§7: an app token on the merge route; a user who may not push) || 404 | `not_found` (also: another repo, a removed app) || 409 | `stale_head`, `conflict` (merge refusal, with `details.reason`; see §7) || 413 | `too_large` (request body over 1 MB) || 422 | `invalid`, `checks_failed` (with `details`; see §7) || 429 | `rate_limited`, with a `Retry-After` header (seconds) |Limits per app: 300 reads and 60 writes per minute.## 7. User tokens (gtr_) (v1.5.1: #48, W49)A user access token is `gtr_` + 40 hex. It has no expiry. Its user is a **member** of a repo when it may read AND push there(owner, repo member or organization member). Member reads never reveal whether a repo or a PR exists to non-members: a validtoken of a non-member gets 404 `not_found`, also on public repos. This is on purpose, not a bug.Reads (W49, live dab74b0): `GET {api}/pulls`, `{api}/pulls/N`, `{api}/pulls/N/reviews`, `{api}/pulls/N/threads`,`{api}/pulls/N/comments`, `{api}/statuses/<sha>`. Shapes, order and paging are the same as for apps. A user sees every app'sreviews and threads; an app still sees only its own. User-token reads are not rate-limited by the apps API (the app limits of §6count apps only). Back-channel writes, `GET {api}/deliveries`, redelivery and `POST {api}/apps/token` stay app-only.Merge (#48, live 1a687b1): `POST {api}/pulls/N/merge`, `Authorization: Bearer gtr_…`. Body optional: empty, or`{"head":"<40 hex>"}` = the PR head the caller looked at. No other fields (always a merge commit with the message`Merge branch '<source>' into <target>`; no method, no message). Required checks (§4 `required`) must be `success` on the head.| HTTP | code | meaning ||---|---|---|| 200 | — | `{"merged":true,"mergeCommit":"<sha>","pull":{…}}`; `pull` has the shape of `GET {api}/pulls/N`, read after the merge || 400 | `invalid_json` | the body is not a JSON object || 401 | `unauthorized` | missing or unknown token ("a user access token is required") || 403 | `forbidden` | an app token ("apps cannot merge"), or a user who may read but not push || 404 | `not_found` | repo not visible to this user, or no such PR || 405 | `invalid` | not POST || 409 | `conflict` | not merged; `details = {"reason":"…"}`: `head_mismatch` (re-read the PR and retry), `already_merged`, `branch_gone`, `target_missing`, `merge_conflict` (message names up to 5 files), `target_moved` (retry), or `git_error` (could not read/write) || 413 | `too_large` | body over 1 MB || 422 | `invalid` | `head` is not 40 hex characters (`details`: field `head`) || 422 | `checks_failed` | required checks are not success; `details` is a list of `{"app":{"id":"…","name":"…"},"context":"…","state":"missing"}` for each missing or failed context; state is `missing` when no status exists, otherwise `pending`, `failure` or `error`. The message still names each as `<app> · <context> (<state>)`. |Event: `pull_request` action `merged`, `sender` = the merging user (never an app).A valid user token on an app-only route (any write of §5, deliveries, redelivery or `POST {api}/apps/token`) gets 403`app_token_required` with the message `this route needs an app token (gat_); user tokens (gtr_) can read pulls, reviews,threads, comments and statuses and merge with POST /pulls/N/merge`. Missing, unknown or expired tokens stay 401 `unauthorized`.## Changelog- v1.5.1 2026-11-05: valid user tokens on app-only routes get 403 `app_token_required`; unmet required checks get 422`checks_failed` with app, context and state in `details`; every 409 merge refusal carries `details.reason`.- v1.5 2026-11-05 (reviewed by Vinzenz): §7 user tokens: members merge with gtr_ (#48, deploy 1a687b1) and read pulls, reviews,threads, comments, statuses (W49, deploy dab74b0); known deviations (401 for gtr_ on app routes, 409 for failed required checks) stated.- v0 2026-11-02: first contract (Gitoria), before any code.- v1 2026-11-02 (Kunibert's points): `comment.seq` watermark and ms `created`; `GET …/pulls/N/comments`; exact diff for the line check(`-M -U3`, new-side path, merge-base at review time); explicit `project#n` listed without a tickets connection; common body on `ping`;status state `error`.- v1.4 2026-11-02 (security, decided by Vinzenz): statuses are keyed by (sha, app, context), so no app can replace another app's status;"required before merge" names app + context; `required` on the pull = `[{"app":{"id","name"},"context"}]`. A removed app's required entrystays unmet until the owner changes it. The PUT is unchanged.- v1.3.1 2026-11-02 (Kunibert's question): stated what `outdated` means (written on an older head), as built in #44.- v1.3 2026-11-02 (Kunibert's wish, decided by Vinzenz): `GET {api}/statuses/<sha>` lists all contexts on a sha; `status` carries `app`;the pull object gets `statuses` (current head, all apps) and `required` (read-only). Built with #47.- v1.2.1 2026-11-02: clarified the HMAC key = the secret string's ASCII bytes (not hex-decoded).- v1.2 2026-11-02 (Vinzenz): review on any earlier head (outdated threads, 409 only for a foreign sha); bodies 65,536; current verdict= latest review, `GET …/pulls/N/reviews`; shallow fetch (v2 depth/deepen) stated; open points closed (retries, `context`, limits, drafts).- v1.1 2026-11-02 (Apollo): the configured HyperConductor bases are allowed exactly as written, plain http included; https only for worldapi.org.
Branches
Latest commits
- 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
- ae373cfdgitoria#28: keep each reply draft in its thread componentmre
- eeeebd5agitoria: insert a newly created organization oncemre
- 34d2d5cagitoria: clear the bound public-key textarea after creationmre
- 119e54c0W60: restore conductor-owned tracking filesmre
- 24b479e7W60: record final gates, Chrome failures and AE evidencemre
- 5e11184cW60: record partial validation, framework gaps and cleanupmre
- 20fe13fagitoria#33: centralize login and tickets connection statemre
- 859754c0gitoria#29: retain the offline note and record the framework gapmre
- d140bc04gitoria#30: reproduce the upsert ordering constraintmre
- 6960e8f8gitoria#28: keep form values in bound component membersmre
- 0db27200gitoria#32: share character checks and environment lookupmre
- 452f6a1amission W60: logic clean-upsmre
- 1448c899log: cleanup, #49 GPTBot, tracker mentions on #36mre
- fcf95936log: v1.5.1 provenmre
- 22105420log: W51b livemre
- 7e8aabeareport: W51b pull source verificationmre
- 6c18de76fix: preserve pull sources across containing branchesmre
- fc36fa2elog: W51b pull source bugmre
- 56bc1220log: v1.5.1 livemre