| 1 | # BraidHub: the protocol |
| 2 | |
| 3 | BraidHub is a braid server: repositories live on it, people and agents sign |
| 4 | in with GitHub, and agents on any machine land on the same `main`. Each |
| 5 | repository can keep a GitHub repository as its mirror. BraidHub runs at |
| 6 | <https://braidhub.elffuss.com>. This document is the contract between the |
| 7 | hub and the client (`braid login`, `braid hub …`, and `braid land` / `braid |
| 8 | update` in a repository linked to a hub). `crates/hubproto` holds the types |
| 9 | and the object stream codec that both sides use. |
| 10 | |
| 11 | Status: protocol version 1. Everything here is new in braid 0.1, and the |
| 12 | hub serves all of it. |
| 13 | |
| 14 | Sections 1 to 14 are the core: accounts, repositories, objects, landing, |
| 15 | git, mirrors, limits, the client and the web. Sections 15 to 24 are what |
| 16 | grows around the repositories: browsing, discovery, stars and following, |
| 17 | issues, change requests, forks, the inbox, blocks, syncing with GitHub, |
| 18 | and the terms. Section 25 is verification: keeping a repository's default |
| 19 | branch green with the verdicts of its CI. |
| 20 | |
| 21 | ## 1. Conventions |
| 22 | |
| 23 | - `GET /v1` → `{"version": 1, "limits": {"max_body", "max_put", |
| 24 | "max_json", "max_ids", "max_paths", "missing_page", "missing_page_max", |
| 25 | "missing_objects", "tree_entries", "tree_depth", "max_list", |
| 26 | "social"}, "features": ["verify"]}`: the protocol version, and the sizes |
| 27 | of section 12 this hub enforces, in bytes or entries, so that a client |
| 28 | sizes its requests to them. `social` holds those of browsing and of the |
| 29 | social features: `{"title", "text", "page", "topics", "topic", |
| 30 | "labels", "thread_labels", "assignees", "comments_per_thread", |
| 31 | "review_comments", "mentions", "references", "request_changesets", |
| 32 | "request_bytes", "dir_page", "text_view"}`. `features` lists the parts |
| 33 | of the protocol the hub serves beyond its core: `verify` when it |
| 34 | verifies branches (section 25). It is left out when the hub lists none, |
| 35 | and a client calls the routes of such a part, or sends a field of it, |
| 36 | only when the hub lists it. Anyone may ask. |
| 37 | - JSON bodies are UTF-8, `Content-Type: application/json`. Ids are 64 |
| 38 | lowercase hex digits (braid) or 40 (git SHA-1). Times are RFC 3339 in UTC. |
| 39 | - Every error is a JSON object `{"error": "<code>", "detail": "<text>"}` |
| 40 | with a 4xx or 5xx status, plus extra fields where noted. Codes: |
| 41 | `unauthorized` (401), `forbidden` (403), `not_found` (404), |
| 42 | `method_not_allowed` (405: the route exists, the method does not), |
| 43 | `exists` (409), `invalid` (400), `missing` (409, with `ids`: objects the |
| 44 | server needs), `not_on_branch` (409, with `head`: the stack is not built |
| 45 | on the ref, which points to `head`; update first), `moved` (409: a ref |
| 46 | does not point where the request |
| 47 | expects), `too_large` (413), `rate_limited` (429, with `retry_after` |
| 48 | seconds), `quota` (403: an account holds as many repositories, or its |
| 49 | repositories store as many bytes, as an account may; section 12), |
| 50 | `internal` (500), `unavailable` (503: the hub cannot do this |
| 51 | now, such as signing in when it has no GitHub app or GitHub does not |
| 52 | answer). The detail of `internal` only says that the hub failed: why goes |
| 53 | to the hub's log. |
| 54 | - What the hub's logs keep, and for how long, is in its terms |
| 55 | (`/terms#logs`, section 24). |
| 56 | - A repository is `{owner}/{name}`. `owner` is a GitHub login, compared |
| 57 | without regard to case and stored lowercase. `name` is 1 to 100 of |
| 58 | `A-Z a-z 0-9 . _ -`, does not start with `.` and does not end with `.git`; |
| 59 | names are compared without regard to case too (`Demo` and `demo` are one |
| 60 | repository), and a repository keeps the case it was made with. |
| 61 | - A path parameter that breaks these rules, or an id that is not 64 |
| 62 | lowercase hex digits (40 for git), is 400 `invalid`. |
| 63 | - A private repository answers 404 `not_found` to whoever may not read it, |
| 64 | as if it did not exist, whatever the route, the method, the path or the |
| 65 | body; and it is in none of their lists, counts, search results, |
| 66 | notifications or links (section 5). One the caller may read but not |
| 67 | change answers 403 `forbidden`. |
| 68 | - Branch and tag names are braid ref names: not empty, at most 4,096 bytes, |
| 69 | no NUL. A ref under `braid/` or `remote/` is internal: it is listed, never |
| 70 | written by a client. |
| 71 | - **Lists that come a page at a time** take `limit`, 1 to 100 (the `page` |
| 72 | of `limits.social`; 30 when it is left out), and `after`, the `next` of |
| 73 | the page before, and answer `next`, `null` on the last page. A cursor is |
| 74 | opaque: one that does not belong to the list (another route, query or |
| 75 | order) is 400 `invalid`, as is a `limit` out of range. A page holds only |
| 76 | what the caller may see, and neither it nor its `next` says anything of |
| 77 | what was left out. |
| 78 | - **`Idempotency-Key`.** A request that creates something (each route that |
| 79 | takes the header says so: opening an issue or a change request, |
| 80 | commenting, reviewing, forking, a sync of GitHub repositories, and a |
| 81 | verdict or a reset of verification) may |
| 82 | send `Idempotency-Key: <key>`, 1 to 64 of `A-Z a-z 0-9 _ -`, a new key |
| 83 | for each new request; any other value, or the header twice, is 400 |
| 84 | `invalid`. The hub keeps the first answer for a day, for the account |
| 85 | that sent it: the same request sent again with the same key, by any |
| 86 | token or the web session of that account, gets that answer again, with |
| 87 | `Idempotency-Replayed: true`, and is not done twice. The same request |
| 88 | means the same method, path and body. The same key with another request |
| 89 | is 400 `invalid`; while the first request is still being answered, 409 |
| 90 | `exists`, and the request can be sent again a moment later for its |
| 91 | answer. An answer that says the hub failed (5xx) or was busy (429), and |
| 92 | one over 64 KiB, is not kept: sent again, the request runs again. A day |
| 93 | after its request, a key is forgotten. Without the header, every request |
| 94 | runs. |
| 95 | - **Texts.** The titles of issues and change requests are 1 to 256 |
| 96 | characters on one line, without control characters (400 `invalid` |
| 97 | otherwise). Their texts, and those of comments and reviews, are Markdown |
| 98 | of at most 64 KiB (413 `too_large` past it), and a comment says |
| 99 | something (400 for an empty one). `title` and `text` of `limits.social` |
| 100 | give both sizes. A body that writes a text may carry `agent`, a label of |
| 101 | 1 to 100 characters without control characters, for the agent that |
| 102 | writes it: the hub records it beside the text and shows it as "via". |
| 103 | - READMEs, other Markdown files, and the bodies of issues, change |
| 104 | requests, comments and reviews are Markdown. The hub keeps them as they |
| 105 | were written, and renders them to HTML itself, on its pages and in the |
| 106 | `html` fields of its answers, by the rules below. |
| 107 | |
| 108 | ### Markdown |
| 109 | |
| 110 | The text is CommonMark, with GitHub's tables, strikethrough (`~~text~~`), |
| 111 | task lists (`- [ ]`, `- [x]`) and footnotes (`[^1]`). What it renders to is |
| 112 | safe on the hub's pages, whoever wrote it: |
| 113 | |
| 114 | - Raw HTML shows as text, as it was written, and HTML comments are left |
| 115 | out. |
| 116 | - A link keeps its destination when it is an `http://`, `https://` or |
| 117 | `mailto:` URL, a fragment (`#install`), a path on the hub that starts |
| 118 | with one `/`, or a path relative to the text. A relative path leads to |
| 119 | its file's page in the same repository and revision (`tree` for a path |
| 120 | that ends with `/`, `blob` otherwise), and `..` never leads out of the |
| 121 | repository. The destination is read as a browser reads it: without |
| 122 | control characters and white space, with `\` as `/`, and its scheme in |
| 123 | any case. Any other link (`javascript:`, `data:`, `//host`, …) shows its |
| 124 | text without the link. Every link in a text carries |
| 125 | `rel="nofollow ugc noopener noreferrer"`. |
| 126 | - Images show in a repository's own Markdown (its READMEs and the Markdown |
| 127 | files its pages show) when they are `.png`, `.jpg`, `.jpeg`, `.gif` or |
| 128 | `.webp` files of the same repository named by a relative path: they load |
| 129 | from the repository's raw route. Any other image, and every image in an |
| 130 | issue, a comment or a review, is a link to where it is, so that no text |
| 131 | makes a reader's browser fetch anything from elsewhere. |
| 132 | - Headings get ids: `user-content-` and a slug made as GitHub makes it |
| 133 | (lowercase; letters, digits, `-` and `_` kept; spaces as `-`; `-1`, `-2`, |
| 134 | … after a repeat), and a link to `#Install` leads to the heading |
| 135 | `Install`. Footnotes are numbered in the order they are referred to, and |
| 136 | listed at the end. The first word after a code fence names the code's |
| 137 | language, which the page carries as `class="language-…"` when it is 1 to |
| 138 | 32 of `a-z 0-9 + # -`. |
| 139 | - Elements nested more than 32 deep keep their text and lose their tags. A |
| 140 | README renders up to 512 KiB of it, and no text renders to more than |
| 141 | 2 MiB of HTML; past either, a note says that only the beginning is shown. |
| 142 | - A text that would cost the hub far more to render than its size, such as |
| 143 | tables whose head is wide and whose rows leave out many thousands of |
| 144 | cells, or thousands of emphasis marks in one paragraph that never pair |
| 145 | up, shows as it is written, in a block of plain text with a note that |
| 146 | says so. It links no references and names no issues to close. |
| 147 | |
| 148 | References in the prose of a text, outside code, links, images and raw |
| 149 | HTML, link where the reader may follow them, and stay text otherwise, as a |
| 150 | reference to something that does not exist does: |
| 151 | |
| 152 | - `#N`: thread `N` of the same repository, an issue or a change request; |
| 153 | - `owner/name#N`: thread `N` of another repository; |
| 154 | - `@login`: an account; |
| 155 | - 12 to 64 lowercase hex digits, at least one of them a letter: a changeset |
| 156 | of the repository, by its id or the start of it. |
| 157 | |
| 158 | A reference stands apart from what is around it: nothing that would make |
| 159 | it part of a word, a path, a URL, an entity or an e-mail address comes just |
| 160 | before it (`a#4`, `x/#4`, `` and `ada@example.com` hold none), and no |
| 161 | letter, digit or `_` comes just after it. `N` is 1 to 999,999,999, written |
| 162 | without leading zeros. The first 50 different references of a text link; |
| 163 | the rest stay text. What a reference does when a text is written is in |
| 164 | section 18. |
| 165 | |
| 166 | Closing words name the issues that a landing on the default branch closes |
| 167 | (section 8): `close`, `closes`, `closed`, `fix`, `fixes`, `fixed`, |
| 168 | `resolve`, `resolves` or `resolved`, in any case, then spaces, then `#N`, |
| 169 | outside code. `Fixes #4` names issue 4, and `closes#6` names nothing; a |
| 170 | message names at most 50. |
| 171 | |
| 172 | ## 2. Authentication |
| 173 | |
| 174 | **Tokens.** `brd_<id>_<secret>`: `id` is 8 characters and `secret` 52, both |
| 175 | lowercase RFC 4648 base32 without padding (`a-z 2-7`); the secret holds 32 |
| 176 | random bytes. A client sends `Authorization: Bearer brd_…` on every request, |
| 177 | SSE included. Never in a URL, a query string, argv or a log: the server logs |
| 178 | the token's `id` only, and keeps a keyed hash of the whole token, compared in |
| 179 | constant time. |
| 180 | |
| 181 | A token has an expiry (required, at most one year) and scopes. A scope is |
| 182 | `{"repo": "<owner>/<name>" | "<owner>/*" | "*", "rights": [<right>…]}`, where |
| 183 | a right is `read`, `interact`, `write`, `land:<ref glob>`, |
| 184 | `verify:<ref glob>` or `admin`. `write` includes `read` and `interact`, and |
| 185 | `admin` includes all three; a `land:<glob>` right counts only together |
| 186 | with `write`. A `verify:<glob>` right lets a token post verdicts on the |
| 187 | default branch when its glob matches it (section 25), and nothing else: it |
| 188 | counts only where the token's account may write, on a token that reads the |
| 189 | repository, through a scope or because anyone may read it, and that holds |
| 190 | no `write`, `admin`, `land:` or `interact` there, so that the token of a |
| 191 | CI job can say how its tests went and do nothing more. `interact` lets a |
| 192 | token take part where its account reads (section 5): star, watch, open |
| 193 | issues and change requests, comment, review, and mark its notifications; |
| 194 | on `*`, it also follows and blocks accounts and changes the account's |
| 195 | settings. It gives no `read` of its own, and forking also needs `write` |
| 196 | where the fork goes (section 20). A token never grants more than its |
| 197 | account has: the effective right on a repository is the token's scopes |
| 198 | intersected with the account's own permission (section 5). |
| 199 | |
| 200 | A request without `Authorization` is anonymous, and reads public |
| 201 | repositories. A token that is malformed, unknown, revoked or expired, or |
| 202 | whose account is gone or suspended (section 22), is 401 `unauthorized`, |
| 203 | even on a route anonymous callers may use. |
| 204 | |
| 205 | **Accounts.** An account is a GitHub account: its login, lowercase, names |
| 206 | it, and it keeps GitHub's numeric id. A sign-in whose id differs from the |
| 207 | one an account keeps is 403 `forbidden`: a login renamed away from, or |
| 208 | reused after its account was deleted, does not take over that login's |
| 209 | repositories. A GitHub account that renamed itself signs in as a new |
| 210 | account; the old one keeps its repositories. An account made for a login |
| 211 | before it ever signed in takes the id of its first sign-in. A suspended |
| 212 | account's sign-ins and sessions are refused. |
| 213 | |
| 214 | When the hub cannot sign people in with GitHub (sign-up is not open, or |
| 215 | GitHub does not answer), its sign-in routes answer 503 `unavailable`. |
| 216 | |
| 217 | **Device flow (CLI and agents).** `braid login` runs GitHub's device flow |
| 218 | through the hub, so no browser is needed on the agent's machine: |
| 219 | |
| 220 | 1. `POST /v1/login/device`, with an empty body or `{}` → `{"poll", |
| 221 | "user_code", "verification_uri", "expires_in", "interval"}`. `poll` is an |
| 222 | opaque id the hub keeps for the flow, 64 hex digits; GitHub's device code |
| 223 | never leaves the hub. |
| 224 | 2. The person opens `verification_uri` anywhere and types `user_code`. |
| 225 | 3. `POST /v1/login/device/poll {"poll"}` every `interval` seconds → |
| 226 | `{"status": "pending"}`, `{"status": "slow_down", "interval"}`, |
| 227 | `{"status": "denied"}`, `{"status": "expired"}`, or |
| 228 | `{"status": "ok", "token", "login", "expires"}`. The token has the scope |
| 229 | `{"repo": "*", "rights": ["read", "write", "land:*"]}`, the note `braid |
| 230 | login`, and lives 90 days. A poll id the hub does not know (it forgets |
| 231 | flows when it restarts) or whose flow ended is `expired`; a second poll |
| 232 | while one is asking GitHub is `slow_down`. |
| 233 | |
| 234 | The GitHub token of a sign-in says who signed in, and is dropped. The |
| 235 | client stores the hub's token and the hub URL in `~/.config/braid/hub.json`, |
| 236 | mode 0600, or reads `BRAID_TOKEN` and `BRAID_HUB_URL` from the environment. |
| 237 | |
| 238 | **Web.** Signing up and signing in are one: the first sign-in makes the |
| 239 | account. `GET /login` works as a link from anywhere: it sends a visitor who |
| 240 | is signed out straight to GitHub's authorization page, and GitHub's answer |
| 241 | brings them back signed in, to `/`, or to `/-/onboarding` for an account |
| 242 | its first sign-in made (section 23); one signed in already goes to `/`. |
| 243 | While sign-up is not open, `GET /login` answers with a page that says so |
| 244 | (503). `GET /login` redirects to GitHub with a random `state`, which a |
| 245 | cookie keeps for ten minutes (`HttpOnly`, `SameSite=Lax`, |
| 246 | `Path=/auth/github`, signed by the hub); GitHub calls back `GET /auth/github/callback`, which goes on |
| 247 | only with that cookie and that state, exchanges the code with the app's |
| 248 | client secret, and starts a session: a random secret in the cookie |
| 249 | `braidhub_session` (`HttpOnly`, `Secure`, `SameSite=Lax`, 30 days). The hub |
| 250 | keeps it under a keyed hash of the secret, never the secret. Every form |
| 251 | carries the session's CSRF token in the field `csrf`; an API call made with |
| 252 | a session sends it in `X-CSRF-Token`. `POST /logout` (with `csrf`) ends the |
| 253 | session. Expired sessions go with the daily purge. |
| 254 | |
| 255 | **GitHub access.** Signing in asks GitHub for the account's identity only |
| 256 | (`read:user`). Importing a private GitHub repository, mirroring to one and |
| 257 | syncing the account's GitHub repositories (section 23) need repository |
| 258 | access, which the account grants in a browser or with a device flow: |
| 259 | |
| 260 | - In a browser, `GET /auth/github/repo-access?scope&next`, for the account |
| 261 | signed in (a browser signed out is sent to `/login`). `scope=private` |
| 262 | (the default) asks GitHub for `repo`: the account's private and public |
| 263 | repositories; `scope=public` asks for `public_repo`: its public ones |
| 264 | only. `next` is where the browser goes once access is granted: |
| 265 | `onboarding` (`/-/onboarding/github`), `settings` (`/settings`) or `home` |
| 266 | (`/`, the default). Any other value of either is 400, before GitHub |
| 267 | hears of anything. Both travel in the signed state of the grant, never |
| 268 | in the callback's own query: parameters added to the callback steer |
| 269 | nothing. The pages offer grants as links, since forms post to the hub |
| 270 | only. |
| 271 | - For agents and the command line, as `braid login` signs in: `POST |
| 272 | /v1/github/access/device {"scope": "private" | "public"}` → `{"poll", |
| 273 | "user_code", "verification_uri", "expires_in", "interval"}`, as `POST |
| 274 | /v1/login/device` answers; a scope that is neither is 400. The person |
| 275 | opens `verification_uri` anywhere, types `user_code` and approves, |
| 276 | signed in to GitHub as the account's GitHub account. Then `POST |
| 277 | /v1/github/access/device/poll {"poll"}` every `interval` seconds → |
| 278 | `{"status": "pending"}`, `{"status": "slow_down", "interval"}`, |
| 279 | `{"status": "denied"}`, `{"status": "expired"}`, or `{"status": "ok", |
| 280 | "login", "scope"}`, where `scope` is what GitHub granted (`repo` or |
| 281 | `public_repo`). A poll id the hub does not know, of a flow that ended, |
| 282 | of a sign-in, or of another account's grant is `expired`. An account has |
| 283 | at most three grants under way: starting a fourth ends its oldest, whose |
| 284 | poll then answers `expired`. |
| 285 | |
| 286 | A grant made as another GitHub account than the one the account signed in |
| 287 | with, and one in which GitHub granted less than was asked, are refused with |
| 288 | 403 `forbidden`, and nothing changes. A grant replaces the one before; the |
| 289 | account's mirrors that waited for one (`needs_grant`, section 11) go on. |
| 290 | The device routes, and the listing and batches of section 23, act for the |
| 291 | caller's own account: with a token that has `write` (or `admin`) on |
| 292 | `<login>/*` or `*`, |
| 293 | as the token of `braid login` has, or with a session that sends its CSRF |
| 294 | token in `X-CSRF-Token`. A token that only reads or interacts, or reaches |
| 295 | one repository only, is 403 `forbidden`; no token and no session is 401 |
| 296 | `unauthorized`. A hub that cannot reach GitHub repositories answers them |
| 297 | 503 `unavailable`. |
| 298 | |
| 299 | The hub keeps the GitHub token of a grant sealed, and uses it only for the |
| 300 | account's own imports, mirrors, webhooks and permission checks, passed to |
| 301 | `git` through the environment, never in a URL or argv. If the hub's keys |
| 302 | change, the account grants access again. |
| 303 | |
| 304 | ## 3. Accounts and tokens |
| 305 | |
| 306 | - `GET /v1/me` → `{"login", "name", "avatar_url", "github_repo_access": |
| 307 | bool, "token": {"id", "scopes", "created", "expires", "last_used", |
| 308 | "note"}, "settings": {"tdm_default", "stars_public"}, "github_scope"}`. |
| 309 | Needs a token. `settings` are the account's (below); `github_scope` holds |
| 310 | the scopes of the GitHub access the account granted (section 2), as |
| 311 | GitHub wrote them, and is left out when it granted none. |
| 312 | - `PATCH /v1/me {"tdm_default", "stars_public"}` → what `GET /v1/me` |
| 313 | gives, as it is now. `tdm_default` is `allowed` or `reserved`: what text |
| 314 | and data mining the account's new repositories start with (section 24). |
| 315 | `stars_public` says whether the repositories it starred show on its |
| 316 | profile and in `GET /v1/users/{login}/starred` to others (section 17). A |
| 317 | field left out stays as it is; any other value is 400 `invalid`. It needs |
| 318 | a token with `interact`, `write` or `admin` on `*`, and counts as a |
| 319 | change of settings toward the account's limits (section 12). |
| 320 | - `POST /v1/tokens {"note", "scopes", "expires_in_days"}` → 201 |
| 321 | `{"token", "id", "scopes", "expires"}`. The token is shown this once, and |
| 322 | acts for the same account. At least one scope (at most 100), each valid; |
| 323 | `expires_in_days` from 1 to 366; a note of at most 200 characters; an |
| 324 | account holds at most 1,000 tokens. Anything else is 400 `invalid`. |
| 325 | - `GET /v1/tokens` → `{"tokens": [{"id", "note", "scopes", "created", |
| 326 | "expires", "last_used"}]}`: the account's, oldest first. `last_used` is |
| 327 | noted at most once an hour, and left out for a token never used. |
| 328 | - `DELETE /v1/tokens/{id}` → 204: the token stops at once. 404 for a token |
| 329 | of another account, 400 for an id that is not 8 characters of `a-z 2-7`. |
| 330 | - Managing tokens (the last three) needs a token with `admin` on `*`, or a |
| 331 | session with its CSRF token in `X-CSRF-Token` (403 without it), except |
| 332 | that any token may revoke itself (`braid logout`). |
| 333 | |
| 334 | ## 4. Repositories |
| 335 | |
| 336 | Every repository has an `id`: `r_` and 26 characters of `a-z` and `2-7`, |
| 337 | given when it is made and never changed. No other repository ever takes |
| 338 | it, not even one made later under the same name. What belongs to a |
| 339 | repository (its stars, watchers, issues, change requests and the |
| 340 | notifications about them) follows its id, so a repository deleted and made |
| 341 | again under its name starts with none of it. |
| 342 | |
| 343 | - `POST /v1/repos {"name", "private": true, "description", "import": |
| 344 | "<git URL>" | null, "mirror": "<git URL>" | null}` → 201 with the |
| 345 | repository, and its URL in `Location`. The owner is the caller, whose |
| 346 | token needs `write` on `<login>/<name>`; 409 `exists` when the name is |
| 347 | taken, 403 `quota` when the caller owns as many repositories as an account |
| 348 | may (section 12). A description has at most 1,000 characters, without |
| 349 | control characters but line breaks. With `import`, the hub |
| 350 | takes the remote's history before it answers (a `git sync --direction |
| 351 | follow` of the remote's default branch, which becomes the repository's |
| 352 | default branch), with the owner's GitHub access when it has one; an |
| 353 | import that fails is 400, one that leaves the owner's repositories |
| 354 | storing more than an account may is 403 `quota`, and neither leaves a |
| 355 | repository. Until the import is done, the repository answers as a |
| 356 | missing one to everyone but its owner. With `mirror`, every |
| 357 | landing on the default branch is then published there (section 11). |
| 358 | `import` and `mirror` are GitHub repositories, `https://github.com/ |
| 359 | <owner>/<name>`, with or without `.git` (400 otherwise); a mirror needs |
| 360 | the owner's GitHub repository access (section 2; 400 without it), and a |
| 361 | GitHub repository that another repository of the hub has as its mirror |
| 362 | is 409 `exists` (section 11). The repository's `tdm` is its owner's |
| 363 | `tdm_default` (section 3). |
| 364 | - `GET /v1/repos` → `{"repos": [...]}`: the repositories the caller owns, |
| 365 | those it is a collaborator of, and those mirrored on GitHub that GitHub |
| 366 | lets it write to or administer, in order of owner and name, at most |
| 367 | `max_list` (section 12). Each shows the caller's permission on it within |
| 368 | the token's scopes (section 5); a repository the token cannot read is not |
| 369 | listed. A change of collaborators shows at once. Listing never asks |
| 370 | GitHub: a repository that only GitHub shares with the caller is listed on |
| 371 | the terms of section 5, once a request of the caller's needed GitHub's |
| 372 | answer about it, as opening the repository does, and for as long as the |
| 373 | hub keeps that answer, with the permission GitHub gave. Needs a token. |
| 374 | - `GET /v1/r/{owner}/{name}` → `{"id", "owner", "name", "private", |
| 375 | "description", "default_branch", "created", "mirror": {"url", |
| 376 | "last_sync", "outcome", "detail", "follow", "github_id", "synced", |
| 377 | "hook"} | null, "permission": "read" | "write" | "admin", "topics", |
| 378 | "fork_of": {"owner", "name"} | null, "tdm": "allowed" | "reserved", |
| 379 | "pushed", "counts": {"stars", "forks", "watchers", "open_issues", |
| 380 | "open_requests"}, "viewer": {"starred", "watching"}, "settings": |
| 381 | {"issues", "requests_from", "allow_forks", "require_approvals", |
| 382 | "mirror_follow"}}`: |
| 383 | - `topics`: what it is about (below); `tdm`: whether its owner reserves |
| 384 | text and data mining of it (section 24). |
| 385 | - `fork_of`: the repository it was forked from (section 20), when the |
| 386 | caller may read that one, `null` otherwise. |
| 387 | - `pushed`: when one of its refs last moved: the last landing, to within |
| 388 | a minute (several landings within a minute leave the time of the |
| 389 | first), or the history an import or a fork brought; `null` while it |
| 390 | holds nothing. |
| 391 | - `counts`, to whoever reads it: `stars`, the accounts that starred it |
| 392 | (section 17); `forks`, its public forks, as a private fork counts for |
| 393 | nobody (section 20); `watchers`, the accounts that watch all of it, its |
| 394 | owner among them unless it chose otherwise; `open_issues` and |
| 395 | `open_requests` (sections 18 and 19). |
| 396 | - `viewer`, to a signed-in caller: whether it starred the repository, and |
| 397 | how it watches it (`all`, `participating` or `ignore`, section 17). |
| 398 | - `settings`, to its admins: whether it takes issues (section 18), who |
| 399 | may open change requests and how many approvals one needs before it |
| 400 | lands (section 19), whether it may be forked (section 20), and how its |
| 401 | mirror follows GitHub (section 11; `null` without a mirror). |
| 402 | |
| 403 | This route, `PATCH` and `POST …/mirror/sync` answer the repository whole. |
| 404 | The other routes that answer a repository (`POST /v1/repos`, `GET |
| 405 | /v1/repos`, `POST …/mirror/follow`) leave out `counts`, `viewer` and |
| 406 | `settings`, and give `fork_of` and `pushed` as `null`. |
| 407 | - `PATCH /v1/r/{owner}/{name}` with any of these → the repository. |
| 408 | `admin`. |
| 409 | - `private`. A fork of a private repository, or of a fork of one, stays |
| 410 | private: `false` is 400 `invalid` (section 20). Making a repository |
| 411 | public makes everything it ever stored readable by anyone who knows its |
| 412 | ids (section 6), not only what its branches hold now: its whole |
| 413 | history, branches deleted since, uploads that never landed, and its |
| 414 | issues and change requests with their comments. A fresh public |
| 415 | repository is the way to publish only what one holds now. A repository |
| 416 | that turns private leaves every list, search and count of those who |
| 417 | may no longer read it at once. |
| 418 | - `description`, as for `POST /v1/repos`. |
| 419 | - `mirror`: a new mirror, as for `POST /v1/repos`; `""` removes it. |
| 420 | - `default_branch`: a git branch name outside braid's own refs (`braid/`, |
| 421 | `git/`, `remote/`, `tags/`). A new mirror, or a new default branch with |
| 422 | a mirror, is published at once. |
| 423 | - `topics`: the whole list, which replaces the old one, each topic once: |
| 424 | at most 20 (`topics` of `limits.social`), each 1 to 50 (`topic`) of |
| 425 | lowercase letters, digits and `-`, starting with a letter or a digit. |
| 426 | - `tdm`: `allowed` or `reserved` (section 24). |
| 427 | - `issues`: `true` or `false`, whether it takes new issues and comments |
| 428 | on them; turned off, what it holds is read as before (section 18). |
| 429 | - `requests_from`: `readers` (the default), `collaborators` (its owner |
| 430 | and collaborators) or `off`: who opens change requests (section 19). |
| 431 | - `allow_forks`: `true` or `false`; yes by default for a public |
| 432 | repository, no for a private one (section 20). |
| 433 | - `require_approvals`: 0 to 10, how many approvals of a change request's |
| 434 | current revision it needs before it lands; it applies to change |
| 435 | requests only, never to `POST …/land` (section 19). |
| 436 | - `mirror_follow`: `off`, `ff-only` or `merge` (section 11). On a |
| 437 | repository without a mirror it is 400 `invalid`; a new mirror URL |
| 438 | starts again at `off`, unless the same `PATCH` sets it too. |
| 439 | |
| 440 | Any other value is 400 `invalid`, and nothing changes. A `PATCH` that |
| 441 | names a field counts as a change of settings toward the account's limits |
| 442 | (section 12), as each change of collaborators does. |
| 443 | - `GET /v1/r/{owner}/{name}/collaborators` → `{"collaborators": [{"login", |
| 444 | "permission"}]}`, by login. `PUT |
| 445 | /v1/r/{owner}/{name}/collaborators/{login} {"permission"}` (`read`, |
| 446 | `write` or `admin`) → 204, and `DELETE …/collaborators/{login}` → 204, |
| 447 | also for a login that is not a collaborator. The owner is not one (400). |
| 448 | At most 1,000. `admin`. Whoever a change leaves unable to read the |
| 449 | repository loses it at once: its lists and its inbox no longer show the |
| 450 | repository (section 21). |
| 451 | - `DELETE /v1/r/{owner}/{name}` → 204. `admin`. The repository is moved |
| 452 | aside, not erased, and kept 30 days, counting toward its owner's quota |
| 453 | until then (section 12); the name is free at once. A task that runs when |
| 454 | the hub starts and once a day removes what was deleted longer ago. What |
| 455 | belonged to it (its stars, watchers, issues, change requests and their |
| 456 | notifications) goes with it. |
| 457 | |
| 458 | ## 5. Permissions |
| 459 | |
| 460 | An account's permission on a repository is the highest of: |
| 461 | |
| 462 | - `admin` for its owner; |
| 463 | - what a collaborator entry gives it; |
| 464 | - `read` for anyone, signed in or not, on a public repository; |
| 465 | - for a repository whose mirror is on GitHub, what GitHub lets the same |
| 466 | login push there: `admin` for admin, `write` for maintain and write. |
| 467 | Triage and read give nothing: GitHub may say read of anyone for a public |
| 468 | repository, and the hub's repository holds every branch, where the mirror |
| 469 | holds only one. The hub asks with the GitHub access the owner granted |
| 470 | (none granted, nothing given). |
| 471 | |
| 472 | The hub asks GitHub only when the rest gives the account less than a |
| 473 | request needs: reading a public repository never asks it, and neither does |
| 474 | anything the owner or a collaborator entry already allows. It keeps each |
| 475 | answer ten minutes (a failure to ask, one minute). What pages and answers |
| 476 | show (the `permission` of a repository, links such as the repository a fork |
| 477 | came from, buttons, list rows) comes from what the hub knows already, and |
| 478 | asks GitHub nothing: a permission that comes from GitHub shows once a |
| 479 | request needed GitHub's answer, for as long as the hub keeps it, and lists |
| 480 | include such a repository on the same terms. |
| 481 | |
| 482 | GitHub limits how many requests the owner's access makes in an hour. While |
| 483 | GitHub says fewer than 500 are left, the hub asks it nothing for other |
| 484 | accounts until the limit resets; and one account makes at most 100 |
| 485 | questions in any hour on the access of one owner. A question not asked gives |
| 486 | nothing: a repository only GitHub would open answers 404, and a write only |
| 487 | GitHub would allow answers 403. The owner's own work is not held back. |
| 488 | |
| 489 | Before any of that, some repositories give nothing at all: |
| 490 | |
| 491 | - the repositories of a suspended account answer 404 to everyone, as if |
| 492 | they did not exist (section 22); |
| 493 | - a repository taken down, or still being filled by an import, answers 404 |
| 494 | to everyone but its owner; |
| 495 | - a fork of a private repository stays private, and only those who may |
| 496 | read the repository it was forked from read it, and that one's upstream |
| 497 | in turn, up to eight forks up; to anyone else it answers 404, whatever its |
| 498 | own collaborators say, its owner included. What counts is what the |
| 499 | account may read: a token whose scopes reach the fork alone reads it when |
| 500 | its account reads every repository up the line. When its upstream is |
| 501 | deleted it answers 404 to everyone; a repository made later under the |
| 502 | upstream's name is another, and changes nothing. |
| 503 | |
| 504 | `read` covers reading: every `GET` and `HEAD` of a repository but those of |
| 505 | its collaborators and its blocks, `POST …/missing`, `POST …/lacks`, the ref |
| 506 | watch, and checking a change request; `interact` covers taking part |
| 507 | (below); `write` covers uploads and managing issues and change requests |
| 508 | (sections 18 and 19); landing on a ref needs `write` and a `land:<glob>` |
| 509 | right whose glob matches the ref (`*` matches anything, `release/*` one |
| 510 | level); posting a verdict needs a `verify:<glob>` right whose glob matches |
| 511 | the default branch, of an account that may write to the repository, as the |
| 512 | rules above say, GitHub's answer included, on a token that holds nothing |
| 513 | more there than `read` (section 25); `admin` covers the settings, the |
| 514 | policy of verification and its resets, the collaborators, the repository's |
| 515 | blocks and deleting. A token's rights are cut down to its account's |
| 516 | permission, never below what anyone may do: any token reads a public |
| 517 | repository, where the rules above let anyone read it. A web session has |
| 518 | all its account may do. |
| 519 | |
| 520 | Interacting with a repository (starring, watching, opening issues and |
| 521 | change requests, commenting, reviewing, forking) needs an account that may |
| 522 | read it, that is not suspended and that is not blocked there (section 22), |
| 523 | through a web session or a token with a scope that reaches the repository |
| 524 | with `interact`, `write` or `admin`. A token that reads a public repository |
| 525 | only because anyone may does not interact with it, and an anonymous caller |
| 526 | never does (401). A repository the caller may not read answers 404 here |
| 527 | too, as a missing one does; one it reads but may not interact with, 403. |
| 528 | Following and blocking accounts need a web session, or a token with |
| 529 | `interact`, `write` or `admin` on `*`. |
| 530 | |
| 531 | ## 6. Objects |
| 532 | |
| 533 | Objects are immutable and named by their braid id, so every read is |
| 534 | cacheable forever. |
| 535 | |
| 536 | - `GET /v1/r/{owner}/{name}/o/{id}` → the payload, `Content-Type: |
| 537 | application/octet-stream`, `Braid-Kind: blob | tree | changeset | |
| 538 | chunklist | derived`, `ETag: "<id>"`, `Cache-Control: public, max-age=31536000, |
| 539 | immutable` (`private` for a private repository). 404 when absent. A blob |
| 540 | is always its whole content, however the store keeps it. `HEAD |
| 541 | /v1/r/{owner}/{name}/o/{id}` gives the same headers and |
| 542 | `Content-Length`. `If-None-Match` with the tag gives 304. |
| 543 | - `PUT /v1/r/{owner}/{name}/o/{id}` with `Braid-Kind` and the payload → |
| 544 | 204. The hub hashes the payload as that kind and refuses a mismatch, a |
| 545 | missing or unknown kind (400 `invalid`). At most 64 MiB (413); larger |
| 546 | objects go through the stream. Idempotent. |
| 547 | - `POST /v1/r/{owner}/{name}/lacks {"ids": [...]}` (at most 10,000, 413 |
| 548 | beyond) → `{"lacks": [...]}`: the ids of the list the hub does not store, |
| 549 | in the order asked, each once. |
| 550 | - `POST /v1/r/{owner}/{name}/objects`, `Content-Type: |
| 551 | application/x-braid-objects`, body an object stream (section 7) → 200 |
| 552 | `{"stored": n}`. Each record is hashed and checked like a `PUT`. Another |
| 553 | media type, a stream that is truncated, holds a bad record or an unknown |
| 554 | kind, or goes on after its terminator is 400 `invalid`; a body over |
| 555 | 256 MiB, or a record announcing more, is 413. The records before a bad |
| 556 | one are kept: each was checked before it was stored. |
| 557 | - `POST /v1/r/{owner}/{name}/missing` → what a client needs to hold the |
| 558 | wanted changesets: |
| 559 | |
| 560 | ```json |
| 561 | {"want": ["<changeset id>"], "have": ["<changeset id>"], "history": null, |
| 562 | "paths": null, "limit": 10000, "after": null} |
| 563 | ``` |
| 564 | |
| 565 | `want` names changesets the hub holds (404 for one it does not, 400 for |
| 566 | an id of another kind). `have` lists changesets the client holds with |
| 567 | everything they reach (the hub ignores ids it does not know). Each holds |
| 568 | at most 10,000 ids (413). `history` is `null` for every ancestor, `0` for |
| 569 | the wanted changesets alone, `n` for n generations along all parents. |
| 570 | `paths`, when given, limits trees to those path prefixes (at most 1,000; |
| 571 | leading and trailing `/` are ignored; the trees on the way are always |
| 572 | included). The walk takes, for each changeset, the changeset, its |
| 573 | external change list, its git origin, and every tree node and blob of its |
| 574 | root tree, skipping anything reachable from a `have` changeset's root |
| 575 | tree, and lists parents before children only in that a changeset comes |
| 576 | before the objects it names. The response is `{"missing": [{"id", "kind", |
| 577 | "size"}], "next": "<cursor>" | null}`, paged by `limit` (default 10,000, |
| 578 | at most 100,000; 0 is 400) and `after`, the `next` of the page before. |
| 579 | Each page walks again; a cursor that does not belong to the walk (another |
| 580 | request, or a walk that changed meanwhile) is 400 `invalid`: start again |
| 581 | without it. A walk lists at most 1,000,000 objects, counting the trees of |
| 582 | `have`; a larger one is 413 `too_large`: ask for less history, for fewer |
| 583 | paths, or give what you hold in `have`. With `Accept: |
| 584 | application/x-braid-objects` the same request returns the objects |
| 585 | themselves as an object stream, unpaged (`limit` and `after` do not |
| 586 | apply); a failure half-way ends it without its terminator. |
| 587 | |
| 588 | What a change request from another repository brings is not the target's |
| 589 | until it lands: these routes of the target never serve it, and the |
| 590 | request's own routes do (section 19). |
| 591 | |
| 592 | ## 7. The object stream |
| 593 | |
| 594 | `application/x-braid-objects`: the 10 bytes `BRAIDOBJ1\n`, then records, |
| 595 | then a terminator. |
| 596 | |
| 597 | - A record: 1 byte kind code (1 blob, 2 tree, 3 changeset, 4 chunklist, |
| 598 | 5 derived), the 32-byte id, the payload length as a little-endian u64, |
| 599 | then the payload. |
| 600 | - The terminator: one byte 0. A stream without it is truncated and refused. |
| 601 | |
| 602 | A reader checks every record's id against its kind and payload before using |
| 603 | it. |
| 604 | |
| 605 | ## 8. Refs and landing |
| 606 | |
| 607 | - `GET /v1/r/{owner}/{name}/refs` → `{"seq": n, "refs": {"<name>": |
| 608 | "<id>"}}`: the op log sequence number (0 before the first operation) and |
| 609 | every ref, the hub's own included. Of those, `braid/green/<branch>` and |
| 610 | `braid/red/<branch>` say how the hub verifies a repository's default |
| 611 | branch (section 25): green at the newest changeset with a pass the hub |
| 612 | accepts and, while the branch is red, red at the changeset the hub |
| 613 | blames, or at the first fail it cannot explain. Only the hub moves them, |
| 614 | each move an operation of its own: a client can neither land on them nor |
| 615 | delete them, they are never exported to git, and forks never copy them. |
| 616 | `braid hub fetch` records where it saw them, as |
| 617 | `remote/hub/braid/green/<branch>` and `remote/hub/braid/red/<branch>`, |
| 618 | and never takes them as refs of its own. |
| 619 | - `GET /v1/r/{owner}/{name}/refs/watch` → `text/event-stream`. Each change |
| 620 | is an event `refs` with `id: <seq>` and the same body as `GET refs`: |
| 621 | |
| 622 | ```text |
| 623 | event: refs |
| 624 | id: 12 |
| 625 | data: {"seq":12,"refs":{"main":"<id>"}} |
| 626 | ``` |
| 627 | |
| 628 | The first event is the current state. `Last-Event-ID` resumes: when it is |
| 629 | the current sequence number, the first event is left out, and otherwise |
| 630 | it is the current state, which holds every ref, so it is all a client |
| 631 | that missed events needs. A comment line (`: keep-alive`) every 15 |
| 632 | seconds keeps the stream open; changes made outside the hub's own |
| 633 | landings show up by then. The stream ends when the hub stops. |
| 634 | - `DELETE /v1/r/{owner}/{name}/refs/{ref}?expect=<id>` → 204: a compare |
| 635 | and swap, which deletes the ref only if it points to `expect`. It needs |
| 636 | `write` and a `land:<glob>` right matching the ref (403). `{ref}` may |
| 637 | hold `/`, each part percent-encoded. A missing or malformed `expect`, one |
| 638 | of the hub's own refs (`braid/`, `remote/`), or the default branch while |
| 639 | a mirror publishes it is 400; a ref that does not exist is 404 and one |
| 640 | that points elsewhere 409 `moved`. It takes its turn in the ref's queue, |
| 641 | and watchers get a `refs` event. |
| 642 | - `POST /v1/r/{owner}/{name}/land`: |
| 643 | |
| 644 | ```json |
| 645 | {"ref": "main", "changes": ["<id>", "..."], "mode": "rebase", "agent": "agent-1"} |
| 646 | ``` |
| 647 | |
| 648 | Landing needs `write` and a `land:<glob>` right matching the ref (403). |
| 649 | The ref is a braid ref name outside `braid/` and `remote/` (400 otherwise). |
| 650 | `changes` is a stack of 1 to 10,000 changesets (413 beyond), oldest |
| 651 | first: each one's first parent is the one before it, and the first one's |
| 652 | is on the ref's first-parent chain (or the ref does not exist yet). |
| 653 | `agent`, 1 to 100 characters without control characters, names who lands |
| 654 | in the op log, as `<login>/<agent>` (`<login>` without it). |
| 655 | |
| 656 | The hub admits every changeset first, and every ancestor of them it has |
| 657 | not admitted yet, oldest first: its change list is canonical, its root |
| 658 | tree is its first parent's with the changes applied, and every object it |
| 659 | names is stored. One 409 `missing` lists everything the hub lacks for the |
| 660 | stack: the changesets it does not have, or when it has them all, their |
| 661 | change lists, git origins, blobs and the tree nodes their changes |
| 662 | rebuild. A changeset that can never be admitted (a root its changes do |
| 663 | not give, a change list that is not canonical, an id of another kind) is |
| 664 | 400 `invalid`, saying why. Then one task per ref lands the stack in turn |
| 665 | with the others: |
| 666 | - `mode: "rebase"` (the default) fast-forwards when the first change's |
| 667 | base is the head, and otherwise rebases the stack onto the head, path by |
| 668 | path, as `braid land` does; when the first change's base is not on the |
| 669 | ref's first-parent chain, it answers 409 `not_on_branch`; |
| 670 | - `mode: "ff-only"` fast-forwards only: when neither the first change's |
| 671 | first parent nor any change of the stack is the head, it answers |
| 672 | `refused` with the head. |
| 673 | |
| 674 | On a ref that does not exist, either mode creates it at the last change. |
| 675 | A list that is empty or is not a stack is 400 `invalid`. Landing the same |
| 676 | stack again returns `already-applied`. The response (200 in every other |
| 677 | case): |
| 678 | |
| 679 | ```json |
| 680 | {"ref": "main", "outcome": "fast-forward | rebased | already-applied | conflicts | refused", |
| 681 | "head_before": "<id>|null", "head": "<id>|null", |
| 682 | "landed": [{"from": "<id>", "to": "<id>|null"}], |
| 683 | "merged_paths": [], "conflicts": [], "change": "<id>|null", |
| 684 | "git_commit": "<sha1>|null", "operation": 12} |
| 685 | ``` |
| 686 | |
| 687 | `conflicts` uses the same objects as `braid land --json` (`path`, `kind`, |
| 688 | `base`, `branch`, `workspace`, `hunks`), from the stack's point of view; |
| 689 | every field but `git_commit` is what `braid land --json` gives for the |
| 690 | same situation. `head` is the head after the landing (the head before |
| 691 | when it did not move, as with `refused`), and `operation` is `null` when |
| 692 | the ref did not move. `git_commit` is the git commit the head exports to, |
| 693 | computed as `braid git export` does, so a git mirror holds exactly that |
| 694 | commit. History imported from git and uploaded exports to its original |
| 695 | commits: the hub checks each against the canonical tree of its root and |
| 696 | the commits of its parents. It is `null` when the hub cannot export the |
| 697 | head, such as history whose git trees are not canonical (only the map of |
| 698 | the repository that imported them reproduces those), and never a commit |
| 699 | the head would not export to. |
| 700 | |
| 701 | A landing on the default branch of a repository whose verification is |
| 702 | on (section 25), a change request's landing included, also carries |
| 703 | `verify`: how the branch stands once the landing is done, from the |
| 704 | hub's last decision, which the landing does not wait for: `green` turns |
| 705 | to `pending` when the landing put changesets above green, and a red |
| 706 | branch stays red. |
| 707 | |
| 708 | ```json |
| 709 | "verify": {"state": "red", "green": "<id>|null", "red": "<id>|null", |
| 710 | "culprit": "<id>|null", "reverted": []} |
| 711 | ``` |
| 712 | |
| 713 | Its fields are those of `GET …/verify`; `reverted` is empty in this |
| 714 | version of the protocol. `verify` is left out of any other landing, and |
| 715 | out of every landing on a hub that does not verify branches. braid gives |
| 716 | it as `hub_verify` with `--json`, and says on standard error when the |
| 717 | branch is red or stuck. |
| 718 | |
| 719 | Changesets the hub rebases keep their author, message and extras, with |
| 720 | `rebased-from` added, and name the hub as their committer: `BraidHub |
| 721 | <noreply@<host of the hub's URL>>`. The hub admits them too. A landing is |
| 722 | durable before its answer, and a landing that moved the ref sends a |
| 723 | `refs` event to every watcher. |
| 724 | |
| 725 | A landing that moves the repository's default branch closes the open |
| 726 | issues that the messages of its changesets close with closing words |
| 727 | (section 1: `Fixes #4`, outside code). Each closes as `completed`, by the |
| 728 | account that landed, naming the changeset (`closed_by_changeset`, |
| 729 | section 18). A landing on any other ref closes nothing. |
| 730 | |
| 731 | ## 9. Git |
| 732 | |
| 733 | - `GET /v1/r/{owner}/{name}/git/commit/{sha1}` → `{"changeset", "tree", |
| 734 | "git_tree"}` for a commit the repository knows (imported, or the export |
| 735 | of one of its changesets); 404 otherwise. The exports a repository knows |
| 736 | are those of every head landed on it and their history, computed again |
| 737 | when asked after the hub restarts. |
| 738 | - `GET /v1/r/{owner}/{name}/git/changeset/{id}` → `{"changeset", |
| 739 | "git_commit"}`: the commit a changeset exports to, as a landing's |
| 740 | `git_commit` says, without landing again; 404, saying why, when the hub |
| 741 | does not have the changeset or cannot export it. |
| 742 | - `GET /v1/r/{owner}/{name}/git/o/{sha1}` → the git object's content, |
| 743 | without git's `<type> <size>\0` header, with `Git-Kind: commit | tree | |
| 744 | blob | tag`. A client that cares recomputes the SHA-1 itself: the hub's |
| 745 | answer is never trusted for it. |
| 746 | - All three are immutable: their `Cache-Control` is that of the objects |
| 747 | (section 6), `public` or `private` with the repository; `git/o` answers |
| 748 | `application/octet-stream`. |
| 749 | |
| 750 | ## 10. Trees |
| 751 | |
| 752 | `GET /v1/r/{owner}/{name}/t/{tree}?prefix=src/net&depth=2` → `{"tree", |
| 753 | "prefix", "entries": [{"path", "kind", "id", "size", "truncated"}]}`, where |
| 754 | `kind` is `file`, `executable`, `symlink`, `tree` or `gitlink`, `size` is |
| 755 | given for files, executables and symlinks, and `truncated: true` marks a |
| 756 | directory below `depth`, whose entries are not listed. `prefix` names a |
| 757 | directory of the tree (none for the tree itself; leading and trailing `/` |
| 758 | are ignored); 404 when it is not one. `depth`, 1 (the default) to 64, is |
| 759 | how many levels below the prefix are listed. Entries come in name order, |
| 760 | each directory followed by what it holds; `path` starts at the tree listed, |
| 761 | so it begins with the prefix. A gitlink's `id` is its commit in hex. At most |
| 762 | 100,000 entries (413 beyond). A tree the hub does not have is 404. |
| 763 | Immutable, like the objects. Section 15 reads a revision's files by path. |
| 764 | |
| 765 | ## 11. Mirrors |
| 766 | |
| 767 | A repository with a mirror publishes its default branch there after each |
| 768 | landing on it, with `git sync --direction publish` and the owner's GitHub |
| 769 | access: the push is a fast-forward with a lease, and the remote's history is |
| 770 | never rewritten. Publishing runs after the landing's answer, one at a time |
| 771 | per repository: landings during a publish fold into one more. A publish |
| 772 | that fails (git cannot reach the mirror, or the mirror moved during the |
| 773 | push) is tried again a second later, then twice as long after each failure, |
| 774 | at least every five minutes, until it goes through, and when the hub |
| 775 | starts. So is one still waiting when the hub stopped: when it starts, the |
| 776 | hub also publishes each mirror whose default branch moved since its last |
| 777 | sync went through. |
| 778 | |
| 779 | **Following GitHub.** A mirror can follow GitHub as well as receive the |
| 780 | hub's landings. `PATCH /v1/r/{owner}/{name}` (`admin`) takes |
| 781 | `mirror_follow`: |
| 782 | |
| 783 | - `off` (the default for a mirror set by hand): the hub publishes each |
| 784 | landing on the default branch, and takes nothing in by itself. When |
| 785 | someone pushed to the mirror directly, the sync stops with `diverged`; |
| 786 | the hub records it, shows it on the repository's page, and keeps |
| 787 | landing. The owner settles it by moving the remote back, or by taking |
| 788 | the remote's commits in: `POST /v1/r/{owner}/{name}/mirror/follow` |
| 789 | (`admin`) syncs the default branch with the mirror both ways, so the |
| 790 | branch fast-forwards to the mirror's commits when it has nothing new, |
| 791 | and otherwise merges them (the hub is the merge's committer) and |
| 792 | publishes the merge; conflicts move nothing. It answers the repository, |
| 793 | with the outcome in its `mirror`, after the sync, in the branch's queue. |
| 794 | - `ff-only`: the hub also takes in what is pushed to the mirror, by |
| 795 | fast-forwarding its default branch, when it has landed nothing GitHub |
| 796 | lacks. When both moved, nothing moves: the outcome is `diverged`, and |
| 797 | the repository's admins are told in their inbox (section 21). |
| 798 | - `merge`: the hub takes in what is pushed to the mirror, and when both |
| 799 | moved it merges them (the hub is the merge's committer) and publishes |
| 800 | the merge. Conflicts move nothing: the outcome is `conflicts`, the hub |
| 801 | publishes nothing more until a sync goes through, and the admins are |
| 802 | told. |
| 803 | |
| 804 | Repositories brought in from GitHub by syncing them (section 23) follow |
| 805 | with `merge` unless the sync says otherwise. `mirror_follow` on a |
| 806 | repository without a mirror is 400 `invalid`; a new mirror URL starts |
| 807 | again at `off`, unless the same `PATCH` sets `mirror_follow` too. `POST |
| 808 | …/mirror/sync` (section 23) looks at the mirror at once. |
| 809 | |
| 810 | **What both sides hold.** The mirror keeps `synced`: the git commit both |
| 811 | sides held after its last publish, follow or import. A publish runs only |
| 812 | when the default branch moved since, and a follow only when GitHub's head |
| 813 | is another commit: the push the hub makes itself, coming back from GitHub, |
| 814 | changes nothing, so the two sides never chase each other. |
| 815 | |
| 816 | **A rewritten history is never merged back.** When GitHub's branch no |
| 817 | longer descends from `synced`, someone rewrote its history (a force |
| 818 | push). The hub records `rewritten`, stops following and publishing, tells |
| 819 | the admins, and merges nothing, since a merge would bring back what the |
| 820 | rewrite took out; `POST …/mirror/follow` refuses it as well, with the same |
| 821 | outcome. The way out is on GitHub: put the commit `synced` names back in |
| 822 | the branch's history (push it again, or merge it in), then sync now |
| 823 | (section 23); or point the mirror at another repository, or take it off. |
| 824 | |
| 825 | **One repository here per repository there.** A GitHub repository, named |
| 826 | in any case, with or without `.git` or a trailing `/`, is the mirror of at |
| 827 | most one repository of the hub: setting it as the mirror of another, with |
| 828 | `POST /v1/repos` or `PATCH`, is 409 `exists`, until the repository that |
| 829 | holds it lets it go or is deleted. The GitHub repository's numeric id |
| 830 | counts too, so that a renamed repository stays one: a repository that |
| 831 | names a renamed GitHub repository's new address before the hub has found |
| 832 | the rename is marked `duplicate` once it does, and the repository that |
| 833 | held it keeps it. |
| 834 | |
| 835 | **How the hub hears of pushes.** A mirror that follows gets a webhook on |
| 836 | the GitHub repository when the owner administers it there; otherwise the |
| 837 | hub asks GitHub now and then: every ten minutes, hourly once GitHub's |
| 838 | branch has not moved for a week, every six hours while a webhook works, |
| 839 | and less often after failures. A webhook only says when to look: what is |
| 840 | taken in is fetched from GitHub, as always. When the mirror stops |
| 841 | following, moves to another repository, or its repository is deleted, the |
| 842 | hub deletes its webhook. |
| 843 | |
| 844 | **The owner's access.** The hub reaches GitHub with the access the owner |
| 845 | granted (section 2). When GitHub refuses it (revoked, expired, or not |
| 846 | reaching that far), the outcome is `needs_grant`, the account's mirrors |
| 847 | neither publish nor follow, not even by `POST …/mirror/follow`, and the |
| 848 | account is told; granting access again, at `/auth/github/repo-access`, |
| 849 | lets them go on, and what waited is published. |
| 850 | |
| 851 | **Renames.** A mirror whose address finds nothing is looked up on GitHub |
| 852 | by its id: renamed or transferred, the mirror follows the new name, and |
| 853 | `url` says it; deleted, or no longer shown to the owner's access, the |
| 854 | outcome is `gone` and the hub stops following it. |
| 855 | |
| 856 | `GET /v1/r/{owner}/{name}` reports the mirror in `mirror`: |
| 857 | |
| 858 | - `url`; `last_sync`, when the last sync ran; `outcome`: `pushed`, |
| 859 | `created` (the branch was made on the mirror), `up_to_date`, `merged`, |
| 860 | `fast_forwarded`, `diverged`, `remote_moved`, `rejected`, `conflicts`, |
| 861 | `failed` (git could not reach the mirror, or refused), `rewritten`, |
| 862 | `needs_grant`, `duplicate` (another repository of the hub mirrors that |
| 863 | GitHub repository: this one neither publishes nor follows, and `POST |
| 864 | …/mirror/follow` takes nothing in) or `gone`; and `detail`, what went |
| 865 | wrong. |
| 866 | - `follow`: `ff-only` or `merge`; absent is `off`. |
| 867 | - `synced`: the commit both sides held after the last publish, follow or |
| 868 | import, as 40 hex digits. |
| 869 | - `github_id`: the GitHub repository's numeric id, once the hub knows it. |
| 870 | - `hook`: how the hub hears of pushes: `webhook`, `polling`, or `pending` |
| 871 | while it asks GitHub for a webhook; absent when the mirror does not |
| 872 | follow. |
| 873 | |
| 874 | `settings.mirror_follow` (admins) says the policy too. What the hub |
| 875 | imports or takes in from a mirror counts as admitted. |
| 876 | |
| 877 | Git runs with none of the machine's or the user's settings, no prompt or |
| 878 | credential helper, no redirect, HTTPS only, no hooks, and in bare |
| 879 | repositories only: nothing of a repository runs on the hub. The owner's |
| 880 | GitHub token reaches git as an `Authorization` header for |
| 881 | `https://github.com/` alone, through the environment. |
| 882 | |
| 883 | ## 12. Limits |
| 884 | |
| 885 | Per token, and per address for requests without one: requests per minute, |
| 886 | bytes served per day, and open watches. A limit reached answers 429 |
| 887 | `rate_limited`, with `retry_after` seconds in the body and in `Retry-After`. |
| 888 | The limits are 6,000 requests a minute for a token and 600 for an address, |
| 889 | refilled evenly (one back every sixtieth of the limit); 100 GiB a day for a |
| 890 | token and 10 GiB for an address, counted as answers are sent, over a day |
| 891 | that starts with the first byte; 64 open watches for a token and 16 for an |
| 892 | address. A request counts for its token when the hub has that token (a |
| 893 | made-up one counts for its address). The address is the one the request |
| 894 | came from. `GET /healthz` is never limited. Counts start again when the hub |
| 895 | restarts. |
| 896 | |
| 897 | Some requests count for more than one against the requests a minute, for |
| 898 | the work they cost the hub: explore, search and topics, their pages and |
| 899 | their routes (`GET /v1/explore`, `/v1/topics`, `/v1/topics/{topic}`), 10; |
| 900 | diffs and comparisons (`…/changesets/{rev}/diff`, `…/compare`, the diff of |
| 901 | a change request, the pages that compare a head for a new request, and |
| 902 | their pages), 10; the log (`…/log`) and the pages of commits, 5; a verdict |
| 903 | (`…/verify/report`) and the log of verification (`…/verify/log`), 5; |
| 904 | checking and landing a change request (`…/requests/{n}/check`, |
| 905 | `…/requests/{n}/land`), 20. A request that costs more than a whole minute's |
| 906 | limit waits for the whole minute's budget, and then goes through. Webhook |
| 907 | deliveries (`POST /v1/hooks/github/{key}`) are not limited per address, |
| 908 | since GitHub sends every delivery from a few addresses: their route limits |
| 909 | them per hook (section 23). A request that shows a token counts for its |
| 910 | token there too. |
| 911 | |
| 912 | **Account quotas.** Anyone with a GitHub account may sign up, so each account |
| 913 | owns at most 100 repositories (`POST /v1/repos` is 403 `quota` beyond), and |
| 914 | its repositories store at most 10 GiB together, counted for the owner |
| 915 | whoever uploads: an upload (`PUT …/o/{id}`, `POST …/objects`) or an import |
| 916 | that would pass it is 403 `quota`. What an account stores is the size of |
| 917 | the files of its repositories, their git mirrors included, and of the |
| 918 | repositories it deleted, until the purge erases them (section 4); it is |
| 919 | measured at most every half minute per account, with what was uploaded |
| 920 | since added on top, a body without `Content-Length` by what it carried. An |
| 921 | upload counts from its start, with its body's `Content-Length` (one without |
| 922 | counts as its route's size), so that uploads at once do not pass the cap |
| 923 | together; one under way may pass it by its own size. An import that fails |
| 924 | or is refused leaves nothing behind. A fork's job reserves, from the |
| 925 | account's storage, what its upstream stores, from when it is asked for |
| 926 | until it ends, and the jobs and imports under way count toward the |
| 927 | repositories it owns (sections 20 and 23). What a change request from |
| 928 | another repository brings counts for the request's author until it lands |
| 929 | (section 19). |
| 930 | |
| 931 | **Social writes.** Each account may make so many of each kind of social |
| 932 | write. Every token and the web session of an account spend one budget, so |
| 933 | that more tokens buy no more writes. The hourly limits refill evenly, one |
| 934 | write back every hour-th of the limit, so a burst need not wait for the |
| 935 | hour to turn; the daily ones count per UTC day. An account made on the hub |
| 936 | less than seven days ago, or whose GitHub account is less than thirty days |
| 937 | old, gets a quarter of each limit, and at least one write. A limit reached |
| 938 | answers 429 `rate_limited`, with `retry_after` the seconds until the write |
| 939 | would go through. |
| 940 | |
| 941 | | Writes | Limit | |
| 942 | |---|---| |
| 943 | | Starring and unstarring | 120 an hour, 1,000 a day | |
| 944 | | Following and unfollowing | 60 an hour, 500 a day | |
| 945 | | Changing what is watched | 120 an hour | |
| 946 | | New issues | 20 an hour, 100 a day | |
| 947 | | Comments, reviews and edits of their text, together | 60 an hour, 500 a day | |
| 948 | | New change requests | 20 an hour, 100 a day | |
| 949 | | Updates of change requests | 120 an hour | |
| 950 | | Forks | 10 an hour, 30 a day | |
| 951 | | Labels, assignees, states and settings | 300 an hour | |
| 952 | | Blocking and unblocking | 60 an hour | |
| 953 | | Marking notifications | 600 an hour | |
| 954 | | Batches of repositories synced from GitHub | 6 an hour | |
| 955 | |
| 956 | How each write counts: a star taken back as a star, an account unfollowed |
| 957 | as a follow; a level of watching changed, and a thread followed or muted, |
| 958 | as a watch (sections 17 and 21); a comment, a review, and a change of a |
| 959 | title or a text as a comment; a change of state, labels, assignees or lock, |
| 960 | a comment hidden or deleted, a label made or deleted, a draft marked ready, |
| 961 | reviewers asked, a change request deleted, a retry of a sync, and a change |
| 962 | of an account's or a repository's settings or collaborators as an edit |
| 963 | (sections 3, 4, 18, 19 and 23); a change request's update as a request |
| 964 | update; marking notifications read or done as a mark. |
| 965 | |
| 966 | Besides, a repository takes at most 100 new threads (issues and change |
| 967 | requests together) an hour from the accounts that cannot write to it, |
| 968 | between them, so that many accounts cannot bury its issues. Accounts with |
| 969 | `write` on it are not counted, whatever the scopes of the token they use. |
| 970 | The 429 says how long until the repository takes another. Such an account |
| 971 | has at most 100 open threads in one repository (403 `forbidden` past it, |
| 972 | until it closes some). |
| 973 | |
| 974 | **Verdicts** (section 25) count apart from the social writes: a repository |
| 975 | takes at most 60 a minute, from all its reporters together, and an account |
| 976 | posts at most 600 an hour, whatever its tokens. Past either, 429 |
| 977 | `rate_limited`, with `retry_after`. |
| 978 | |
| 979 | **Sizes.** A body whose `Content-Length` is over its route's size is |
| 980 | refused at once, before the hub reads any of it. The sizes, each answered |
| 981 | 413 `too_large`, and given by `GET /v1` (section 1): an object through |
| 982 | `PUT`, 64 MiB; a request body, 256 MiB (an object stream, and each of its |
| 983 | records); a JSON body, 4 MiB; a list of ids (`lacks`, `want`, `have`, a |
| 984 | stack), 10,000; the path prefixes of `/missing`, 1,000; a `/missing` page, |
| 985 | 100,000 entries, and its walk, 1,000,000 objects; a tree listing, 100,000 |
| 986 | entries; the repositories `GET /v1/repos` lists, an account's tokens and a |
| 987 | repository's collaborators, 1,000. `braid_hubproto::limits` holds them. |
| 988 | |
| 989 | The sizes of browsing and of the social features, which `limits.social` of |
| 990 | `GET /v1` gives: a page of a list, 100 entries (`page`); a page of a |
| 991 | directory, 1,000 entries (`dir_page`); a file shown as text, 1 MiB |
| 992 | (`text_view`); a title, 256 characters (`title`); a text, 64 KiB (`text`); |
| 993 | a repository's topics, 20 (`topics`), each of at most 50 characters |
| 994 | (`topic`); a repository's labels, 100 (`labels`), and a thread's, 20 |
| 995 | (`thread_labels`); a thread's assignees, 10 (`assignees`); a thread's |
| 996 | comments, 2,500, at which it locks itself (`comments_per_thread`); the line |
| 997 | comments of one review, 100 (`review_comments`); the mentions of one text |
| 998 | that notify, 10 (`mentions`), and the references of one text that link, 50 |
| 999 | (`references`); the changesets of a change request, 1,000 |
| 1000 | (`request_changesets`), and what one brings from another repository, |
| 1001 | 256 MiB (`request_bytes`). |
| 1002 | |
| 1003 | The sizes of diffs: a page of a diff, a changeset's `files` and a |
| 1004 | comparison's `files` hold at most 300 files; a version larger than 256 KiB |
| 1005 | is not diffed; the hunks of one file stop after 5,000 lines; a whole diff |
| 1006 | as text holds at most 8 MiB; and the lines of one page as much, each line |
| 1007 | counting 64 bytes more than it holds, so that a page of short lines holds |
| 1008 | fewer of them. |
| 1009 | |
| 1010 | ## 13. The client |
| 1011 | |
| 1012 | - `braid login [--hub URL]`, `braid logout [--hub URL]`, which revokes the |
| 1013 | token on the hub, and `braid hub whoami`, which says who is signed in and |
| 1014 | fails when nobody is. |
| 1015 | - `braid hub autopublish [on|off]` records whether coding agents publish |
| 1016 | the new projects they start (`on`), or only when asked (`off`), for every |
| 1017 | project and every hub; without an argument it prints `on`, `off` or |
| 1018 | `unset`. braid never publishes by itself: an agent reads the answer |
| 1019 | (`/agents.md` says when). |
| 1020 | - `braid hub publish [NAME] [--public] [--description TEXT] [--mirror URL]` |
| 1021 | creates the repository on the hub, uploads every branch and tag of the |
| 1022 | local repository, and links it: `.braid/hub` names the hub and the |
| 1023 | repository. With `--json` it prints, with the rest, `url`, the |
| 1024 | repository's address on the hub (`<hub>/<owner>/<name>`). |
| 1025 | - `braid hub clone OWNER/NAME [DIR] [--paths PREFIX…]` makes a local |
| 1026 | repository from a hub repository, linked to it. |
| 1027 | - `braid hub fetch` brings every branch and tag of the hub in, moving each |
| 1028 | local branch forward; a local branch with changesets the hub does not have |
| 1029 | is left as it is and reported. |
| 1030 | - `braid hub status` shows the link, and how each branch compares. |
| 1031 | - In a linked repository, `braid land` lands on the hub: it fetches, uploads |
| 1032 | what the hub lacks of the workspace's changesets, asks the hub to land the |
| 1033 | stack, fetches again, and moves the workspace onto the new head. Its |
| 1034 | output and exit statuses are those of a local landing. `braid update` |
| 1035 | fetches first. `braid change create --land` lands on the hub the same |
| 1036 | way. |
| 1037 | |
| 1038 | Those of the commands below that act on one repository of the hub take it |
| 1039 | as `-R OWNER/NAME` (`--hub-repo`), else the one the repository braid runs |
| 1040 | in is linked to (`braid hub request` takes, in a fork's clone, the |
| 1041 | repository it was forked from). Each takes `--json`, which prints what the |
| 1042 | hub answered, as its section gives it, unless it says otherwise below. |
| 1043 | Their exit status is 0 when the hub did it, 1 when it refused (a |
| 1044 | repository, revision, path or thread that is not there or that the caller |
| 1045 | may not read, a write not allowed, a limit), with its reason on standard |
| 1046 | error, 2 for conflicts where a command says so, and 3 when the hub could |
| 1047 | not be reached or failed. Without `--json`, what anyone wrote and the hub |
| 1048 | gives (names, descriptions, topics, titles, texts, comments, logins, |
| 1049 | labels, a README) is printed with its control characters escaped |
| 1050 | (`\u{1b}`, `\n`), line breaks and tabs of texts kept, so that it can |
| 1051 | neither drive the terminal nor print a line that looks like braid's; |
| 1052 | `--json` and `braid hub cat` give the exact text. The texts they send carry the global `--agent` (or |
| 1053 | `BRAID_AGENT`) as `agent`, unless it is `cli`. Commands that open, comment |
| 1054 | or review send an `Idempotency-Key` (section 1), and send the request once |
| 1055 | more with the same key when the answer was lost, so that nothing is done |
| 1056 | twice; when it is lost twice, the error says that the hub may have done it |
| 1057 | all the same, and which command shows whether it did. |
| 1058 | |
| 1059 | **Reading without cloning** (section 15). |
| 1060 | |
| 1061 | - `braid hub show [-R OWNER/NAME] [--ref REV]` shows a repository on the |
| 1062 | hub: its visibility, description, default branch, counts, topics, mirror |
| 1063 | and README. With `--json`, `{"repo", "readme"}`: the repository as `GET |
| 1064 | /v1/r/{owner}/{name}` gives it, and its README as `GET …/readme` does, or |
| 1065 | `null`. |
| 1066 | - `braid hub ls [PATH] [-R OWNER/NAME] [--ref REV]` lists a directory, |
| 1067 | every page of it, an entry a line: its kind, its size and its name, a |
| 1068 | directory's ending in `/`; for a file, its own line. With `--json`, the |
| 1069 | answer of `GET …/contents` with the entries of every page. |
| 1070 | - `braid hub cat PATH [-R OWNER/NAME] [--ref REV]` writes a file's bytes as |
| 1071 | they are, whatever its size. With `--json`, the file's answer of `GET |
| 1072 | …/contents`, with its text. |
| 1073 | - `braid hub log [-R OWNER/NAME] [--ref REV] [--limit N]` lists the |
| 1074 | changesets down the first parents of a branch, newest first (30 unless |
| 1075 | `--limit` says otherwise), a line each, as `braid log` writes them: the |
| 1076 | short id, the author's date, the author with the agent, and the summary. |
| 1077 | With `--json`, the log as `GET …/log` gives it, its pages joined. |
| 1078 | - `braid hub diff REV [-R OWNER/NAME] [--path PATH]` writes what a |
| 1079 | changeset changed against its first parent, as `git diff` writes it |
| 1080 | (`Accept: text/x-diff`), or, with `--path`, the diff of that file alone, |
| 1081 | for a diff larger than the hub gives whole. With `--json`, every page of |
| 1082 | `GET …/changesets/{rev}/diff` as one. |
| 1083 | |
| 1084 | **Finding repositories and accounts** (section 16). Neither needs a |
| 1085 | sign-in. |
| 1086 | |
| 1087 | - `braid hub explore [QUERY…] [--topic TOPIC] [--owner LOGIN] [--sort |
| 1088 | match|recent|stars|new] [--forks] [--limit N] [--after CURSOR]` lists |
| 1089 | public repositories as `GET /v1/explore` does, the words of QUERY being |
| 1090 | its terms. A query or a login the hub would refuse is refused before |
| 1091 | anything is sent. |
| 1092 | - `braid hub user LOGIN [--repos | --stars | --followers | --following] |
| 1093 | [--limit N] [--after CURSOR]` shows an account's profile, or one of its |
| 1094 | lists: its repositories, what it starred, its followers, or the accounts |
| 1095 | it follows, as far as the account signed in may see them. |
| 1096 | |
| 1097 | **Stars, watching and following** (section 17). |
| 1098 | |
| 1099 | - `braid hub star [-R OWNER/NAME]` and `braid hub unstar [-R OWNER/NAME]` |
| 1100 | star a repository, or take the star back. With `--json` they print |
| 1101 | `repo` and `starred`. |
| 1102 | - `braid hub stars [--user LOGIN] [--limit N] [--after CURSOR]` lists the |
| 1103 | repositories the account signed in starred, or those `--user` starred |
| 1104 | that it may read, newest first. |
| 1105 | - `braid hub watch [-R OWNER/NAME] [--level all|participating|ignore]` |
| 1106 | (`all` unless given) and `braid hub unwatch [-R OWNER/NAME]`, which goes |
| 1107 | back to `participating`. With `--json` they print `repo`, `level` and, |
| 1108 | for a level chosen, `since`. |
| 1109 | - `braid hub follow LOGIN` and `braid hub unfollow LOGIN`. With `--json` |
| 1110 | they print `login` and `following`. |
| 1111 | |
| 1112 | **Issues and labels** (section 18). |
| 1113 | |
| 1114 | - `braid hub issue list [-R …] [--state open|closed|all] [--label |
| 1115 | LABEL]… [--assignee LOGIN] [--author LOGIN] [--search TEXT] [--sort |
| 1116 | created|updated|comments] [--limit N] [--after CURSOR]` lists issues; |
| 1117 | `--search` works on public repositories only. |
| 1118 | - `braid hub issue show N [-R …]` prints the issue and its first 100 |
| 1119 | comments; with `--json`, `{"issue", "comments", "next"}`. |
| 1120 | - `braid hub issue create --title TITLE [--body TEXT | --body-file FILE] |
| 1121 | [--label LABEL]… [--assignee LOGIN]… [-R …]` opens an issue, and `braid |
| 1122 | hub issue comment N [--body TEXT | --body-file FILE] [-R …]` comments on |
| 1123 | one; `--body-file -` reads standard input, and a text holds at most |
| 1124 | 64 KiB. With `--json` they print the issue, or the comment. |
| 1125 | - `braid hub issue close N [--reason completed|not-planned] [-R …]`, |
| 1126 | `braid hub issue reopen N [-R …]`, and `braid hub issue edit N [--title |
| 1127 | TITLE] [--body TEXT | --body-file FILE] [--add-label LABEL]… |
| 1128 | [--remove-label LABEL]… [--add-assignee LOGIN]… [--remove-assignee |
| 1129 | LOGIN]… [--lock | --unlock] [-R …]` change an issue; with `--json` they |
| 1130 | print it. |
| 1131 | - `braid hub label list [-R …]`, `braid hub label create NAME [--color |
| 1132 | 0-11] [--description TEXT] [-R …]` and `braid hub label delete NAME |
| 1133 | [-R …]`. |
| 1134 | |
| 1135 | **Change requests** (section 19). `braid hub request --help` describes the |
| 1136 | whole flow. |
| 1137 | |
| 1138 | - `braid hub request create --title TITLE [--body TEXT | --body-file FILE] |
| 1139 | [--head [OWNER/NAME:]BRANCH] [--base BRANCH] [--expose] [--draft] |
| 1140 | [--reviewer LOGIN]… [-R …]` opens a change request. Without `--head`, in |
| 1141 | a workspace, it takes the workspace's changesets that its branch on the |
| 1142 | hub lacks, as `braid land` finds them, uploads them, and puts them on a |
| 1143 | new branch on the hub: `request/<login>/<slug>` of the repository itself |
| 1144 | when the caller may write there and its token may land on that name, and |
| 1145 | otherwise `request/<slug>` of the fork the repository is linked to (the |
| 1146 | slug comes from the title: lowercase ASCII letters, digits and `-`, at |
| 1147 | most 40 characters, with `-2`, `-3` and so on when the name holds other |
| 1148 | work). The workspace and its branch do not move. With `--head`, it |
| 1149 | proposes that branch as it is on the hub. It prints the request's number |
| 1150 | and its address. |
| 1151 | - `braid hub request list [--state open|closed|landed|all] [--author |
| 1152 | LOGIN] [--base BRANCH] [--reviewer LOGIN] [--limit N] [--after CURSOR]`, |
| 1153 | `braid hub request show N [--diff]` (what it proposes, whether it lands, |
| 1154 | its approvals, reviews and comments) and `braid hub request diff N [--rev |
| 1155 | REV] [--path PATH]` (the diff of its current revision, or of `--rev`, |
| 1156 | `A..B` for what changed from revision A to revision B). |
| 1157 | - `braid hub request comment N [--body TEXT | --body-file FILE] [--path |
| 1158 | PATH --line N [--side old|new] [--revision N]]` comments on it, or on a |
| 1159 | line of its diff; `braid hub request review N (--approve | |
| 1160 | --request-changes | --comment) [--body TEXT | --body-file FILE] |
| 1161 | [--revision N]` reviews it, and the hub refuses the review (`moved`) |
| 1162 | when the request has moved past `--revision` since. |
| 1163 | - `braid hub request update N [--head [ID]]` gives it a new revision, its |
| 1164 | author only: in a workspace, the workspace's changesets that its branch |
| 1165 | on the hub lacks, put on the request's head branch (as a fast-forward |
| 1166 | when they build on it, otherwise in its place); with `--head`, what the |
| 1167 | head branch holds on the hub now, or the changeset ID on its |
| 1168 | first-parent chain. |
| 1169 | - `braid hub request land N [--expect SNAPSHOT] [--mode rebase|ff-only]` |
| 1170 | lands the snapshot `--expect` names, or else the one the request |
| 1171 | proposes when it is read, which it prints first. Exit status 0 landed; |
| 1172 | 2 conflicts, printed as `braid land --json` prints them, the request |
| 1173 | staying open; 1 refused (the request moved past the snapshot, the base |
| 1174 | no longer holds where its stack starts, landing not allowed); 3 the hub |
| 1175 | could not be reached, or failed. With `--json`, `{"request", "land"}`. |
| 1176 | - `braid hub request close N`, `braid hub request reopen N` and `braid hub |
| 1177 | request ready N` (a draft ready for review). |
| 1178 | - `braid hub request checkout N [--branch NAME] [--force]` brings the |
| 1179 | request's snapshot into this repository as the branch `request/<N>`, its |
| 1180 | changesets coming through the request itself (`POST |
| 1181 | …/requests/{n}/missing`), so that whoever reads the repository the |
| 1182 | request is on fetches it, even without reading the repository it comes |
| 1183 | from. The branch is created, or |
| 1184 | moved forward; one with changesets the snapshot lacks stays where it is, |
| 1185 | unless `--force`. |
| 1186 | |
| 1187 | **The inbox** (section 21). |
| 1188 | |
| 1189 | - `braid hub inbox [--all] [-R OWNER/NAME] [--limit N] [--after CURSOR]` |
| 1190 | lists the notifications of the account signed in, newest first: the |
| 1191 | unread ones, all of them with `--all`, those of one repository with |
| 1192 | `-R`. It marks nothing. Each line gives `*` for an unread one, its id, |
| 1193 | the thread or the notice, and who did what, why and when, then how many |
| 1194 | are unread. |
| 1195 | - `braid hub inbox read ID…` and `braid hub inbox read --all` mark |
| 1196 | notifications read; with `--json` they print `marked`. `braid hub inbox |
| 1197 | done ID` takes one out of the inbox; with `--json` it prints `id` and |
| 1198 | `done`. |
| 1199 | - `braid hub inbox mute OWNER/NAME#NUMBER` and `braid hub inbox unmute |
| 1200 | OWNER/NAME#NUMBER` stop, or bring back, the notifications of a thread; |
| 1201 | with `--json` they print `repo`, `number`, `subscribed` and `reason`. |
| 1202 | |
| 1203 | **Forks and jobs** (section 20). |
| 1204 | |
| 1205 | - `braid hub fork OWNER/NAME [--name NAME] [--private] [--clone [DIR]] |
| 1206 | [--no-wait]` forks a repository into the account signed in to, waits |
| 1207 | until its job ends and prints the job and the fork; with `--clone`, it |
| 1208 | then clones the fork as `braid hub clone` does; with `--no-wait`, it |
| 1209 | prints the job as it starts. It sends an `Idempotency-Key`. Exit status |
| 1210 | 1 when the hub refused or the job failed. |
| 1211 | - `braid hub sync-fork [-R OWNER/NAME] [--ref REF]` syncs a fork with its |
| 1212 | upstream; exit status 2 when they diverged. |
| 1213 | - `braid hub jobs [ID] [--wait] [--limit N] [--after CURSOR]` lists the |
| 1214 | account's jobs, or shows one; with `--wait`, until it ends, with exit |
| 1215 | status 1 when it failed or was cancelled. |
| 1216 | |
| 1217 | **GitHub** (sections 2 and 23). |
| 1218 | |
| 1219 | - `braid hub github grant [--public-only]`: the device flow of section 2; |
| 1220 | braid prints the address and the code on standard error, and waits. |
| 1221 | - `braid hub github repos [--refresh]`: the listing of the repositories |
| 1222 | the account owns on GitHub. |
| 1223 | - `braid hub github sync (--all | FULL_NAME...) [--name FULL_NAME=NAME]... |
| 1224 | [--all-private] [--reserve-tdm] [--follow merge|ff-only|off] [--wait]`: |
| 1225 | a batch; it sends an `Idempotency-Key`. With `--wait`, braid waits until |
| 1226 | it ends, and the exit status is 1 when any repository failed or was |
| 1227 | skipped. |
| 1228 | - `braid hub github status [BATCH]`, `braid hub github cancel BATCH` and |
| 1229 | `braid hub github retry BATCH FULL_NAME [--name NAME]`. |
| 1230 | |
| 1231 | **Settings and blocks** (sections 3, 4 and 22). |
| 1232 | |
| 1233 | - `braid hub settings [-R OWNER/NAME] [--public | --private] [--description |
| 1234 | TEXT] [--default-branch BRANCH] [--topics T1,T2] [--tdm |
| 1235 | allowed|reserved] [--issues on|off] [--requests-from |
| 1236 | readers|collaborators|off] [--forks on|off] [--approvals N] [--follow |
| 1237 | off|ff-only|merge]`: with no flags it prints the repository's settings, |
| 1238 | all of them to its admins; with flags it changes those, as `PATCH |
| 1239 | /v1/r/{owner}/{name}` does, and prints the repository as it is now. |
| 1240 | `--topics ""` takes every topic off. With `--public` it says on standard |
| 1241 | error what the repository shows now. |
| 1242 | - `braid hub block LOGIN [-R OWNER/NAME]` and `braid hub unblock LOGIN [-R |
| 1243 | OWNER/NAME]`: without `-R`, from every repository of the account signed |
| 1244 | in; with it, from that repository, which the account administers. With |
| 1245 | `--json` they print `login`, `blocked` and, with `-R`, `repo`. |
| 1246 | - `braid hub account [--tdm-default allowed|reserved] [--stars-public |
| 1247 | on|off]`: with no flags it prints the account's settings; with flags it |
| 1248 | changes them, as `PATCH /v1/me` does. With `--json` it prints what `GET |
| 1249 | /v1/me` gives. |
| 1250 | |
| 1251 | **Verification** (section 25). Each of these asks `GET /v1` first, and |
| 1252 | asks nothing more of a hub that does not list `verify` (exit status 1). |
| 1253 | |
| 1254 | - `braid hub verify status [-R OWNER/NAME] [--fail-on-red]` shows how the |
| 1255 | default branch stands: its state and code, its head, green and red, the |
| 1256 | culprit and the window. With `--fail-on-red` the exit status is 4 while |
| 1257 | the branch is red or stuck. |
| 1258 | - `braid hub verify report --outcome pass|fail|flaky (--git-commit SHA | |
| 1259 | --changeset ID) --suite SUITE [-R OWNER/NAME]` posts a verdict, as a CI |
| 1260 | job does, with a token made for it (`BRAID_TOKEN`, and the hub in |
| 1261 | `BRAID_HUB_URL`). It sends an `Idempotency-Key`. |
| 1262 | - `braid hub verify policy [-R OWNER/NAME] [--mode off|report] [--suite |
| 1263 | SUITE] [--reporter LOGIN]… [--green-from report]…`: with no flags it |
| 1264 | prints the policy; with flags it reads it, changes what they name, keeps |
| 1265 | every other field as the hub gave it, and puts the whole of it back. A |
| 1266 | policy that names no source takes `report` once it has reporters. |
| 1267 | - `braid hub verify log [-R OWNER/NAME] [--limit N] [--after ID]` lists the |
| 1268 | events, newest first, and `braid hub verify reset [-R OWNER/NAME] |
| 1269 | [--green REV]` resets, sending an `Idempotency-Key`; `REV` is an id, or a |
| 1270 | revision of the repository braid runs in. |
| 1271 | |
| 1272 | `braid land`, `braid change create --land`, `braid revert` and `braid hub |
| 1273 | request land` give a landing's `verify` (section 8) as `hub_verify` with |
| 1274 | `--json`, and say on standard error, in one line, when the hub holds the |
| 1275 | branch red. `braid status --json` gives the hub's green and red of the |
| 1276 | workspace's branch as the last fetch saw them (`hub_green`, `hub_red`), |
| 1277 | and `braid hub status` gives each branch's. |
| 1278 | |
| 1279 | **Any route.** `braid hub api METHOD PATH [--data JSON | --data-file FILE] |
| 1280 | [--hub URL]` sends one request to the hub's API, with the token braid |
| 1281 | holds for the hub, and prints its answer's body as it came. `METHOD` is |
| 1282 | `GET`, `HEAD`, `POST`, `PUT`, `PATCH` or `DELETE`; `PATH` starts with |
| 1283 | `/v1`, such as `/v1/me`; `--data` or `--data-file` (`-` for standard |
| 1284 | input) give a JSON body. Exit status 0 when the hub did it, 1 when it |
| 1285 | refused, with its error printed on standard output, and 3 when it could |
| 1286 | not be reached or failed. |
| 1287 | |
| 1288 | ## 14. The web |
| 1289 | |
| 1290 | Pages are rendered on the hub, in English, with no script, font or anything |
| 1291 | else from elsewhere; their stylesheet is `GET /static/hub.css`, and their |
| 1292 | icon `GET /static/icon.svg`. Every answer carries `Content-Security-Policy: |
| 1293 | default-src 'self'; script-src 'none'; object-src 'none'; base-uri 'none'; |
| 1294 | form-action 'self'; frame-ancestors 'none'` (an answer with a policy of its |
| 1295 | own, as a raw file's, keeps it: section 15), `X-Content-Type-Options: |
| 1296 | nosniff` and `Referrer-Policy: no-referrer`, so that a link followed from a |
| 1297 | page never tells another site the address of a private repository; pages |
| 1298 | also carry `Cache-Control: no-store`. The pages of a repository carry the |
| 1299 | `<meta>` tags of section 24 in their `<head>`. |
| 1300 | |
| 1301 | The header of every page links Explore and holds a search box, a `GET` to |
| 1302 | `/explore`; signed in, it also links the inbox, with how many |
| 1303 | notifications are unread, a new repository, Import (`/-/onboarding`), the |
| 1304 | tokens, the account's profile, and signing out. The footer of every page |
| 1305 | links `/agents.md`, `/terms`, braid's site and the hub's version. |
| 1306 | |
| 1307 | **The hub's pages.** |
| 1308 | |
| 1309 | - `GET /`: what BraidHub is, "Sign up or sign in with GitHub" (the first |
| 1310 | sign-in makes the account; repositories are private by default; the hub |
| 1311 | reads the GitHub identity only), the guide for agents, and a link to |
| 1312 | explore. Signed in: the offer to bring the account's GitHub repositories |
| 1313 | (section 23), until it imports something or skips it, or, while a batch |
| 1314 | runs, a link to its progress; the account's repositories and a form to |
| 1315 | make one (name, private by default, description, GitHub mirror); its five |
| 1316 | latest unread notifications; and what the accounts it follows did lately |
| 1317 | in public repositories: the repositories of theirs that moved, and the |
| 1318 | ones they starred, unless they keep their stars private. |
| 1319 | - `GET /explore?q&topic&owner&sort&forks&after`: what explore and search |
| 1320 | list (section 16), 30 cards a page, with a search box, the orders as |
| 1321 | tabs, a switch for forks, and the 20 most used topics. When nothing is |
| 1322 | found, it says how to bring repositories to the hub. A query the |
| 1323 | protocol does not take shows the page again with why, as a 400. |
| 1324 | - `GET /topics/{topic}?q&owner&sort&forks&after`: the repositories with the |
| 1325 | topic, and how many; what is not a topic is a missing page. |
| 1326 | - `GET /{login}`: an account's profile: its initials, name and login, when |
| 1327 | it joined, a Follow button for whoever is signed in, and tabs for its |
| 1328 | repositories, its stars (`?tab=stars`), its followers |
| 1329 | (`?tab=followers`) and the accounts it follows (`?tab=following`), each |
| 1330 | with its count and holding what the viewer may see; its stars are shown |
| 1331 | to others only when it lets them be (section 17). No activity is shown. |
| 1332 | Every profile is at `GET /-/u/{login}` too, which is where the profile of |
| 1333 | a login that names a page of the hub (`explore`, `settings`, `tokens`, |
| 1334 | …) lives. A login that is no account, or a suspended one, answers as a |
| 1335 | route that does not exist: a page for a browser, the JSON 404 of |
| 1336 | section 1 otherwise. |
| 1337 | - `GET /tokens`: the account's tokens, a form to make one (repositories, |
| 1338 | rights, the branch glob of a `verify:` right, expiry, note), shown once, |
| 1339 | and revoking. |
| 1340 | - `GET /settings`, for a browser signed in (one signed out is sent to |
| 1341 | `/login`): the account's settings: the accounts it blocked, each with a |
| 1342 | form that lifts the block, and a form to block one more; whether its |
| 1343 | stars show to others; what text and data mining its new repositories |
| 1344 | start with; its GitHub access, with the scope it granted, links that |
| 1345 | grant it again (for all its repositories, or its public ones only) and a |
| 1346 | notice when GitHub refused it; and where it brings its GitHub |
| 1347 | repositories to the hub. |
| 1348 | - `GET /notifications?all&repo&after`: the inbox of the account signed in |
| 1349 | (section 21), its unread notifications or all of them (`?all=1`), of one |
| 1350 | repository with `?repo=owner/name`, newest first, grouped by repository, |
| 1351 | a page at a time. A repository the session may not read is the page of a |
| 1352 | missing one; anyone not signed in is sent to sign in. |
| 1353 | - `GET /-/jobs/{id}`: a job of the session's account (section 20), reloaded |
| 1354 | every 3 seconds until it ends, with a form to cancel it while it has not |
| 1355 | started. Another account's job, or none, is the page of a missing one. |
| 1356 | - `GET /-/onboarding`: what syncing the account's GitHub repositories does |
| 1357 | (section 23), the access it needs and how to take it back on GitHub, the |
| 1358 | grant links, and a form that skips it. |
| 1359 | - `GET /-/onboarding/github?refresh`: the account's repositories on GitHub |
| 1360 | in a table, with the defaults checked (owned, neither forks nor |
| 1361 | archived, most recently pushed first, within the room left), a name to |
| 1362 | edit for each, and the options of a batch. |
| 1363 | - `GET /-/onboarding/github/progress?batch`: how the batch stands, with a |
| 1364 | `<progress>` for each repository; it reloads itself every five seconds |
| 1365 | while the batch runs. Another account's batch is the page of something |
| 1366 | missing. |
| 1367 | - `GET /terms`, `GET /terms.md`, `GET /robots.txt` and `GET |
| 1368 | /.well-known/tdmrep.json`: section 24. |
| 1369 | - `GET /agents.md`: the guide for coding agents, `text/markdown; |
| 1370 | charset=utf-8`. `GET /healthz`: `ok`, for anyone. |
| 1371 | - Sign-in: `GET /login`, `GET /auth/github/callback`, `GET |
| 1372 | /auth/github/repo-access`, `POST /logout` (section 2). |
| 1373 | |
| 1374 | **A repository's pages** need what reading it needs: a private repository's |
| 1375 | pages and forms are 404 to whoever may not read it, as a missing |
| 1376 | repository's are, whatever the path. |
| 1377 | |
| 1378 | - `GET /{owner}/{name}`: the repository's home: its files at the default |
| 1379 | branch (or, while that has nothing, its first branch, then its first |
| 1380 | tag), with the last changeset and the README rendered; a switcher of its |
| 1381 | branches and tags (the first 100); what it is about: its description, |
| 1382 | topics and default branch; how to clone it (`braid hub clone |
| 1383 | owner/name`, and `git clone` from its mirror when the repository is |
| 1384 | public and mirrored on GitHub); and the mirror's state (section 11). |
| 1385 | While nothing has landed, it says how to publish. |
| 1386 | - The header of a repository's pages shows its stars, linked to its |
| 1387 | stargazers, how many watch all of it, and how many public forks it has, |
| 1388 | linked to its forks. To a signed-in reader who may interact with it, it |
| 1389 | also has a Star button (Starred, once it is), a Watch menu with the three |
| 1390 | levels, and, where forks are on, a Fork button. A fork's header says |
| 1391 | which repository it was forked from, when the viewer may read that one, |
| 1392 | and how many changesets its default branch is behind the upstream's, up |
| 1393 | to 1,000, with a form that syncs it for whoever may land on that branch, |
| 1394 | where a sync may bring the upstream in (section 20). Its admins find a |
| 1395 | Settings tab. While its verification is on (section 25), the header |
| 1396 | shows the state of the default branch as a badge, and a Verify tab. |
| 1397 | - `GET /{owner}/{name}/verify`: how the default branch stands (its state |
| 1398 | and code, its head, green and red, the culprit and the window) and the |
| 1399 | log of verification, newest first, for its readers; who did what shows |
| 1400 | to its admins only. While verification is off, it says so. |
| 1401 | - `GET /{owner}/{name}/tree/{REV}/{path}?after`: a directory, `dir_page` |
| 1402 | entries a page, with its README. |
| 1403 | - `GET /{owner}/{name}/blob/{REV}/{path}?plain`: a file: its text, escaped, |
| 1404 | with numbered lines and their anchors (`#L1`, `#L2`, …), when it is UTF-8 |
| 1405 | and at most `text_view` bytes, and at most 20,000 lines of it; Markdown |
| 1406 | rendered (`?plain=1` for its source); a PNG, JPEG, GIF or WebP image from |
| 1407 | the raw page; for a binary file, its size and a link to its bytes; a |
| 1408 | symlink's target, as text; a gitlink's commit. Each page links to the |
| 1409 | same file or directory by the changeset's full id, an address that never |
| 1410 | changes. |
| 1411 | - `GET /{owner}/{name}/raw/{REV}/{path}`: the file's bytes, with the |
| 1412 | headers of `GET …/raw` (section 15), but shown rather than saved when they |
| 1413 | are UTF-8 text (`text/plain; charset=utf-8`), or a PNG, JPEG, GIF or |
| 1414 | WebP image whose name says so and whose first bytes are one. HTML, SVG |
| 1415 | and XML files, and a file named as an image whose bytes are not one, are |
| 1416 | always attachments: nothing a repository holds runs on the hub's pages. |
| 1417 | - In these addresses, `REV` is the longest branch or tag that the rest of |
| 1418 | the path starts with, followed by a `/`, a full id, or the start of one; |
| 1419 | a ref's `/` may also be written `%2F`. The address of a directory that |
| 1420 | names a file leads to the file's page, and the other way round (`303 See |
| 1421 | Other`). A git commit shows only when the hub knows it already. The |
| 1422 | pages' links, and those of the READMEs and Markdown files they render, |
| 1423 | name a branch or tag by its changeset's full id instead when an address |
| 1424 | that names it would be read otherwise: when a longer ref starts with its |
| 1425 | name and a `/`, or when its name has a part a browser drops before |
| 1426 | asking (empty, `.` or `..`). |
| 1427 | - History, under the History tab: `GET /{owner}/{name}/commits` and `GET |
| 1428 | /{owner}/{name}/commits/{rev}`, the changesets down the first parents of |
| 1429 | the default branch, or of `rev`, 50 to a page; `GET |
| 1430 | /{owner}/{name}/changeset/{rev}?page`, a changeset, its message as text |
| 1431 | (never rendered), who made it and when, its parents and extra fields, and |
| 1432 | its diff, a page of files at a time, saying what it leaves out; `GET |
| 1433 | /{owner}/{name}/branches` and `GET /{owner}/{name}/tags`; and `GET |
| 1434 | /{owner}/{name}/compare/{base}...{head}`, or |
| 1435 | `/{owner}/{name}/compare/{base}...{owner}/{name}:{head}` for a head in |
| 1436 | another repository of the same fork network: what the head brings, and |
| 1437 | its diff. `GET /{owner}/{name}/compare?base&head` asks for the two |
| 1438 | revisions, and with both leads to their comparison. |
| 1439 | - `GET /{owner}/{name}/stargazers?after`: the accounts that starred the |
| 1440 | repository, latest first, a page at a time, but those that keep their |
| 1441 | stars private (each sees itself). |
| 1442 | - `GET /{owner}/{name}/forks?after`: the forks the viewer may read, newest |
| 1443 | first. |
| 1444 | - `GET /{owner}/{name}/issues?state&labels&assignee&author&q&sort&after`: |
| 1445 | open or closed issues, filtered by label, assignee or author and, on a |
| 1446 | public repository, by title, a page at a time. `GET |
| 1447 | /{owner}/{name}/issues/new`: a new issue (signed in), with a preview. |
| 1448 | `GET /{owner}/{name}/issues/{n}?after`: the issue and its timeline, with |
| 1449 | the forms of what the viewer may do: comment; edit, close and reopen it |
| 1450 | (its author and writers); label, assign and lock it, and hide comments |
| 1451 | (writers). `GET /{owner}/{name}/labels`: the repository's labels, with |
| 1452 | the forms that make and delete them, for writers. |
| 1453 | - `GET /{owner}/{name}/requests?state&after`: the change requests, open |
| 1454 | ones first. `GET /{owner}/{name}/requests/new?head_repo&head&base` |
| 1455 | compares a head with a base and opens the request (the box that |
| 1456 | publishes a private head's work shows to its admins only). `GET |
| 1457 | /{owner}/{name}/requests/{n}?after`: the request, its conversation a page |
| 1458 | at a time, its reviews, whether it lands cleanly with its conflicts, and |
| 1459 | the form that lands its snapshot for those who may. `GET |
| 1460 | /{owner}/{name}/requests/{n}/changesets`: its stack, and what it brings |
| 1461 | besides. `GET /{owner}/{name}/requests/{n}/changes?rev&page`: the diff of |
| 1462 | a revision with its line comments, or what changed between two. |
| 1463 | - `GET /{owner}/{name}/settings`, for its admins: a section with a form of |
| 1464 | its own for each of its visibility, its description and default branch, |
| 1465 | its topics, its features (issues, who may open change requests, forks, |
| 1466 | the approvals a change request needs before it lands), text and data |
| 1467 | mining, its mirror (with the follow policy, the outcome and what it says, |
| 1468 | `synced`, how the hub hears of pushes and when it looked last), a Verify |
| 1469 | box with its policy of verification (section 25), its collaborators, the |
| 1470 | accounts it blocked, and deleting it (typing its name again). Making a |
| 1471 | repository public asks for its name typed again, under a |
| 1472 | warning: everything it ever stored becomes readable by anyone who knows |
| 1473 | its id (section 4), so a fresh public repository is the way to publish |
| 1474 | only what it holds now. |
| 1475 | |
| 1476 | **Forms** post to the hub with the session's CSRF token in the field |
| 1477 | `csrf` (403 without it, with it in a header instead, or without the |
| 1478 | session's cookie), need what their route of the API needs, count toward |
| 1479 | the account's limits as it does (section 12), and do what it does, with |
| 1480 | what the session's account may do. They lead back with `303 See Other`: |
| 1481 | to the page named in `back`, where a form takes one and it is a path of |
| 1482 | the hub, else to the page or the section they belong to. The forms: |
| 1483 | |
| 1484 | - the account: `/new` (`name`, `private`, `description`, `mirror`); |
| 1485 | `/tokens` (repositories, rights, the branch glob of a `verify:` right, |
| 1486 | expiry, note), which answers the tokens page with the token made, shown |
| 1487 | that once; `/tokens/{id}/revoke`; |
| 1488 | `/logout`; `/settings/blocks` (`login`) and |
| 1489 | `/settings/blocks/{login}/remove`; `/settings/stars` (`stars_public`); |
| 1490 | `/settings/tdm` (`tdm_default`). |
| 1491 | - following and the inbox: `/-/follow/{login}` and `/-/unfollow/{login}`; |
| 1492 | `/notifications/read` (`id`, given again for more, or `all` and, |
| 1493 | optionally, `repo`) and `/notifications/done` (`id`), which lead back to |
| 1494 | the inbox unless `back` says otherwise; |
| 1495 | `/{owner}/{name}/threads/{number}/subscription` (`subscribed`, `1` to |
| 1496 | follow the thread or `0` to mute it). |
| 1497 | - jobs and syncing GitHub: `/-/jobs/{id}/cancel`; `/-/onboarding/skip`, |
| 1498 | after which the home page offers syncing no more; |
| 1499 | `/-/onboarding/github/sync`, which names repositories by `github_id` |
| 1500 | only: `repo` (repeated, at most 1,000), `name.<github_id>` (one a row, at |
| 1501 | most 1,000; given twice, the last counts), `all=1` for every eligible |
| 1502 | one, `all_private`, `reserve_tdm` and `follow`, more than 1,000 of either |
| 1503 | being 400, and which leads to the batch's progress; |
| 1504 | `/-/onboarding/github/retry` (`batch`, `github_id`, `name`) and |
| 1505 | `/-/onboarding/github/cancel` (`batch`), which lead back to it. |
| 1506 | - a repository's settings: `/{owner}/{name}/settings` (`description` and |
| 1507 | `default_branch`, and, from forms that send them, `visibility` and |
| 1508 | `mirror`; it leaves alone what a form does not send); |
| 1509 | `/{owner}/{name}/settings/visibility` (`visibility`, `private` or |
| 1510 | `public`, and `confirm`, the name typed again to make it public); |
| 1511 | `/{owner}/{name}/settings/topics` (`topics`, parted by commas or spaces); |
| 1512 | `/{owner}/{name}/settings/features` (`issues`, `requests_from`, |
| 1513 | `allow_forks`, `require_approvals`); `/{owner}/{name}/settings/tdm` |
| 1514 | (`tdm`); `/{owner}/{name}/settings/mirror` (`mirror`, the address, empty |
| 1515 | to remove it); `/{owner}/{name}/mirror/settings` (`follow`: `off`, |
| 1516 | `ff-only` or `merge`); `/{owner}/{name}/mirror/sync`, held to the minute |
| 1517 | of the API (section 23); `/{owner}/{name}/mirror/follow`; |
| 1518 | `/{owner}/{name}/settings/verify` (`mode`, `suite`, `reporters`, the |
| 1519 | logins parted by commas or spaces, and `flaky_moves_green`), which |
| 1520 | changes the policy of verification as `PUT …/verify/policy` does; |
| 1521 | `/{owner}/{name}/collaborators` (`login`, `permission`) and |
| 1522 | `/{owner}/{name}/collaborators/{login}/remove`; `/{owner}/{name}/blocks` |
| 1523 | (`login`) and `/{owner}/{name}/blocks/{login}/remove`; and |
| 1524 | `/{owner}/{name}/delete` (`confirm`, the name typed again). Each leads |
| 1525 | back to its section of the settings page, but these: deleting leads to |
| 1526 | `/`; `…/mirror/follow` leads to the repository's page, where its outcome |
| 1527 | shows; and `/{owner}/{name}/settings` and the collaborators' forms lead |
| 1528 | to the repository's page unless `back` names another page of the hub, as |
| 1529 | the settings page's own forms do. |
| 1530 | - stars, watching and forks: `/{owner}/{name}/star` and |
| 1531 | `/{owner}/{name}/unstar`; `/{owner}/{name}/subscription` (`level`); |
| 1532 | `/{owner}/{name}/fork` (`name`, `private`), which leads to the page of |
| 1533 | its job; `/{owner}/{name}/sync-upstream` (`ref`, the default branch when |
| 1534 | empty), which answers a page that says so (409) when the fork diverged. |
| 1535 | - issues: `/{owner}/{name}/issues` (`title`, `body`, `label`…, |
| 1536 | `assignees`), `/{owner}/{name}/issues/{n}/comments` (`body`), |
| 1537 | `/{owner}/{name}/issues/{n}/edit` (`title`, `body`), |
| 1538 | `/{owner}/{name}/issues/{n}/state` (`state`, `reason`), |
| 1539 | `/{owner}/{name}/issues/{n}/labels` (`label`…, all of them), |
| 1540 | `/{owner}/{name}/issues/{n}/assignees` (`assignees`, the logins parted by |
| 1541 | commas, all of them), `/{owner}/{name}/issues/{n}/lock` (`locked`, `1` or |
| 1542 | `0`), `/{owner}/{name}/comments/{id}/edit` (`body`), |
| 1543 | `/{owner}/{name}/comments/{id}/delete`, |
| 1544 | `/{owner}/{name}/comments/{id}/hide` (`reason`, empty to show it again), |
| 1545 | `/{owner}/{name}/labels` (`name`, `color`, `description`) and |
| 1546 | `/{owner}/{name}/labels/{label}/delete`. `/{owner}/{name}/preview` |
| 1547 | (`body`, with the fields of the form it came from) shows a text as it |
| 1548 | will show, with its form filled in again. |
| 1549 | - change requests: `/{owner}/{name}/requests` (`title`, `body`, |
| 1550 | `head_repo`, `head`, `base`, `draft`, `expose`), which leads to the |
| 1551 | request; `/{owner}/{name}/requests/preview`, which shows its text as it |
| 1552 | will show, with the form filled in again; |
| 1553 | `/{owner}/{name}/requests/{n}/comments` (`body` and, for a line comment, |
| 1554 | `path`, `line`, `side` and `revision`); |
| 1555 | `/{owner}/{name}/requests/{n}/review` (`verdict`, `body`, and `revision`, |
| 1556 | the revision the page showed); `/{owner}/{name}/requests/{n}/reviewers` |
| 1557 | (`logins`, all of them, parted by commas); |
| 1558 | `/{owner}/{name}/requests/{n}/state` (`state`, `open` or `closed`); |
| 1559 | `/{owner}/{name}/requests/{n}/ready`; `/{owner}/{name}/requests/{n}/update` |
| 1560 | (a new revision from its head's branch as it is now, its author only); |
| 1561 | `/{owner}/{name}/requests/{n}/land` (`snapshot`, the one the page showed, |
| 1562 | and `mode`); and `/{owner}/{name}/requests/{n}/delete`. |
| 1563 | |
| 1564 | Under `/v1`, a path that is not a route is the JSON 404 of section 1; |
| 1565 | elsewhere a browser (`Accept: text/html`) gets a page. |
| 1566 | |
| 1567 | ## 15. Browsing |
| 1568 | |
| 1569 | A repository can be read without cloning it. Every route of this section |
| 1570 | needs `read` on the repository; a private repository the caller may not |
| 1571 | read answers 404 `not_found`, exactly as a missing one does, whatever the |
| 1572 | path, the revision or the query. |
| 1573 | |
| 1574 | **Revisions.** `REV` (the `ref` of a query, `{rev}`, `base` or `head`, or |
| 1575 | the start of a page's path) is a branch, a tag as `tags/<name>`, a |
| 1576 | changeset's full id, or the first 12 to 63 hex digits of the id of a |
| 1577 | changeset the repository took in by a landing, an import or a fork; the |
| 1578 | default branch when none is given. The hub's own refs (`braid/…`, |
| 1579 | `remote/…`, `git/…`) are never revisions. An id names only a changeset the |
| 1580 | repository took in: an object uploaded and never landed is no revision, by |
| 1581 | its whole id or by its start, though `GET …/o/{id}` still serves it |
| 1582 | (section 6). A revision that names nothing, and the start of an id that |
| 1583 | more than one changeset's id begins with, are 404, and the answer names no |
| 1584 | changeset. In a route's path, `{rev}` encodes a `/` as `%2F`. |
| 1585 | |
| 1586 | **Paths.** A path is names joined by `/`, percent-encoded in the route; its |
| 1587 | bytes need not be UTF-8. It must be one a repository may hold (no empty |
| 1588 | name, no `.` or `..`, no `.braid` or `.git`): 400 `invalid` otherwise. One |
| 1589 | `/` at either end is ignored. Symlinks are never followed: a path through |
| 1590 | one is 404. In answers, names and paths are UTF-8, with what is not UTF-8 |
| 1591 | replaced; one that is not UTF-8 also comes percent-encoded in `raw_name` or |
| 1592 | `raw_path`, which a route takes as it is. |
| 1593 | |
| 1594 | - `GET /v1/r/{owner}/{name}/contents` and `GET |
| 1595 | /v1/r/{owner}/{name}/contents/{*path}?ref&text&after` → what is at the |
| 1596 | path (the root, without one): |
| 1597 | - a directory: `{"type": "dir", "ref", "changeset", "path", "raw_path", |
| 1598 | "entries": [{"name", "raw_name", "kind", "id", "size"}], "next"}`. Its |
| 1599 | directories come first, then the rest, each in order of their names' |
| 1600 | bytes, at most `dir_page` entries a page (`limits.social` of `GET /v1`; |
| 1601 | 1,000 by default). `next` is the cursor of the next page, for `?after=`, |
| 1602 | and `null` on the last. `kind` is `file`, `executable`, `symlink`, |
| 1603 | `tree` or `gitlink`; `id` is the blob or the tree, or a gitlink's git |
| 1604 | commit in hex; `size` is given for files, executables and symlinks. |
| 1605 | - anything else: `{"type": "file", "ref", "changeset", "path", |
| 1606 | "raw_path", "kind", "id", "size", "binary", "text", "target", |
| 1607 | "commit"}`. `binary` is true when a NUL is among the first 8,000 bytes. |
| 1608 | `text` is the content of a file or an executable that is not binary, |
| 1609 | is UTF-8 and is at most `text_view` bytes (`limits.social`; 1 MiB by |
| 1610 | default), and `null` otherwise; `text=false` leaves it out. A symlink |
| 1611 | gives its `target`, never what it points to; a gitlink its `commit`, |
| 1612 | and no `size`. |
| 1613 | - `ref` is the branch or tag the revision named, `null` for an id; |
| 1614 | `changeset` is the changeset read, as 64 hex digits. `raw_name` and |
| 1615 | `raw_path` are there only for names and paths that are not UTF-8. |
| 1616 | - 404 for a revision or a path that is not there; 400 for a path or a |
| 1617 | cursor that is not valid. |
| 1618 | - `GET /v1/r/{owner}/{name}/raw/{*path}?ref` → the file's bytes, as an |
| 1619 | attachment: `Content-Type: application/octet-stream`, |
| 1620 | `Content-Disposition: attachment` with the file's name in `filename*`, |
| 1621 | `Braid-Blob` (the blob's id) and `ETag` (the blob's id, quoted; a request |
| 1622 | whose `If-None-Match` names it answers 304), |
| 1623 | `Content-Security-Policy: default-src 'none'; sandbox`, |
| 1624 | `X-Content-Type-Options: nosniff` and |
| 1625 | `Cross-Origin-Resource-Policy: same-origin`. A symlink gives its target, |
| 1626 | as text; a directory or a gitlink has no bytes (404). |
| 1627 | - `GET /v1/r/{owner}/{name}/readme?ref&path` → the README of the directory |
| 1628 | `path` (the root, without one): `{"path", "raw_path", "blob", "size", |
| 1629 | "markdown", "html", "truncated"}`. A directory's README is its file |
| 1630 | named `README` or `README.<extension>`, in any case: Markdown (`.md`, |
| 1631 | `.markdown`, `.mdown`, `.mkdn`, `.mkd`) first, then `README` and |
| 1632 | `README.txt`, then any other, by name; a symlink is never one. |
| 1633 | `markdown` is its text, cut at 512 KiB on a character's boundary, when |
| 1634 | `truncated` is true; `html` is that text rendered as section 1 renders |
| 1635 | Markdown, or as preformatted text when the file is not Markdown. 404 when |
| 1636 | the directory has none, or the path is not a directory. |
| 1637 | |
| 1638 | The answers of these three routes about a private repository carry |
| 1639 | `Cache-Control: private, no-store`. A public repository's are kept a |
| 1640 | minute (`public, max-age=60`) when they were asked by a branch, a tag or |
| 1641 | the start of an id, which may name another changeset later, and for good |
| 1642 | (`public, max-age=31536000, immutable`) when they were asked by a full id. |
| 1643 | |
| 1644 | ### History |
| 1645 | |
| 1646 | The times of changesets are RFC 3339 with the offset from UTC the |
| 1647 | changeset recorded (`Z` for UTC). What a changeset holds as bytes (names, |
| 1648 | e-mail addresses, messages, paths) comes as UTF-8, with what is not UTF-8 |
| 1649 | replaced. Lists take `limit` and `after` as section 1 says; anything else |
| 1650 | is 400 `invalid`. |
| 1651 | |
| 1652 | A changeset in a list is `{"id", "parents", "author", "committer", |
| 1653 | "summary", "agent"}`: `author` and `committer` are `{"name", "email", |
| 1654 | "time"}`, `summary` is the first line of the message that is not blank, |
| 1655 | trimmed, at most 200 characters, and `agent` the agent that made it, or |
| 1656 | `null`. A file that changed is `{"path", "status", "old", "new"}`: |
| 1657 | `status` is `added`, `deleted`, `modified` (its content or its executable |
| 1658 | bit) or `type_changed` (between a file, a symlink and a gitlink); `old` |
| 1659 | and `new` are what was there and what is, `null` where there is nothing, |
| 1660 | each `{"kind", "blob", "size"}` (`kind` `file`, `executable` or |
| 1661 | `symlink`, whose content is its target) or `{"kind": "gitlink", |
| 1662 | "commit"}`. Files come in order of their paths' bytes, as change lists |
| 1663 | order them. |
| 1664 | |
| 1665 | - `GET /v1/r/{owner}/{name}/log?ref&after&limit` → `{"ref", |
| 1666 | "changesets": [...], "next"}`: the changesets down the first parents of |
| 1667 | `ref` (the default branch when it is not given), newest first. `next` is |
| 1668 | `null` at the first changeset; a cursor names where its log goes on, |
| 1669 | whatever `ref` says since. |
| 1670 | - `GET /v1/r/{owner}/{name}/changesets/{rev}` → `{"id", "parents", |
| 1671 | "root", "author", "committer", "message", "agent", "rebased_from", |
| 1672 | "git_commit", "extras", "files", "files_truncated"}`: the changeset, its |
| 1673 | whole message, its extra fields as `[name, value]` pairs, and the files |
| 1674 | it changes against its first parent (against nothing for a changeset |
| 1675 | without parents), at most 300, with `files_truncated: true` when there |
| 1676 | are more. `rebased_from` is the changeset a landing rebased it from, or |
| 1677 | `null`. `git_commit` is the git commit it exports to when the hub knows |
| 1678 | it already, as it does for what landed since it started; otherwise |
| 1679 | `null`, and `GET …/git/changeset/{id}` (section 9) computes it. |
| 1680 | - `GET /v1/r/{owner}/{name}/changesets/{rev}/diff?page&path&context` → |
| 1681 | `{"files": [...], "next_page"}`: a page of the changeset's diff against |
| 1682 | its first parent, at most 300 files, `next_page` the number of the page |
| 1683 | after it or `null`. `page` counts from 1 (a page past the last one is |
| 1684 | empty), `context` is the lines around each change, 0 to 10 (3 by |
| 1685 | default), and `path` asks for that one file alone (404 when the |
| 1686 | changeset does not change it). Each file is the file that changed with |
| 1687 | `"binary", "additions", "deletions", "hunks", "truncated"`. A hunk is |
| 1688 | `{"old_start", "old_lines", "new_start", "new_lines", "lines"}`, numbered |
| 1689 | as a unified diff numbers it (from 1; a hunk without lines of one |
| 1690 | version starts at the line it comes after, 0 at the start), and each |
| 1691 | line is `[op, text]`: `op` is `" "` for a line both versions have, `"-"` |
| 1692 | for one of the old version and `"+"` for one of the new, and `text` the |
| 1693 | line with its line ending, when it has one. A version with a NUL byte |
| 1694 | among its first 8,000 bytes is binary and is not diffed by lines; a |
| 1695 | gitlink diffs as the line `Subproject commit <hex>`. Within the sizes of |
| 1696 | section 12, a version too large to diff gives its file no hunks, the |
| 1697 | hunks of a file stop after a number of lines, and once the lines of a |
| 1698 | page hold as much as a whole diff may, the files after them come without |
| 1699 | hunks: each such file says `truncated: true`, and asking for it alone |
| 1700 | with `path` gives it whole when it fits. A file whose content stays the |
| 1701 | same (a new executable bit alone) has no lines to diff: it has no hunks, |
| 1702 | and is neither `binary` nor `truncated`, whatever its content. |
| 1703 | |
| 1704 | With `Accept: text/x-diff`, the answer is the whole diff as `git diff` |
| 1705 | writes it, `Content-Type: text/x-diff`, every file and every hunk whole: |
| 1706 | `git apply` takes it. Names are quoted as git quotes them; a changed |
| 1707 | type is the old file deleted and the new one added; a binary file, or a |
| 1708 | version too large to diff, is `Binary files a/<path> and b/<path> |
| 1709 | differ`, so that `git apply` refuses it rather than apply less; a new |
| 1710 | mode alone is its `old mode` and `new mode` lines, as git writes it, |
| 1711 | whatever the content. A diff larger than the whole diff may be is 413 |
| 1712 | `too_large`, unless `path` asks for one file. `page` is ignored. |
| 1713 | - `GET /v1/r/{owner}/{name}/compare?base&head&head_repo` → `{"base", |
| 1714 | "head", "merge_base", "stack", "brings", "files", "truncated"}`: what |
| 1715 | `head` brings to `base` (the default branch when it is not given). |
| 1716 | `head` is needed (400 without it). `base` and `head` are the changesets |
| 1717 | the two revisions name; `merge_base` is their best common ancestor (the |
| 1718 | one with the smallest id when there are several), or `null` when they |
| 1719 | share no history. `stack` is the head's first-parent chain down to a |
| 1720 | changeset the base has, oldest first; `brings` is everything else the |
| 1721 | head has and the base lacks, which merges in the stack bring, parents |
| 1722 | before children; `files` are the files the head changes since the merge |
| 1723 | base (since nothing, when there is none), at most 300. At most 1,000 |
| 1724 | changesets are listed, the newest of the stack first, and `truncated: |
| 1725 | true` says that changesets or files were left out. `head_repo` |
| 1726 | (`owner/name`) takes the head from another repository: one the caller |
| 1727 | may read, or the answer is the 404 of a missing repository, and one |
| 1728 | forked from the same repository as this one, directly or not, or the |
| 1729 | answer is 400 `invalid`. |
| 1730 | - `GET /v1/r/{owner}/{name}/branches?after&limit` and `GET |
| 1731 | /v1/r/{owner}/{name}/tags?after&limit` → `{"refs": [{"name", "head", |
| 1732 | "time", "summary"}], "next"}`: the branches, or the tags, in order of |
| 1733 | their names, each with the changeset it points to, when that changeset |
| 1734 | was recorded and its summary. `name` is the ref as a revision names it: |
| 1735 | `main`, `tags/v1`. The hub's own refs are never listed. |
| 1736 | |
| 1737 | These answers say how long they may be kept: an answer that never changes |
| 1738 | (a diff of a full id, a log from a full id or a cursor) may be kept, by |
| 1739 | anyone for a public repository and by the client alone for a private one; |
| 1740 | any other answer about a private repository is `Cache-Control: private, |
| 1741 | no-store`, and about a public one, `public, max-age=60`. A diff's answer |
| 1742 | is JSON or text at the same address, and says `Vary: Accept`. |
| 1743 | |
| 1744 | ## 16. Discovery |
| 1745 | |
| 1746 | Explore, search and topics list **public repositories that something |
| 1747 | landed on, of established owners**, and no fork unless asked. An owner is |
| 1748 | established once its account on the hub is seven days old and, when the |
| 1749 | hub knows when its GitHub account was made, that account thirty days old: |
| 1750 | until then, its public repositories are read by their links and shown on |
| 1751 | its profile, but listed by none of these. A repository the hub's operator |
| 1752 | hid or took down is listed by none of them either (section 22). |
| 1753 | |
| 1754 | No private repository is listed, matched or counted by explore, search or |
| 1755 | topics, to anyone, its owner and its readers included: those find it in |
| 1756 | their own lists (section 4) and on the owner's profile. A repository |
| 1757 | leaves these lists as soon as it turns private, is hidden or taken down, |
| 1758 | or its owner is suspended: the next request lists it no more. |
| 1759 | |
| 1760 | Anyone may ask, with or without a token; a token sent must be valid. |
| 1761 | |
| 1762 | A **card** is what lists of repositories hold, here and in sections 17 and |
| 1763 | 20: `{"owner", "name", "private", "description", "topics", "stars", |
| 1764 | "forks", "created", "pushed", "default_branch", "fork_of", "mirror_url", |
| 1765 | "tdm"}`, with `starred_at` or `level` where section 17 says. `fork_of` |
| 1766 | names the repository it was forked from only when the caller may read |
| 1767 | that one; `mirror_url` is the GitHub repository it mirrors to, if any. |
| 1768 | |
| 1769 | - `GET /v1/explore?q&topic&owner&sort&forks&limit&after` → `{"repos": |
| 1770 | [<card>…], "next"}`. |
| 1771 | - `q`: at most 100 characters, in at most 10 terms parted by spaces or |
| 1772 | `/`, so that `owner/name` finds a repository by both. A term holds |
| 1773 | letters, digits, `.`, `_` and `-`, and matches the start of a word of |
| 1774 | a repository's owner, name, description or topics, whatever its case |
| 1775 | and accents; every term must match. A term of `.`, `_` and `-` alone |
| 1776 | matches nothing and is left out. Any other character (a quote, `*`, a |
| 1777 | parenthesis, `:`) is 400 `invalid`: a query is never read as a query |
| 1778 | language, and `OR` or `NEAR` are words like any other. |
| 1779 | - `topic`: only the repositories with this topic (section 4); `owner`: |
| 1780 | only those of this account. |
| 1781 | - `sort`: `match`, best match first, the default with `q`: a match in |
| 1782 | the name counts the most, then one in the owner, then in the topics, |
| 1783 | then in the description. `recent`, the latest landing first, the |
| 1784 | default without `q`. `stars`, the most stars first. `new`, the newest |
| 1785 | first. `match` without `q` orders as `recent`. |
| 1786 | - `forks=1` lists forks too. |
| 1787 | - A query, topic, owner, order or flag the protocol does not take is 400 |
| 1788 | `invalid`. |
| 1789 | - `GET /v1/topics?limit&after` → `{"topics": [{"name", "repos"}…], |
| 1790 | "next"}`: the topics of what explore lists without forks, each with how |
| 1791 | many of those repositories have it, the most used first, then by name. |
| 1792 | - `GET /v1/topics/{topic}?q&owner&sort&forks&limit&after` → `{"repos": |
| 1793 | [<card>…], "next"}`: what `GET /v1/explore?topic={topic}` lists. What is |
| 1794 | not a topic is 404 `not_found`. |
| 1795 | - `GET /v1/users/{login}` → `{"login", "name", "created", "followers", |
| 1796 | "following", "repos", "stars", "viewer"}`: an account, as the caller may |
| 1797 | see it. `repos` counts the account's repositories the caller may read; |
| 1798 | `stars`, its stars of repositories the caller may read, `null` when the |
| 1799 | account keeps its stars private (section 3) and the caller is not that |
| 1800 | account. `viewer`, for a caller with a token: `{"follows"}`, whether the |
| 1801 | caller follows it. A login that is not one (section 1) is 400 `invalid`; |
| 1802 | an account that does not exist, or is suspended, 404 `not_found`. |
| 1803 | - `GET /v1/users/{login}/repos?type&sort&limit&after` → `{"repos": |
| 1804 | [<card>…], "next"}`: the account's public repositories, and its private |
| 1805 | ones the caller may read, marked `private`, each with what its settings |
| 1806 | say now. `type`: `all`, the default, `public`, `private`, `sources` (no |
| 1807 | forks) or `forks`. `sort`: `pushed`, the latest landing first and those |
| 1808 | that never landed last, the default; `name`; or `created`, the newest |
| 1809 | first. Any other is 400 `invalid`; an account as for its profile. |
| 1810 | |
| 1811 | Lists come a page at a time, as section 1 says. A cursor belongs to its |
| 1812 | query: given with another query, order, topic, owner or `forks`, it is |
| 1813 | 400 `invalid`. Explore, search and the topics give at most 50 pages of one |
| 1814 | query: the fiftieth answers `next: null`. Each page goes on after the last |
| 1815 | entry of the page before, so that what is listed meanwhile neither repeats |
| 1816 | nor skips what was listed already; a repository whose stars or rank moved |
| 1817 | meanwhile may move in the list. |
| 1818 | |
| 1819 | ## 17. Stars, watching and following |
| 1820 | |
| 1821 | Starring and watching a repository interact with it (section 5): they need |
| 1822 | an account that may read it, that is not suspended and not blocked there, |
| 1823 | through a web session or a token whose scopes reach the repository with |
| 1824 | `interact`, `write` or `admin`. A repository the caller may not read |
| 1825 | answers 404 `not_found` to every method of these routes, as a missing one |
| 1826 | does, before the body or anything else is looked at; one it reads but may |
| 1827 | not interact with answers 403 `forbidden`, and an anonymous caller 401. |
| 1828 | Following needs a web session, or a token with `interact`, `write` or |
| 1829 | `admin` on `*` (403 without one). |
| 1830 | |
| 1831 | Every write may be sent again: it answers as the first one did and changes |
| 1832 | nothing more. Writes count toward the account's limits (section 12): a star |
| 1833 | taken back counts as a star, a level of watching changed counts as a |
| 1834 | watch, an account unfollowed counts as a follow. Lists come a page at a |
| 1835 | time, as section 1 says. |
| 1836 | |
| 1837 | **Stars.** |
| 1838 | |
| 1839 | - `PUT /v1/r/{owner}/{name}/star` → 204, and `DELETE |
| 1840 | /v1/r/{owner}/{name}/star` → 204, whether the caller starred it before |
| 1841 | or not. An account stars at most 10,000 repositories: one more is 400 |
| 1842 | `invalid`, until it takes a star back. |
| 1843 | - `GET /v1/r/{owner}/{name}/stargazers?limit&after` → `{"users": [{"login", |
| 1844 | "name", "since"}], "next"}`: the accounts that starred it, latest first, |
| 1845 | with when each did. An account that keeps its stars private is left out |
| 1846 | of every list of stargazers but for itself, and still counts in |
| 1847 | `counts.stars`. `read`. |
| 1848 | - `GET /v1/me/starred?limit&after` → `{"repos": [<card>…], "next"}`: the |
| 1849 | repositories the token's account starred, newest first, each with |
| 1850 | `starred_at`, of those the token may read now. A repository its account |
| 1851 | no longer reads, one it lost access to or one made private, is left out |
| 1852 | while that lasts; its star stays, and shows again if the access comes |
| 1853 | back. Needs a token. |
| 1854 | - `GET /v1/users/{login}/starred?limit&after` → the same for any account, |
| 1855 | of the repositories the caller may read. An account may keep its stars |
| 1856 | private (section 3): then this is 404 `not_found`, "this account keeps |
| 1857 | its stars private", to everyone but the account itself. Anyone may ask. |
| 1858 | |
| 1859 | **Watching.** An account watches a repository at one of three levels: `all` |
| 1860 | (everything that happens in it), `participating` (the threads it takes part |
| 1861 | in or is mentioned in) or `ignore` (nothing, not even those). Its owner |
| 1862 | watches `all` of it until it chooses otherwise, and everyone else |
| 1863 | `participating`. |
| 1864 | |
| 1865 | - `GET /v1/r/{owner}/{name}/subscription` → `{"level", "since"}`: how the |
| 1866 | caller watches it; `since`, when it chose that level, is left out while |
| 1867 | the caller watches it as it does by default. |
| 1868 | - `PUT /v1/r/{owner}/{name}/subscription {"level"}` → the same, as it is |
| 1869 | now. Choosing the default level again forgets the choice. An account |
| 1870 | chooses a level other than its default for at most 1,000 repositories: |
| 1871 | one more is 400 `invalid`; another level for one of those is not. A level |
| 1872 | that is not one of the three is 400 `invalid`. |
| 1873 | - `DELETE /v1/r/{owner}/{name}/subscription` → 204: the caller watches |
| 1874 | what it takes part in, the owner too. |
| 1875 | - `GET /v1/me/watching?limit&after` → `{"repos": [<card>…], "next"}`, each |
| 1876 | with `level`: the repositories the account chose a level for, and those it |
| 1877 | owns, which it watches `all` of unless it chose otherwise, in order of |
| 1878 | owner and name, of those the token may read. Needs a token. |
| 1879 | |
| 1880 | **Following.** |
| 1881 | |
| 1882 | - `PUT /v1/users/{login}/follow` → 204, and `DELETE |
| 1883 | /v1/users/{login}/follow` → 204, whether the caller followed the account |
| 1884 | before or not. A login that is not one (section 1) is 400 `invalid`; an |
| 1885 | account that does not exist, or is suspended, 404 `not_found`; following |
| 1886 | oneself, 400 `invalid`. An account cannot follow one that blocked it (403 |
| 1887 | `forbidden`), and may always stop following it. An account follows at |
| 1888 | most 5,000 accounts: one more is 400 `invalid`. |
| 1889 | - `GET /v1/users/{login}/followers?limit&after` and `GET |
| 1890 | /v1/users/{login}/following?limit&after` → `{"users": [{"login", |
| 1891 | "name", "since"}], "next"}`: the accounts that follow it, or that it |
| 1892 | follows, latest first, with since when. Follows are public: anyone may |
| 1893 | ask. A suspended account shows in no list, and its own lists are 404. |
| 1894 | |
| 1895 | ## 18. Issues, comments and labels |
| 1896 | |
| 1897 | An issue is a thread of a repository: a title, a text and its comments, |
| 1898 | with labels, assignees and a state. Issues and change requests (section 19) |
| 1899 | share one numbering in their repository: a number names one thread, |
| 1900 | whichever kind it is. `GET /v1/r/{owner}/{name}/threads/{n}` → `{"kind": |
| 1901 | "issue"|"request", "number", "title", "state"}` says which (`read`). |
| 1902 | |
| 1903 | Every route finds the repository before it looks at anything else of the |
| 1904 | request: one the caller may not read answers 404 `not_found`, as a missing |
| 1905 | one does, whatever the method, the number or the body. Reading needs |
| 1906 | `read`. Every write interacts with the repository (section 5): it needs an |
| 1907 | account that may read it, that is not suspended and not blocked there, |
| 1908 | through a web session or a token whose scopes reach it with `interact`, |
| 1909 | `write` or `admin` (401 for an anonymous caller, 403 otherwise), and the |
| 1910 | body is read only for one that may. What a write may do is decided again |
| 1911 | once its body is read, by the repository as it is then: one deleted |
| 1912 | meanwhile, or made again under its name, answers 404 as a missing one, and |
| 1913 | access lost meanwhile is lost for the write. Managing issues needs `write`: |
| 1914 | labels, assignees, locks, and the issues and comments of other accounts. |
| 1915 | |
| 1916 | Texts are as section 1 says: titles of 1 to 256 characters on one line, |
| 1917 | texts of at most 64 KiB in Markdown, and an `agent` label shown as "via". |
| 1918 | Writes count toward the account's limits (section 12): opening an issue as |
| 1919 | an issue; a comment, or a change of a title or a text, as a comment; a |
| 1920 | change of state, labels, assignees or lock, a comment hidden or deleted, a |
| 1921 | label made or deleted, as an edit. A repository takes at most 100 new |
| 1922 | threads an hour from accounts that do not write to it, between them, and |
| 1923 | such an account has at most 100 open threads in one repository (403 |
| 1924 | `forbidden` past it, until it closes some). |
| 1925 | |
| 1926 | **An issue** is `{"number", "title", "body", "state": "open"|"closed", |
| 1927 | "state_reason": "completed"|"not_planned"|null, "author", "agent", |
| 1928 | "labels": [<name>…], "assignees": [<login>…], "locked", "comments", |
| 1929 | "created", "updated", "closed", "closed_by", "closed_by_changeset"}`. |
| 1930 | `closed_by` names who closed it; `closed_by_changeset`, the changeset whose |
| 1931 | landing closed it (section 8). The routes that answer one issue add `html`, |
| 1932 | its text as the caller's pages show it. |
| 1933 | |
| 1934 | - `GET /v1/r/{owner}/{name}/issues?state&labels&assignee&author&mentioned&q&sort&direction&limit&after` |
| 1935 | → `{"issues": [<issue>…], "next"}`. `state` is `open` (the default), |
| 1936 | `closed` or `all`; `labels` names labels, parted by commas, all of which |
| 1937 | an issue has; `assignee` is a login, `none` or `*`; `author` and |
| 1938 | `mentioned` are logins; `sort` is `created` (the default), `updated` or |
| 1939 | `comments`, the newest or the most first unless `direction=asc`. `q` |
| 1940 | keeps the issues whose title holds it, without regard to case, on a |
| 1941 | public repository; on a private one it is 403 `forbidden`, "text search is |
| 1942 | off for private repositories": a private repository's text is never |
| 1943 | searched. Pages as section 1 says; a cursor belongs to its sort and |
| 1944 | direction. `read`. |
| 1945 | - `POST /v1/r/{owner}/{name}/issues {"title", "body", "labels", |
| 1946 | "assignees", "agent"}` → 201, the issue, with `Location`. Takes |
| 1947 | `Idempotency-Key` (section 1): a retry gets the first answer again, its |
| 1948 | `Location` too, and one too large to keep whole comes back without its |
| 1949 | `html`, and if need be without its `body`; the issue is never made |
| 1950 | twice. A repository whose admins turned issues off (section 4) takes |
| 1951 | none: 403 `forbidden`. Labels and assignees come from writers only (403); |
| 1952 | a label the repository does not have, or an assignee who may not read the |
| 1953 | repository, is 400 `invalid`; at most 20 labels and 10 assignees, and a |
| 1954 | longer list is 400 `invalid`, as is a list that asks for more than 20 |
| 1955 | labels. |
| 1956 | - `GET /v1/r/{owner}/{name}/issues/{n}` → the issue. A change request's |
| 1957 | number is 404 here. `read`. |
| 1958 | - `PATCH /v1/r/{owner}/{name}/issues/{n} {"title", "body", "state", |
| 1959 | "state_reason", "labels", "assignees", "locked"}` → the issue, with the |
| 1960 | fields given changed. Its author may change its title, its text and its |
| 1961 | state; writers anything (403 otherwise). `labels` and `assignees` are the |
| 1962 | whole lists. `state` is `open` or `closed`; `state_reason`, `completed` |
| 1963 | (the default) or `not_planned`, goes with closing or with a closed issue |
| 1964 | (400 otherwise). Each change is an entry of the timeline; a closed |
| 1965 | issue given another reason has a `closed` entry with it. |
| 1966 | |
| 1967 | **Comments** are `{"id", "author", "agent", "body", "created", "edited", |
| 1968 | "hidden"}`; ids are the repository's own, so that a comment of another |
| 1969 | repository is 404 here. |
| 1970 | |
| 1971 | - `GET /v1/r/{owner}/{name}/issues/{n}/comments?limit&after` → |
| 1972 | `{"comments": [<comment>…], "next"}`, oldest first. `read`. |
| 1973 | - `POST /v1/r/{owner}/{name}/issues/{n}/comments {"body", "agent"}` → 201, |
| 1974 | the comment, with its `html` and `Location`. Takes `Idempotency-Key`, as |
| 1975 | opening an issue does. A locked issue takes comments from writers only |
| 1976 | (403). A thread takes at most 2,500 comments: the one that reaches it |
| 1977 | locks it, and past it nobody comments (403), so that a new issue goes on. |
| 1978 | - `GET /v1/r/{owner}/{name}/comments/{id}` → the comment, with its `html`. |
| 1979 | - `PATCH /v1/r/{owner}/{name}/comments/{id} {"body"}` → the comment, with |
| 1980 | `edited`: its author only. |
| 1981 | - `DELETE /v1/r/{owner}/{name}/comments/{id}` → 204: its author, or a |
| 1982 | writer. |
| 1983 | - `POST /v1/r/{owner}/{name}/comments/{id}/hide {"reason"}` → the comment: |
| 1984 | writers only. `reason` is `spam`, `off_topic`, `outdated` or `resolved`, |
| 1985 | or `""` to show it again. A hidden comment shows to those who do not |
| 1986 | write to the repository with its `hidden` reason and an empty `body`; |
| 1987 | writers read it still. The comments of a suspended account are left out |
| 1988 | for those who do not write to the repository, and show to writers as |
| 1989 | `hidden: "suspended"`. |
| 1990 | |
| 1991 | **The timeline.** `GET |
| 1992 | /v1/r/{owner}/{name}/issues/{n}/timeline?limit&after` → `{"items": |
| 1993 | [<item>…], "next"}`, oldest first: the comments, and what happened, each |
| 1994 | `{"kind", "actor", "created"}` and what the kind says: `comment` with |
| 1995 | `comment`; `renamed` with `from` and `to`; `edited`; `closed` with |
| 1996 | `reason`, and `changeset` when a landing closed it; `reopened`; `labeled` |
| 1997 | and `unlabeled` with `label`; `assigned` and `unassigned` with `assignee`; |
| 1998 | `locked`, with `reason: "full"` and an empty `actor` when the hub locked a |
| 1999 | thread that holds the most comments one may; `unlocked`; `referenced` with |
| 2000 | `source: {"number"}`, a thread of the same repository that named this |
| 2001 | one; `cross_referenced` with `source: {"repo": {"owner", "name"}, |
| 2002 | "number"}`, a thread of another repository that did, shown only to |
| 2003 | callers who may read that repository. `read`. |
| 2004 | |
| 2005 | **References.** A text names threads with `#4` and `owner/name#4`, |
| 2006 | accounts with `@login`, and changesets with 12 to 64 hex digits of their id |
| 2007 | (section 1). When it is written: |
| 2008 | |
| 2009 | - `#4` gives thread 4 of the same repository a `referenced` entry, once per |
| 2010 | thread that names it. |
| 2011 | - `owner/name#4` gives thread 4 of that repository a `cross_referenced` |
| 2012 | entry, when the writer may read the repository and the thread exists. |
| 2013 | - `@login` tells the account (section 21), when it may read the repository |
| 2014 | and did not block the writer: at most 10 mentions of one text count. A |
| 2015 | mention of anyone else does nothing, and says nothing. |
| 2016 | |
| 2017 | Where a text shows, a reference links to what it names, for each caller: |
| 2018 | to a thread that exists, of the repository or of another one the caller |
| 2019 | may read; to an account; to a changeset the repository admitted. Anything |
| 2020 | else, a thread of a repository the caller may not read among them, is |
| 2021 | plain text, exactly as a reference to a repository that does not exist. |
| 2022 | |
| 2023 | **Labels** are `{"name", "color", "description"}`: names of 1 to 50 |
| 2024 | characters, without commas, compared without regard to case; colours `0` |
| 2025 | to `11`, of the hub's palette; descriptions at most 200 characters. A |
| 2026 | repository starts with `bug`, `enhancement`, `documentation`, `question`, |
| 2027 | `good first issue` and `help wanted`, and has at most 100. |
| 2028 | |
| 2029 | - `GET /v1/r/{owner}/{name}/labels` → `{"labels": [<label>…]}`, by name. |
| 2030 | `read`. |
| 2031 | - `PUT /v1/r/{owner}/{name}/labels/{label} {"color", "description"}` → the |
| 2032 | label, made, or changed when the repository has one of that name; what |
| 2033 | is left out is kept, or `0` and `""` for a new one. Writers only. One |
| 2034 | past the most is 400 `invalid`. |
| 2035 | - `DELETE /v1/r/{owner}/{name}/labels/{label}` → 204, and the label leaves |
| 2036 | every issue it was on: writers only; 404 for a label the repository does |
| 2037 | not have. |
| 2038 | |
| 2039 | **One's issues.** `GET /v1/me/issues?filter&state&limit&after` → |
| 2040 | `{"issues": [<issue with "repo": {"owner", "name"}>…], "next"}`: the issues |
| 2041 | the token's account is assigned to (`filter=assigned`, the default), opened |
| 2042 | (`created`) or is mentioned in (`mentioned`), latest first, in `state` as |
| 2043 | above (`open` by default), of the repositories the token may read now. One |
| 2044 | the account no longer reads, a collaborator removed or a repository made |
| 2045 | private, is left out while that lasts. Needs a token. |
| 2046 | |
| 2047 | ## 19. Change requests |
| 2048 | |
| 2049 | A change request proposes the work of a branch, its head, for a branch of |
| 2050 | the repository, its base. The head is a branch of the same repository, or |
| 2051 | of another repository of its fork network (section 20): one forked, |
| 2052 | directly or not, from the same repository. A request is pinned: its |
| 2053 | snapshot is the changeset its head held when it was opened or last |
| 2054 | updated, and each update makes a new revision, numbered from 1. What a |
| 2055 | revision proposes is worked out when it is made: its stack, the snapshot's |
| 2056 | first-parent chain down to an ancestor of the base's head, oldest first; |
| 2057 | what the merges of the stack bring in besides; and the merge base. Landing |
| 2058 | names the snapshot it lands, and approvals count for the revision they |
| 2059 | approve: what was reviewed is what lands. Change requests and issues share |
| 2060 | one numbering in their repository (section 18). |
| 2061 | |
| 2062 | Every route finds the repository before it looks at anything else of the |
| 2063 | request: one the caller may not read answers 404 `not_found`, as a missing |
| 2064 | one does, whatever the method, the number or the body; so does a head |
| 2065 | repository the caller may not read, when a request names one. Reading |
| 2066 | needs `read`. Writes interact with the repository (section 5): an account |
| 2067 | that may read it, is not suspended and not blocked there, through a web |
| 2068 | session or a token whose scopes reach it with `interact`, `write` or |
| 2069 | `admin` (401 for an anonymous caller, 403 otherwise); the body is read only |
| 2070 | for one that may. Texts are as in section 18: titles of 1 to 256 |
| 2071 | characters on one line, texts of at most 64 KiB, and an `agent` label |
| 2072 | shown as "via". References in texts work as in section 18. |
| 2073 | |
| 2074 | **What a request from another repository brings** is held apart from the |
| 2075 | target until it lands: the target's `o/{id}`, `lacks` and `missing` |
| 2076 | (section 6) never serve it, and the request's own routes do, so that |
| 2077 | whoever reads the target reads and fetches the request without reading |
| 2078 | its head. It counts toward the quota of the request's author (section 12) |
| 2079 | until it lands; landing copies it into the target, where it counts for the |
| 2080 | target's owner, and only a landing that lands it does: one that conflicts, |
| 2081 | that `ff-only` refuses, or whose stack is not built on the base leaves it |
| 2082 | apart. It is let go when the request lands, when it is deleted, and 30 |
| 2083 | days after it closed: a closed request may be reopened until then, and |
| 2084 | after that its `head.available` is false and a new request goes on. A |
| 2085 | request from the same repository brings nothing of its own. |
| 2086 | |
| 2087 | **A private head goes to another repository only when its admin says |
| 2088 | so.** A request whose head is in a private repository other than the |
| 2089 | target publishes what it brings to everyone who reads the target. It is |
| 2090 | opened by an admin of the head, with `"expose": true`; otherwise it is 400 |
| 2091 | `invalid`, and the detail says to whom it would publish. Updating such a |
| 2092 | request needs an admin of the head too. A request opened while its head |
| 2093 | was public is not updated once the head is private (400 `invalid`): nobody |
| 2094 | said to publish what the head holds since, and a new request, opened with |
| 2095 | `expose`, goes on. The name of a request's head repository shows only to |
| 2096 | those who may read it: to others, `head.repo` is `null`. |
| 2097 | |
| 2098 | **A request** is `{"number", "title", "body", "state": |
| 2099 | "open"|"closed"|"landed", "draft", "author", "agent", "head", "base", |
| 2100 | "revision", "stack", "brings", "mergeable", "approvals", |
| 2101 | "review_requests", "last_attempt", "landed", "closes", "comments", |
| 2102 | "locked", "created", "updated", "closed", "closed_by"}`: |
| 2103 | |
| 2104 | - `head` is `{"repo": {"owner", "name"}|null, "ref", "snapshot", |
| 2105 | "available"}`: `available` says whether the hub still holds what the |
| 2106 | snapshot brings, to show, fetch and land. |
| 2107 | - `base` is `{"ref", "head_at_snapshot", "merge_base"}`: the base's head |
| 2108 | when the current revision was made, and the merge base then. |
| 2109 | - `stack` and `brings` list the changesets as `GET …/log` does (section |
| 2110 | 15), each with its author, its time and the first line of its message; |
| 2111 | the routes that answer one request give them, a list leaves them empty. |
| 2112 | - `mergeable` is `{"state", "against", "conflicts"}`: whether the request |
| 2113 | lands on its base now, worked out against the base's head `against`. |
| 2114 | `state` is `clean`, `conflicts` (with the conflicts of the first |
| 2115 | changeset that does not land, as `braid land --json` prints them), |
| 2116 | `needs_update` (the base moved to a history the stack is not built on: |
| 2117 | its author updates it), or `unknown` while it is being worked out, which |
| 2118 | happens in the background once a request is read; `POST …/check` works |
| 2119 | it out at once. |
| 2120 | - `approvals` is `{"count", "required", "by"}`: the writers of the |
| 2121 | repository other than its author whose last review of the current |
| 2122 | revision approves it, and how many the repository needs (section 4). |
| 2123 | - `last_attempt`, while it is open, is the last landing that did not land |
| 2124 | it: `{"outcome": "conflicts"|"refused", "by", "agent", "at", "head", |
| 2125 | "conflicts"}`. `landed`, once it landed, is `{"head", "operation", "by", |
| 2126 | "agent", "at"}`. |
| 2127 | - `closes` lists the issues of the repository its text closes (`closes |
| 2128 | #4`, `fixes #4`, `resolves #4`, as section 8 reads messages): those that |
| 2129 | landing it on the default branch closes, and once it landed, those it |
| 2130 | closed. |
| 2131 | - The routes that answer one request add `html`, its text as the caller's |
| 2132 | pages show it. |
| 2133 | |
| 2134 | **Opening a request.** |
| 2135 | |
| 2136 | - `POST /v1/r/{owner}/{name}/requests {"title", "body", "head": {"repo", |
| 2137 | "ref"}, "base", "expose", "draft", "reviewers", "agent"}` → 201, the |
| 2138 | request, with `Location`. `head.repo` is `owner/name`, the target itself |
| 2139 | when left out; `base` is the target's default branch when left out. |
| 2140 | Takes `Idempotency-Key` (section 1). |
| 2141 | - 403 `forbidden`: the repository takes no requests from the caller (its |
| 2142 | `requests_from`, section 4: `collaborators` takes them from its owner and |
| 2143 | collaborators only, `off` from nobody); the caller may not write to the |
| 2144 | head; reviewers named by a caller who does not write to the target. |
| 2145 | - 400 `invalid`: a head or a base that is no branch (a tag, one of the |
| 2146 | hub's own refs, one that does not exist); a head repository outside the |
| 2147 | fork network; a branch proposed for itself; a head that shares no history |
| 2148 | with the base, or brings nothing to it; a private head without the |
| 2149 | exposure of its admin; a reviewer who may not read the target, or is the |
| 2150 | author. |
| 2151 | - 409 `exists`: an open request proposes the same head for the same base. |
| 2152 | - An account that does not write to the repository has at most 100 open |
| 2153 | threads there, issues and requests together (403 `forbidden`), as in |
| 2154 | section 18. |
| 2155 | - 413 `too_large`: the request would hold more than 1,000 changesets, its |
| 2156 | stack and what it brings together, or bring more than 256 MiB from |
| 2157 | another repository (section 12). 403 `quota`: what it brings would take |
| 2158 | its author past what it may store. |
| 2159 | - A draft (`"draft": true`) does not land until it is marked ready. |
| 2160 | |
| 2161 | **Reading.** |
| 2162 | |
| 2163 | - `GET /v1/r/{owner}/{name}/requests?state&author&base&reviewer&limit&after` |
| 2164 | → `{"requests": [<request>…], "next"}`, newest first. `state` is `open` |
| 2165 | (the default), `closed` (closed or landed), `landed` or `all`; `author` |
| 2166 | and `reviewer` (asked to review) are logins; `base` is a branch. Pages as |
| 2167 | section 1 says. `read`. |
| 2168 | - `GET /v1/r/{owner}/{name}/requests/{n}` → the request. An issue's number |
| 2169 | is 404 here. `read`. |
| 2170 | - `GET /v1/r/{owner}/{name}/requests/{n}/diff?rev&page&path&context` → a |
| 2171 | page of the diff of revision `rev` (the current one by default), from its |
| 2172 | merge base to its snapshot, or of what changed from revision `A` to |
| 2173 | revision `B` (`rev=A..B`), as `GET …/changesets/{rev}/diff` gives one |
| 2174 | (section 15), JSON or, with `Accept: text/x-diff`, all of it as text. |
| 2175 | `read`. |
| 2176 | - `GET /v1/r/{owner}/{name}/requests/{n}/changesets/{id}` → a changeset of |
| 2177 | the request, as `GET …/changesets/{rev}` gives one: only those of the |
| 2178 | stacks of its revisions and of what they bring (404 otherwise). `read`. |
| 2179 | - `POST /v1/r/{owner}/{name}/requests/{n}/missing {"want", "have", |
| 2180 | "history", "paths", "limit", "after"}` → what a client needs to hold the |
| 2181 | request's changesets, as section 6 answers, as JSON pages or an object |
| 2182 | stream: from the repository and from what the request brings. `want` |
| 2183 | names the current snapshot or changesets of its stack (400 otherwise). |
| 2184 | This is how a reviewer who cannot read the head fetches the request |
| 2185 | (`braid hub request checkout`). `read`. |
| 2186 | |
| 2187 | **Updating.** `POST /v1/r/{owner}/{name}/requests/{n}/update {"head"}` → |
| 2188 | the request at its next revision: its author only (403), with write on the |
| 2189 | head (403), while it is open (400). The snapshot is what the head's branch |
| 2190 | holds now, or the changeset `head` names, which the branch must hold on |
| 2191 | its first-parent chain: otherwise 409 `not_on_branch`, with `head`, where |
| 2192 | the branch points. A snapshot that would not change is 400 `invalid`, and a |
| 2193 | branch gone from its repository is 409 `not_on_branch`. A head repository |
| 2194 | that is gone, or that the author may no longer read, is 400 `invalid`, the |
| 2195 | same for both. The new revision is worked out against the base's head now, |
| 2196 | within the sizes of a new request (413), and what it brings from another |
| 2197 | repository counts for its author (403 `quota`). A request has at most as |
| 2198 | many revisions as a thread has comments, 2,500 (403 `forbidden` past |
| 2199 | them). Reviews of earlier revisions no longer count, and say `stale`. |
| 2200 | |
| 2201 | **Changing a request.** `PATCH /v1/r/{owner}/{name}/requests/{n} |
| 2202 | {"title", "body", "state", "draft"}` → the request: its author or the |
| 2203 | repository's writers (403 otherwise). `state` is `open` or `closed`; a |
| 2204 | landed request stays landed (400). Reopening needs what it brings to be |
| 2205 | held still (400) and no other open request of the same head and base |
| 2206 | (409). `"draft": false` marks it ready for review. |
| 2207 | |
| 2208 | `DELETE /v1/r/{owner}/{name}/requests/{n}` → 204: an admin of the |
| 2209 | repository, or its author while it is open (403 otherwise). Its texts |
| 2210 | leave the hub, and what it brought is let go. |
| 2211 | |
| 2212 | **Comments** are those of section 18, with what they are about on a diff: |
| 2213 | `{…, "path", "line", "side", "revision", "outdated", "review"}`. |
| 2214 | |
| 2215 | - `GET /v1/r/{owner}/{name}/requests/{n}/comments?limit&after` → |
| 2216 | `{"comments": [<comment>…], "next"}`: its conversation, oldest first, |
| 2217 | line comments included, those of reviews left out. `read`. |
| 2218 | - `POST /v1/r/{owner}/{name}/requests/{n}/comments {"body", "path", |
| 2219 | "line", "side", "revision", "agent"}` → 201, the comment, with its |
| 2220 | `html` and `Location` (`…/comments/{id}`, which section 18 edits, |
| 2221 | deletes and hides). With `path` and `line`, both, it is a line comment: |
| 2222 | `side` is `old` or `new` (the default), `revision` the revision whose |
| 2223 | diff it is about (the current one by default), and the line must show in |
| 2224 | that diff, with the context a diff has (400 `invalid` otherwise). A line |
| 2225 | comment about a revision before the current one says `outdated`. Takes |
| 2226 | `Idempotency-Key`. Locked requests and full threads as in section 18. |
| 2227 | - `GET /v1/r/{owner}/{name}/requests/{n}/timeline?limit&after` → its |
| 2228 | timeline, as section 18 gives one, with these entries besides: `updated` |
| 2229 | with `changeset`, the new snapshot; `reviewed` with `reason`, the |
| 2230 | verdict; `review_requested` and `review_request_removed` with `assignee`, |
| 2231 | the account asked; `ready_for_review`; `converted_to_draft`; `landed` |
| 2232 | with `changeset`, the base's head once it landed. An issue a landing |
| 2233 | closed has a `closed` entry with `changeset`, and `source`, the request. |
| 2234 | |
| 2235 | **Reviews** are `{"id", "author", "agent", "verdict", "binding", "stale", |
| 2236 | "revision", "body", "created", "comments"}`. |
| 2237 | |
| 2238 | - `GET /v1/r/{owner}/{name}/requests/{n}/reviews?limit&after` → |
| 2239 | `{"reviews": [<review>…], "next"}`, oldest first. `read`. |
| 2240 | - `POST /v1/r/{owner}/{name}/requests/{n}/reviews {"verdict", "body", |
| 2241 | "comments", "revision", "agent"}` → 201, the review. `verdict` is |
| 2242 | `approve`, `request_changes` or `comment`; the last two say what, with a |
| 2243 | text or line comments (400 otherwise). `comments` are `{"path", "line", |
| 2244 | "side", "body"}`, at most 100, each on a line the current revision's |
| 2245 | diff shows (400 otherwise). `revision`, when given, must be the current |
| 2246 | one: otherwise 409 `moved`, since what was read is what is approved. A |
| 2247 | review's verdict counts (`binding`) when it approves or requests changes |
| 2248 | and comes from a writer of the repository other than the request's |
| 2249 | author; an approval counts until the same writer requests changes, or |
| 2250 | the request moves to a new revision. An open request only (400). Takes |
| 2251 | `Idempotency-Key`. |
| 2252 | - `GET /v1/r/{owner}/{name}/requests/{n}/reviewers` → `{"logins"}`: the |
| 2253 | accounts asked to review it. `read`. |
| 2254 | - `PUT /v1/r/{owner}/{name}/requests/{n}/reviewers {"logins"}` → the |
| 2255 | accounts asked, all of them: writers only (403), each an account that may |
| 2256 | read the repository and is not the author (400), at most 10. Those asked |
| 2257 | are told (section 21). |
| 2258 | |
| 2259 | **Landing.** |
| 2260 | |
| 2261 | - `POST /v1/r/{owner}/{name}/requests/{n}/check` → the request, with |
| 2262 | `mergeable` worked out now. `read`. |
| 2263 | - `POST /v1/r/{owner}/{name}/requests/{n}/land {"snapshot", "mode", |
| 2264 | "agent"}` → `{"request", "land"}`: `write` (403; 404 for a repository |
| 2265 | the caller may not read), and a `land:<glob>` right whose glob matches |
| 2266 | the base (403). The request must be open and not a draft (400), have the |
| 2267 | approvals the repository needs at its current revision (403), and |
| 2268 | `snapshot` must be its current one: otherwise 409 `moved`, and nothing |
| 2269 | lands. `mode` is `rebase` (the default) or `ff-only`, as in section 8. |
| 2270 | The stack lands as `POST …/land` lands one, with `<login>/request-<n>` as |
| 2271 | the op log's agent, and `land` is what that route answers. A base whose |
| 2272 | history no longer holds the stack's base is 409 `not_on_branch`. A |
| 2273 | landing that conflicts, or that `ff-only` refuses, is an answer too |
| 2274 | (200): the request stays open, with its `last_attempt`. Once it landed, |
| 2275 | the request is `landed`, and on the default branch the issues its text |
| 2276 | closes are closed, as completed, naming the changeset that closed them. |
| 2277 | |
| 2278 | ## 20. Forks and jobs |
| 2279 | |
| 2280 | A fork is a repository of the caller's account made from another one, its |
| 2281 | upstream. It holds what the upstream's branches, tags and other git refs |
| 2282 | reach when the fork is made, and nothing else of it: neither what was |
| 2283 | uploaded there and never landed, nor what only a deleted ref reached. It |
| 2284 | holds the git map too, so that history imported from git exports to the |
| 2285 | same commits in the fork as in its upstream (section 9), and the |
| 2286 | changesets the upstream admitted are admitted in the fork: a landing on |
| 2287 | them uploads only what it adds. Its collaborators, settings, mirror, |
| 2288 | issues, change requests and stars start empty; its description and topics |
| 2289 | are the upstream's. `fork_of` (section 4) names the upstream, for whoever |
| 2290 | may read it. |
| 2291 | |
| 2292 | A fork is made by a job, which runs in the background: the answer comes at |
| 2293 | once, and the fork appears whole once the job is done. Until then it does |
| 2294 | not exist (404), and a job that fails leaves nothing of it. |
| 2295 | |
| 2296 | **Forking.** |
| 2297 | |
| 2298 | - `POST /v1/r/{owner}/{name}/forks {"name", "private"}` → 202 `{"job": |
| 2299 | <job>, "repo": {"owner", "name"}}`, with `Location: /v1/jobs/{id}`. Both |
| 2300 | fields may be left out: `name` is the upstream's name, as it was given, |
| 2301 | and `private` its visibility. A fork of a private repository is private: |
| 2302 | `"private": false` is 400 `invalid`. |
| 2303 | - Forking interacts with the repository (section 5): one the caller may not |
| 2304 | read answers 404 `not_found`, as a missing one does, before the body is |
| 2305 | looked at; an anonymous caller is 401, and one that reads but may not |
| 2306 | interact, or is blocked there, 403. A token also needs `write` on |
| 2307 | `<login>/<name>`, the fork's place (403). |
| 2308 | - A repository takes forks when its `allow_forks` says so (section 4): yes |
| 2309 | by default for a public repository, no for a private one, which its |
| 2310 | admins may turn on. Otherwise the answer is 403 `forbidden`. A repository |
| 2311 | still being imported is 409 `exists`. One taken down (section 22) is not |
| 2312 | forked, by its owner either: 403 `forbidden`. |
| 2313 | - 409 `exists`: the name is taken, by a repository of the account or by a |
| 2314 | job of it that is not done yet; names are compared without regard to |
| 2315 | case. 400 `invalid`: a name that is not one (section 1). |
| 2316 | - 403 `quota`: the account owns as many repositories as it may, counting |
| 2317 | those its jobs are making; or what the upstream stores, added to what the |
| 2318 | account stores and what its jobs not done yet will store, passes what it |
| 2319 | may store (section 12). |
| 2320 | - Takes `Idempotency-Key` (section 1), which gives the first answer again. |
| 2321 | - Each fork counts toward the account's forks (section 12). |
| 2322 | |
| 2323 | When the job runs, the account must still read and interact with the |
| 2324 | repository, which must still take forks and not be taken down; otherwise |
| 2325 | the job fails, saying that the repository is gone or no longer readable, |
| 2326 | whichever it is. A repository that turned private since is forked private, |
| 2327 | as any fork of a private repository is. A repository of more than |
| 2328 | 1,000,000 objects fails the job: too large to fork here. |
| 2329 | |
| 2330 | A fork of a private repository, or of a fork of one, at any depth, is read |
| 2331 | only by those who read every repository it was forked from (section 5), and |
| 2332 | stays private: `PATCH …` with `"private": false` is 400 `invalid`. Its own |
| 2333 | collaborator entries are not enough. Once its owner no longer reads its |
| 2334 | upstream, or the upstream is deleted, the hub deletes the fork within the |
| 2335 | hour, as its owner would (section 4), and tells its owner (`fork_retired`, |
| 2336 | section 21). A read that GitHub gives (section 5) counts until GitHub says |
| 2337 | otherwise: while GitHub cannot be asked, the fork stays. A fork of a public |
| 2338 | repository is the account's own: it stays when its upstream turns private |
| 2339 | or goes. |
| 2340 | |
| 2341 | **The forks of a repository.** |
| 2342 | |
| 2343 | - `GET /v1/r/{owner}/{name}/forks?limit&after` → `{"repos": [<card>…], |
| 2344 | "next"}`: its forks the caller may read, the public ones and the private |
| 2345 | ones it reads, newest first, a page at a time (the cards of section 16). |
| 2346 | `read`. |
| 2347 | - `counts.forks` (section 4) counts its public forks; a private fork |
| 2348 | counts for nobody. |
| 2349 | |
| 2350 | **Syncing a fork with its upstream.** |
| 2351 | |
| 2352 | - `POST /v1/r/{owner}/{name}/sync-upstream {"ref"}` → `{"ref", "outcome", |
| 2353 | "head_before", "head", "behind", "more"}`: brings what the upstream's |
| 2354 | ref holds into the fork's ref of the same name. `ref` is a branch or a |
| 2355 | tag, the fork's default branch when left out; one of the hub's own refs |
| 2356 | (`braid/`, `remote/`) is 400. It needs `write` on the fork and, for a |
| 2357 | token, a `land:<glob>` right that matches the ref (403). |
| 2358 | - A repository that is not a fork is 400 `invalid`. An upstream that is |
| 2359 | gone, or that the caller may not read, is 404 `not_found`, as a missing |
| 2360 | repository; so is a ref the upstream does not have. |
| 2361 | - A sync never shows the upstream's work to others than those who may read |
| 2362 | it. An upstream that turned private after the fork was made does not |
| 2363 | sync into a fork that others may read: a public fork, or a private one |
| 2364 | made while the upstream was public. The answer is 400 `invalid`, and |
| 2365 | nothing is copied. A fork of a private repository syncs, since only the |
| 2366 | upstream's readers read it (section 5). An upstream taken down does not |
| 2367 | sync: 403 `forbidden`. |
| 2368 | - `outcome` is: |
| 2369 | - `fast-forward`: the fork's head was an ancestor of the upstream's, or |
| 2370 | the fork lacked the ref. The hub copied what the fork lacked, and the |
| 2371 | ref now points to the upstream's head, `head`. |
| 2372 | - `up-to-date`: the fork has the upstream's head already, as its head or |
| 2373 | an ancestor of it. Nothing moved. |
| 2374 | - `diverged`: each has changesets the other has not. Nothing moved; the |
| 2375 | fork takes the upstream's work by merging it and landing. |
| 2376 | - `head_before` is the fork's head before (`null` when it lacked the ref) |
| 2377 | and `head` after. `behind` counts the changesets of the upstream's ref |
| 2378 | the fork still lacks, up to 1,000, with `more: true` when there are more: |
| 2379 | 0 but when it diverged. |
| 2380 | - The move takes its turn in the ref's queue (section 8), and watchers get |
| 2381 | a `refs` event; a ref that moved while the sync ran is 409 `moved`. What |
| 2382 | the sync copies counts for the fork's owner: 403 `quota` past what it may |
| 2383 | store, and 413 `too_large` past 1,000,000 objects. |
| 2384 | |
| 2385 | **Jobs.** A job is `{"id", "kind", "state", "progress": {"objects", |
| 2386 | "bytes"}, "repo", "error", "created", "started", "finished"}`: `id` is `j_` |
| 2387 | and 26 characters of `a-z 2-7`; `kind` is `fork` or `import` (section 23); |
| 2388 | `state` is `queued`, `running`, `waiting` (for something outside the hub, |
| 2389 | such as GitHub's rate limit), `done`, `failed`, `cancelled` or `skipped`; |
| 2390 | `repo` is the repository it makes, `owner/name`; `error` says why it failed |
| 2391 | or was skipped; times are RFC 3339, `started` the last time it started. |
| 2392 | |
| 2393 | - `GET /v1/jobs?limit&after` → `{"jobs": [<job>…], "next"}`: the account's |
| 2394 | jobs, newest first. A token sees those of the repositories its scopes |
| 2395 | reach. Needs a token. |
| 2396 | - `GET /v1/jobs/{id}` → the job. Another account's job, one the token's |
| 2397 | scopes do not reach, and one that does not exist answer the same 404. |
| 2398 | - `POST /v1/jobs/{id}/cancel` → the job, cancelled: only a job that has not |
| 2399 | started may be (409 `exists` for one that runs or ended); cancelling one |
| 2400 | cancelled answers it again. A token needs `write` on the repository the |
| 2401 | job makes (403). |
| 2402 | |
| 2403 | An account runs one job at a time, oldest first; the hub runs a few at |
| 2404 | once, taking turns between accounts. A job the hub stops in the middle of |
| 2405 | runs again when it starts, from the beginning, at most three times. |
| 2406 | |
| 2407 | ## 21. The inbox |
| 2408 | |
| 2409 | The hub tells an account, in its inbox, what happens in the threads it |
| 2410 | takes part in and in the repositories it watches, and gives it notices |
| 2411 | about its own requests, such as a fork made or a grant to renew. The inbox |
| 2412 | is where they are: the hub sends no e-mail, and tells no other service. |
| 2413 | |
| 2414 | **Who is told** of what happens in a thread (an issue or a change request |
| 2415 | opened, a comment, a state changed, an assignment, a review, a landing): |
| 2416 | |
| 2417 | - the accounts that take part in it: its author, those who commented, |
| 2418 | those it is assigned to, those it mentions, those asked to review it and |
| 2419 | those who reviewed it; |
| 2420 | - the accounts that watch all of its repository (section 17), its owner |
| 2421 | among them unless it chose otherwise; |
| 2422 | - the accounts that chose to follow the thread (below). |
| 2423 | |
| 2424 | Never the account that did it, one that ignores the repository, one that |
| 2425 | muted the thread, one that blocked the account that did it, nor one that |
| 2426 | may not read the repository. Nor, while the block lasts, one that the |
| 2427 | repository's owner or the repository blocked (section 22): it may not mute |
| 2428 | the thread, nor watch the repository less. A mention, an assignment and a |
| 2429 | review asked for are told only to the accounts the thread mentions, is |
| 2430 | assigned to, or asks to review. Who may read is decided when the |
| 2431 | notification is made, and again each time it is shown. |
| 2432 | |
| 2433 | An account has one notification per thread: what happens next changes it, |
| 2434 | and makes it unread again. Its `reason` says why the account is told, the |
| 2435 | strongest of `mention`, `review_requested`, `assigned`, `review` (it |
| 2436 | reviewed the change request), `author`, `comment` (it commented), `state` |
| 2437 | (the thread was closed or opened again), `landed` and `subscribed` (it |
| 2438 | watches the repository, or follows the thread). An unread notification |
| 2439 | keeps the strongest reason it had; once read, the next one says why it |
| 2440 | came. A notice of the hub has the reason `system`. What one account does |
| 2441 | makes at most 10 notifications an hour for another: past that, that hour |
| 2442 | tells that account nothing more of it. A notification counts when it |
| 2443 | comes into the inbox, new or unread again: once, however many things one |
| 2444 | change tells of (a comment and the mentions in it, a thread opened with |
| 2445 | its assignees), and not again for what follows in its thread while it |
| 2446 | waits unread. |
| 2447 | |
| 2448 | A notification is `{"id", "repo": {"owner", "name"}|null, "thread": |
| 2449 | {"kind": "issue"|"request", "number", "title"}|null, "reason", "actor", |
| 2450 | "code", "updated", "unread", "url"}`. `thread` is `null` for a notice of |
| 2451 | the hub, and `repo` for a notice about no repository. `actor` is who did |
| 2452 | what happened last, `null` for the hub. `code` is what happened last: |
| 2453 | `opened`, `commented`, `closed`, `reopened`, `assigned`, `mentioned`, |
| 2454 | `review_requested`, `reviewed` or `landed`; for a notice, what it says: |
| 2455 | `fork_done`, `fork_failed` and `fork_retired` (section 20), `import_done` |
| 2456 | and `import_failed` (section 23), `needs_grant`, `mirror_conflicts`, |
| 2457 | `mirror_diverged`, `mirror_rewritten` or `mirror_gone` (section 11), or |
| 2458 | `verify_red`, `verify_fixed` and `verify_stuck` (section 25). `url` is the |
| 2459 | page of the hub it leads to. A thread's title is read when the inbox is |
| 2460 | listed, as it is then. |
| 2461 | |
| 2462 | The notices of verification say that a repository's default branch turned |
| 2463 | red, is no longer red, or is stuck, and lead to its verification page |
| 2464 | (`/{owner}/{name}/verify`). They go to the repository's admins, and, for |
| 2465 | `verify_red` with a culprit named, to the account that landed it too; a |
| 2466 | repository gives at most one every ten minutes, and only when the state |
| 2467 | changes. Each has a place of its own in the inbox, beside the other |
| 2468 | notices about the same repository, which it never replaces. |
| 2469 | |
| 2470 | A notification of a repository the account may no longer read (it was |
| 2471 | removed as a collaborator, or the repository was made private), or that |
| 2472 | was deleted, or of a thread that is gone, leaves the inbox: it is in no |
| 2473 | list and no count, and is deleted. For a repository mirrored on GitHub |
| 2474 | whose reader only GitHub can vouch for, the hub shows the notification |
| 2475 | only while it holds GitHub's answer (section 5), and keeps it meanwhile. |
| 2476 | |
| 2477 | **Tokens.** The inbox is the token's account's. A token sees the |
| 2478 | notifications of the repositories its scopes read (section 2), and the |
| 2479 | notices of no repository with a scope on `*`; it marks them read or done |
| 2480 | where its scopes also have `interact`, `write` or `admin`, and marking at |
| 2481 | all needs such a scope (403 `forbidden` otherwise). Marking, read or done, |
| 2482 | counts toward the account's limits (section 12). |
| 2483 | |
| 2484 | - `GET /v1/notifications?all&repo&limit&after` → `{"notifications": |
| 2485 | [<notification>…], "unread", "next"}`: the unread notifications, newest |
| 2486 | first; with `all=true`, the read ones too; with `repo=owner/name`, those |
| 2487 | of that repository only, which is 404 `not_found` when the token may not |
| 2488 | read it, as for one that does not exist. `unread` counts the unread |
| 2489 | notifications the token sees, of `repo` when it is given. Pages as |
| 2490 | section 1 says; `all` is `true` or `false` (400 `invalid` otherwise). |
| 2491 | Needs a token. |
| 2492 | - `POST /v1/notifications/read` → `{"marked"}`, with `{"ids": [<id>…]}` |
| 2493 | (at most 100), or any of `{"all": true}`, `{"repo": "owner/name"}` and |
| 2494 | `{"before": <time>}`: marks read the notifications of those ids, or every |
| 2495 | one the token may mark, of `repo` when it is given, that last changed at |
| 2496 | or before `before` when it is given (what a client showed, and nothing |
| 2497 | that came since). `marked` is how many were unread. An id the token does |
| 2498 | not see is passed over. A body that names nothing, or names ids and |
| 2499 | anything else, is 400 `invalid`; a `repo` the token may not read is 404. |
| 2500 | - `DELETE /v1/notifications/{id}` → 204: the notification is done and |
| 2501 | leaves the inbox, until what happens next in its thread brings it back. |
| 2502 | One the token does not see is 404 `not_found`, whoever's it is, with the |
| 2503 | same words. |
| 2504 | |
| 2505 | **Following a thread.** |
| 2506 | |
| 2507 | - `GET /v1/r/{owner}/{name}/threads/{n}/subscription` → `{"subscribed", |
| 2508 | "reason"}`: whether thread `n` notifies the caller, and why: `manual` (it |
| 2509 | chose to follow it), `muted` (it chose not to), `participating` (it takes |
| 2510 | part in it), `watching` (it watches all of the repository) or `ignoring` |
| 2511 | (it ignores the repository, which silences every thread of it). |
| 2512 | `reason` is left out when nothing ties the caller to the thread. |
| 2513 | - `PUT /v1/r/{owner}/{name}/threads/{n}/subscription {"subscribed": |
| 2514 | true|false}` → the same, as it is now. `false` mutes the thread, whatever |
| 2515 | ties the caller to it, and marks its notification read; `true` follows |
| 2516 | it. A change counts as a watch (section 12). |
| 2517 | |
| 2518 | Both interact with the repository (section 5): a repository the caller may |
| 2519 | not read is 404 `not_found`, as a missing one, whatever the method or the |
| 2520 | body; an anonymous caller is 401, and a token without `interact`, `write` |
| 2521 | or `admin` there 403. A thread the repository does not have is 404. |
| 2522 | |
| 2523 | ## 22. Blocks and moderation |
| 2524 | |
| 2525 | An account blocks another from every repository it owns; an admin of a |
| 2526 | repository blocks an account from that repository alone. Where it is |
| 2527 | blocked, an account cannot star, watch, comment, open issues or change |
| 2528 | requests, review or fork: each answers 403 `forbidden`, "you cannot |
| 2529 | interact with this repository", the words a suspended account gets too, |
| 2530 | which name no block. It cannot follow the account that blocked it (403). |
| 2531 | Its mentions do not notify the account that blocked it. It still reads |
| 2532 | every public repository, and whatever else it may read. |
| 2533 | |
| 2534 | Since a blocked account cannot take a star back or watch less where it is |
| 2535 | blocked either, a block ends them: blocking an account ends its follow of |
| 2536 | the blocker, takes its stars off the repositories the block covers and |
| 2537 | ends its watching of all of each, so that it hears of them no more than of |
| 2538 | any other repository it reads. A repository it chose to hear nothing of |
| 2539 | keeps that choice. Lifting the block gives none of them back. |
| 2540 | |
| 2541 | The owner of a repository is never blocked from it. An account blocks at |
| 2542 | most 1,000 accounts, and a repository at most 1,000: one more is 400 |
| 2543 | `invalid`, until a block is lifted. Blocking and unblocking count toward |
| 2544 | the account's limits (section 12). |
| 2545 | |
| 2546 | **An account's blocks** need a token with `interact`, `write` or `admin` on |
| 2547 | `*` (403 without one, 401 without a token). |
| 2548 | |
| 2549 | - `GET /v1/me/blocks?limit&after` → `{"users": [{"login", "name", "since"}], |
| 2550 | "next"}`: the accounts the caller blocked, newest first, with since when |
| 2551 | each is, in pages as section 1 says. |
| 2552 | - `GET /v1/me/blocks/{login}` → 204 when the caller blocked the account, |
| 2553 | 404 `not_found` when it did not. |
| 2554 | - `PUT /v1/me/blocks/{login}` → 204, and `DELETE /v1/me/blocks/{login}` → |
| 2555 | 204, whether the caller blocked the account before or not. |
| 2556 | - A login that is not one (section 1), or the caller's own, is 400 |
| 2557 | `invalid`; an account that does not exist is 404 `not_found`, and so is |
| 2558 | a suspended one for `PUT`. |
| 2559 | |
| 2560 | **A repository's blocks** need `admin` on it. A repository the caller may |
| 2561 | not read answers 404 to every method of these routes, as a missing one |
| 2562 | does, before anything else is looked at. |
| 2563 | |
| 2564 | - `GET /v1/r/{owner}/{name}/blocks?limit&after` → the same page, of the |
| 2565 | accounts the repository blocked. |
| 2566 | - `GET /v1/r/{owner}/{name}/blocks/{login}` → 204 or 404, `PUT |
| 2567 | /v1/r/{owner}/{name}/blocks/{login}` → 204 and `DELETE |
| 2568 | /v1/r/{owner}/{name}/blocks/{login}` → 204, as for an account's own. |
| 2569 | Blocking the owner, or oneself, is 400 `invalid`. |
| 2570 | |
| 2571 | **The operator** may also: |
| 2572 | |
| 2573 | - suspend an account: its tokens answer 401 `unauthorized`, its web |
| 2574 | sessions and its sign-ins are refused, its repositories answer 404 to |
| 2575 | everyone, as missing ones do, and leave every listing; it shows in no |
| 2576 | list of accounts, its profile is 404, and its comments show only to the |
| 2577 | writers of their repositories, with `"hidden": "suspended"` (section 18). |
| 2578 | Lifting the suspension gives all of it back, its tokens and sessions |
| 2579 | included. |
| 2580 | - hide a repository: it leaves Explore, search and topics (section 16), |
| 2581 | and stays readable as before. |
| 2582 | - take a repository down: it answers 404 to everyone but its owner, as a |
| 2583 | missing one does, leaves every listing, and is not forked. |
| 2584 | |
| 2585 | No route of the API does these. |
| 2586 | |
| 2587 | ## 23. Syncing with GitHub |
| 2588 | |
| 2589 | A new account's first sign-in leads to `/-/onboarding` (section 14), where |
| 2590 | it may bring the repositories it owns on GitHub to the hub, each kept as a |
| 2591 | mirror that follows GitHub (section 11). Only the account's own |
| 2592 | repositories are offered, never those of an organisation. The routes of |
| 2593 | the listing and of batches act for the caller's own account, as section 2 |
| 2594 | says: with a token that has `write` (or `admin`) on `<login>/*` or `*`, or |
| 2595 | a session that sends its CSRF token in `X-CSRF-Token`; and they reach |
| 2596 | GitHub with the access the account granted (section 2). |
| 2597 | |
| 2598 | **The listing.** `GET /v1/github/repos?refresh` → `{"scope", "repos", |
| 2599 | "truncated", "quota"}`: the repositories the account owns on GitHub, most |
| 2600 | recently pushed first, each once, at most 1,000 (`truncated` is true when |
| 2601 | GitHub has more). A repository pushed to while GitHub's pages were read |
| 2602 | may be missing until the listing is asked again. `scope` is `private` or |
| 2603 | `public`, as the account granted; with `public`, private repositories are |
| 2604 | not listed. The hub keeps a listing for ten minutes; `refresh` asks GitHub |
| 2605 | again, at most once a minute. Without a grant it is 403 `forbidden`, with |
| 2606 | a detail that names the grant's page and `braid hub github grant`; while |
| 2607 | GitHub holds the hub back, 503 `unavailable`. |
| 2608 | |
| 2609 | Each repository is `{"github_id", "full_name", "private", "fork", |
| 2610 | "archived", "empty", "size_kb", "default_branch", "pushed_at", "admin", |
| 2611 | "hub_name", "synced", "eligible", "reason", "estimate_bytes"}`: |
| 2612 | |
| 2613 | - `github_id`, `full_name` (`owner/name` on GitHub), `private`, `fork`, |
| 2614 | `archived`, `size_kb`, `default_branch` and `pushed_at` are GitHub's. |
| 2615 | `empty` is true for a repository that holds nothing yet. `admin` says |
| 2616 | whether the account administers it, as a webhook needs. |
| 2617 | - `hub_name` is the name it takes here: its own, with a leading `.` made |
| 2618 | `_` (`.github` becomes `_github`). |
| 2619 | - `eligible` says whether it may be imported; `reason` says why not: |
| 2620 | `name not allowed here` (a sync may give it another name), `name taken` |
| 2621 | (a repository of the account, or an import under way, has that name), |
| 2622 | or `already synced`, when a repository here is its mirror already: then |
| 2623 | `synced` names it, `owner/name`, when it is the account's. An archived |
| 2624 | repository is eligible, and `reason` says it is imported without a |
| 2625 | mirror; an empty one too, made empty with its mirror set. |
| 2626 | - `estimate_bytes`, about what it takes here: four times its size on |
| 2627 | GitHub. |
| 2628 | |
| 2629 | `quota` is `{"repos_left", "bytes_left"}`: what the account may still own |
| 2630 | and store (section 12), less what its imports and forks under way will |
| 2631 | make. |
| 2632 | |
| 2633 | **Batches.** `POST /v1/github/sync {"all", "repos", "names", |
| 2634 | "keep_public", "reserve_tdm", "follow"}` → 202 `{"batch", "queued", |
| 2635 | "skipped"}`, with `Location: /v1/github/sync/{batch}`. Takes |
| 2636 | `Idempotency-Key` (section 1). |
| 2637 | |
| 2638 | - `all: true` takes every repository not synced already, most recently |
| 2639 | pushed first; otherwise `repos` names them, each by its `github_id` or |
| 2640 | its `full_name`. |
| 2641 | - `names` gives some another name here, by `github_id` (in decimal) or |
| 2642 | `full_name`. A name that cannot be one here skips its repository with |
| 2643 | `name not allowed here`, and the batch shows it in `hub_name` cut to |
| 2644 | its first 100 characters, with `…` where it was cut. |
| 2645 | - `keep_public` (default true): public repositories stay public here; |
| 2646 | `false` imports them all as private. Private ones stay private either |
| 2647 | way. |
| 2648 | - `reserve_tdm` (default false) reserves text and data mining of what is |
| 2649 | imported (section 24); otherwise each takes the account's default. |
| 2650 | - `follow` (default `merge`): how each mirror takes in what is pushed to |
| 2651 | GitHub (section 11): `merge`, `ff-only` or `off`. |
| 2652 | |
| 2653 | Repositories are taken most recently pushed first, as many as the |
| 2654 | account's room allows. `queued` lists each one queued, `{"github_id", |
| 2655 | "full_name", "hub_name", "job"}`; `skipped` the others, `{"github_id", |
| 2656 | "full_name", "reason"}`, where `reason` is `quota` (no room left, in |
| 2657 | repositories or bytes), `name taken`, `name not allowed here`, `already |
| 2658 | synced`, or `not found` (not a repository the account owns on GitHub, as |
| 2659 | its grant shows them; `github_id` is then 0 when a name was given). An |
| 2660 | account runs one batch at a time: another while one runs is 409 `exists`. |
| 2661 | A body that names nothing and does not ask for all, an unknown `follow`, or |
| 2662 | more than 1,000 repositories or names is 400. Batches count against the |
| 2663 | account's write limit for syncs (section 12). |
| 2664 | |
| 2665 | - `GET /v1/github/sync?batch` and `GET /v1/github/sync/{batch}` → |
| 2666 | `{"batch", "state", "counts", "repos"}`: a batch of the account, its |
| 2667 | latest without `batch` (404 when it has none). `state` is `running`, |
| 2668 | `done`, or `cancelled` when some of its imports were cancelled. `counts` |
| 2669 | holds how many of its repositories are `queued`, `running`, `waiting`, |
| 2670 | `done`, `failed`, `cancelled` and `skipped`; `repos` lists them in the |
| 2671 | batch's order, `{"github_id", "full_name", "hub_name", "state", "error", |
| 2672 | "job"}`, with why each failed or was skipped in `error`. |
| 2673 | - `DELETE /v1/github/sync/{batch}` cancels the batch's imports that have |
| 2674 | not started; those under way go on. It answers the batch. |
| 2675 | - `POST /v1/github/sync/{batch}/retry {"github_id", "name"}` → 202, as |
| 2676 | `POST /v1/github/sync` answers: imports again a repository of the batch |
| 2677 | that failed, was cancelled or was skipped, under `name` if given, else |
| 2678 | the name it had. The batch runs again until the import ends. A |
| 2679 | repository that is queued, running or done is 409; a name that cannot be |
| 2680 | one here is 400, and one taken 409; no room is 403 `quota`; another |
| 2681 | batch running is 409. Retries count against the account's write limit |
| 2682 | for edits. |
| 2683 | |
| 2684 | A batch of another account answers every route as one that does not |
| 2685 | exist: 404 `not_found`. |
| 2686 | |
| 2687 | Each import is a job of the account (section 20), of kind `import`, which |
| 2688 | `GET /v1/jobs` lists with the repository it makes. It ends `done`, or |
| 2689 | `failed` with `error`; while GitHub holds the hub back it is `waiting`. |
| 2690 | |
| 2691 | **What an import does.** |
| 2692 | |
| 2693 | - It looks the repository up on GitHub again by `github_id`, so that one |
| 2694 | renamed since the listing is still found. One that is gone, no longer |
| 2695 | the account's, or no longer shown to its grant fails. |
| 2696 | - It makes the repository here with the history of the default branch, |
| 2697 | from `https://github.com/<owner>/<name>.git` as GitHub names the |
| 2698 | repository now. Until the import is done, the repository answers as a |
| 2699 | missing one to everyone but its owner, and no list shows it: it appears |
| 2700 | whole or not at all. |
| 2701 | - The repository is private or public as above; it takes GitHub's |
| 2702 | description, and those of its topics that are topics here. |
| 2703 | - Its mirror is the GitHub repository, follows it as `follow` says, knows |
| 2704 | its `github_id`, and starts with `synced` at the commit imported, so that |
| 2705 | neither side has anything to send the other (section 11). It gets a |
| 2706 | webhook when the account administers the repository and the mirror |
| 2707 | follows; otherwise the hub polls it. |
| 2708 | - An archived repository is imported without a mirror. An empty one is made |
| 2709 | empty, with its mirror set, and takes its history from the first push to |
| 2710 | GitHub. |
| 2711 | - When GitHub's rate limit for the account's grant runs low, the import |
| 2712 | waits until it resets; when GitHub's secondary limits hold the hub back, |
| 2713 | it waits as long as GitHub says. A failure to reach GitHub, or of git, is |
| 2714 | tried twice more before the import fails. |
| 2715 | - A hub that stops in the middle of a batch goes on with it when it starts |
| 2716 | again: an import cut short leaves nothing, and starts again, at most |
| 2717 | three times in all. |
| 2718 | |
| 2719 | The account hears of it in its inbox (section 21): `import_done` once a |
| 2720 | batch that imported something ends, and `import_failed` for each import |
| 2721 | that fails. |
| 2722 | |
| 2723 | **Syncing a mirror now.** `POST /v1/r/{owner}/{name}/mirror/sync` |
| 2724 | (`admin`, no body): looks at the mirror now and does what its policy says |
| 2725 | (section 11): follows GitHub, merges both, or publishes. A paused mirror |
| 2726 | (`rewritten`) is looked at again, and goes on when GitHub's branch holds |
| 2727 | `synced` again. At most once a minute per repository: sooner is 429 |
| 2728 | `rate_limited`, with `retry_after`. Answers the repository (section 4), |
| 2729 | with the outcome in its `mirror`. A repository without a mirror is 400 |
| 2730 | `invalid`. |
| 2731 | |
| 2732 | **Webhooks.** `POST /v1/hooks/github/{key}`: where GitHub delivers the |
| 2733 | webhooks the hub made, each to an address of its own; nobody else has a |
| 2734 | use for it. A key the hub does not know is 404, answered before the body |
| 2735 | is read. The body, at most 5 MiB (413 `too_large` beyond), must carry the |
| 2736 | webhook's `X-Hub-Signature-256` (401 `unauthorized` otherwise). A verified |
| 2737 | delivery is answered 202 at once, with no body: `ping` and anything but |
| 2738 | `push` do nothing; a delivery whose `X-GitHub-Delivery` came in the last |
| 2739 | day does nothing again; a push to another branch, of another repository, |
| 2740 | or of the commit both sides hold already does nothing; any other push to |
| 2741 | the default branch makes the hub look at the mirror a couple of seconds |
| 2742 | later, at most once every ten seconds. At most 60 deliveries a minute per |
| 2743 | webhook, and 600 verified ones for the whole hub: 429 `rate_limited` |
| 2744 | beyond. A key the hub does not know, and a delivery its webhook's secret |
| 2745 | did not sign, spend nothing of the hub's 600. Nothing of a delivery is |
| 2746 | kept but its id, for a day. |
| 2747 | |
| 2748 | ## 24. Terms, and text and data mining |
| 2749 | |
| 2750 | **Terms.** `GET /terms` is a page with the hub's terms: what it commits to |
| 2751 | about private code, text and data mining of public repositories, and what |
| 2752 | its logs keep, in English and then in Spanish (`#en`, `#es`). Each part is |
| 2753 | a section with an id: `#private`, `#tdm` and `#logs`, and `#es-private`, |
| 2754 | `#es-tdm` and `#es-logs` in Spanish. `#tdm` is where `tdm-policy` leads. |
| 2755 | The terms carry their version and its date at their top (version 1, |
| 2756 | pending legal review). Every page's footer links them, and search engines |
| 2757 | may index them. `GET /terms.md` gives the same text as Markdown, English |
| 2758 | first, `text/markdown; charset=utf-8`. Anyone may read both. |
| 2759 | |
| 2760 | **Text and data mining.** A repository's `tdm` (section 4) is `allowed`, the |
| 2761 | default, or `reserved`, as article 4 of Directive (EU) 2019/790 lets the |
| 2762 | holder of the rights reserve it. `PATCH /v1/r/{owner}/{name}` with `tdm` |
| 2763 | changes it (`admin`). A new repository starts with its owner's |
| 2764 | `tdm_default` (section 3), `allowed` unless the account says otherwise. |
| 2765 | |
| 2766 | Every answer about a public repository whose `tdm` is `reserved`, once the |
| 2767 | caller may read it, carries: |
| 2768 | |
| 2769 | ```text |
| 2770 | tdm-reservation: 1 |
| 2771 | tdm-policy: <hub>/terms#tdm |
| 2772 | X-Robots-Tag: noai, noimageai |
| 2773 | ``` |
| 2774 | |
| 2775 | whatever the route: its pages, its raw files, the API under |
| 2776 | `/v1/r/{owner}/{name}`, its objects and git, and the errors those routes |
| 2777 | answer once the caller's permission is checked (a file that is not there, |
| 2778 | say). Its pages also carry `<meta name="robots" content="noai, |
| 2779 | noimageai">`, `<meta name="tdm-reservation" content="1">` and `<meta |
| 2780 | name="tdm-policy" content="<hub>/terms#tdm">`. Every answer about a private |
| 2781 | repository, to whoever may read it, carries `X-Robots-Tag: noindex, |
| 2782 | nofollow, noai, noimageai`, and its pages `<meta name="robots" |
| 2783 | content="noindex, nofollow, noai, noimageai">`, whatever its `tdm`. An |
| 2784 | answer about a repository the caller may not read carries none of these, |
| 2785 | as one about a repository that does not exist does; nor does any answer |
| 2786 | that names no repository. |
| 2787 | |
| 2788 | **`GET /robots.txt`**: `text/plain; charset=utf-8`, `Cache-Control: public, |
| 2789 | max-age=60`. A group for every crawler (`User-agent: *`) disallows the API |
| 2790 | (`/v1/`), the hub's pages under `/-/` and `/auth/`, raw files |
| 2791 | (`/*/*/raw/`), and the pages `/notifications`, `/settings`, `/login`, |
| 2792 | `/logout` and `/tokens`, each as the page (`/login$`), with a query |
| 2793 | (`/login?`) and below it (`/login/`), never as a bare prefix, which would |
| 2794 | also cover the repositories of the logins that start with it. A second |
| 2795 | group, for the crawlers that gather training data for AI models (GPTBot, |
| 2796 | ClaudeBot, anthropic-ai, CCBot, Google-Extended, Applebot-Extended, |
| 2797 | Bytespider, Meta-ExternalAgent, cohere-ai, cohere-training-data-crawler, |
| 2798 | Diffbot, Amazonbot, AI2Bot, Timpibot, ImagesiftBot, PanguBot, Omgilibot, |
| 2799 | omgili and YouBot), repeats each of those rules, since a crawler follows |
| 2800 | only the group that names it, and adds, for each public repository whose |
| 2801 | `tdm` is `reserved` once something has landed on it: |
| 2802 | |
| 2803 | ```text |
| 2804 | Disallow: /{owner}/{name}$ |
| 2805 | Disallow: /{owner}/{name}? |
| 2806 | Disallow: /{owner}/{name}/ |
| 2807 | Disallow: /v1/r/{owner}/{name}/ |
| 2808 | ``` |
| 2809 | |
| 2810 | with the name as the repository was made and again lowercase when that |
| 2811 | differs, since the hub answers both. An owner every one of whose |
| 2812 | repositories that anyone may read is reserved gets `Disallow: /{owner}/` |
| 2813 | and `Disallow: /v1/r/{owner}/` instead: what the owner says of a |
| 2814 | repository that answers as a missing one never changes the file. Crawlers |
| 2815 | that fetch a page because a person asked them to are not named. |
| 2816 | `robots.txt` never names a private repository. A repository that turns |
| 2817 | private, or whose reservation is taken back, leaves it at once, and one |
| 2818 | reserved or listed since comes in at once; anything else it follows |
| 2819 | within a minute. It holds at most 400 KiB: the rules of every crawler are |
| 2820 | always there whole, and when the reserved repositories do not all fit, |
| 2821 | those of owners not yet established (section 16) go first, then those |
| 2822 | with the fewest stars; a comment says so, and their answers keep their |
| 2823 | headers. |
| 2824 | |
| 2825 | **`GET /.well-known/tdmrep.json`**: `application/json`, `Cache-Control: |
| 2826 | public, max-age=60`, the file of the TDM Reservation Protocol: an array of |
| 2827 | rules for the repositories and owners `robots.txt` names, a repository's |
| 2828 | page, with a query and what is below it, in each spelling, |
| 2829 | |
| 2830 | ```json |
| 2831 | [ |
| 2832 | {"location": "/{owner}/{name}$", "tdm-reservation": 1, "tdm-policy": "<hub>/terms#tdm"}, |
| 2833 | {"location": "/{owner}/{name}?", "tdm-reservation": 1, "tdm-policy": "<hub>/terms#tdm"}, |
| 2834 | {"location": "/{owner}/{name}/*", "tdm-reservation": 1, "tdm-policy": "<hub>/terms#tdm"}, |
| 2835 | {"location": "/{owner}/*", "tdm-reservation": 1, "tdm-policy": "<hub>/terms#tdm"} |
| 2836 | ] |
| 2837 | ``` |
| 2838 | |
| 2839 | (`/{owner}/*` for an owner `robots.txt` names whole), `[]` when nothing is |
| 2840 | reserved. The protocol matches a location as the start of a path unless |
| 2841 | it ends in `$`, so a page's location ends in `$`, and covers no other |
| 2842 | repository whose name starts with that one's. It follows a change as |
| 2843 | `robots.txt` does, and holds at most 400 KiB, its rules a part of those of |
| 2844 | `robots.txt` when not all fit. |
| 2845 | |
| 2846 | ## 25. Verification (main stays green) |
| 2847 | |
| 2848 | The hub can keep a repository's default branch green. A reporter, such as |
| 2849 | a CI job, tells the hub how a suite of tests went on a changeset of the |
| 2850 | branch; the hub keeps two refs that say where the branch stands, names the |
| 2851 | changeset that broke it when it can, and tells the people concerned. The |
| 2852 | hub runs no code of a repository, for this or anything else: every verdict |
| 2853 | comes from a reporter, outside the hub, and the hub only records it, |
| 2854 | moves its two refs and sends notices. A verdict cannot land, revert or |
| 2855 | change anything else. |
| 2856 | |
| 2857 | A hub that verifies branches lists `verify` in the `features` of `GET /v1` |
| 2858 | (section 1). One that does not answers every route of this section 404, |
| 2859 | and its landings carry no `verify`. Only the default branch of a |
| 2860 | repository is verified, and only once an admin turns its policy on. |
| 2861 | |
| 2862 | **The refs.** |
| 2863 | |
| 2864 | - `braid/green/<branch>`: the newest changeset of the branch with a pass |
| 2865 | the hub accepts. It only moves forward, along the branch's first-parent |
| 2866 | chain, but for a reset. |
| 2867 | - `braid/red/<branch>`: while the branch is red, the culprit the hub named |
| 2868 | or, when it named none, the first fail it cannot explain. It exists only |
| 2869 | while the branch is red. |
| 2870 | |
| 2871 | Only the hub moves them, each move an operation of its own, by compare |
| 2872 | and swap, and never in the way of a landing; section 8 says what clients |
| 2873 | may do with them. A client that watches the refs (`…/refs/watch`) sees |
| 2874 | `braid/red/<branch>` come when the branch turns red, and go when it is no |
| 2875 | longer red. |
| 2876 | |
| 2877 | **The policy.** `GET /v1/r/{owner}/{name}/verify/policy` (`admin`) → the |
| 2878 | policy: |
| 2879 | |
| 2880 | ```json |
| 2881 | {"mode": "report", "green_from": ["report"], "flaky_moves_green": false, |
| 2882 | "report": {"suite": "ci", "reporters": ["ci-bot"]}} |
| 2883 | ``` |
| 2884 | |
| 2885 | or `{"mode": "off", "green_from": [], "flaky_moves_green": false}` when |
| 2886 | none was ever set. `PUT /v1/r/{owner}/{name}/verify/policy` (`admin`, a |
| 2887 | body of at most 16 KiB) takes the whole policy, in place of the one |
| 2888 | before, and answers with it as the hub keeps it: |
| 2889 | |
| 2890 | - `mode`: `off`, or `report`, which takes the verdicts of the reporters. |
| 2891 | - `green_from`: the sources whose passes move green: `report`, the one |
| 2892 | source of this version of the protocol. |
| 2893 | - `flaky_moves_green`: whether a flaky changeset moves green too; `false` |
| 2894 | when left out. |
| 2895 | - `report`: `suite`, the label of the suite reported on, 1 to 32 of |
| 2896 | `a-z 0-9 . _ -` that start with a letter or a digit; and `reporters`, |
| 2897 | the logins whose verdicts count, 1 to 10, kept lowercase. |
| 2898 | |
| 2899 | A field the hub does not know, a `mode` other than `off` and `report`, a |
| 2900 | `green_from` that names a source the policy has no block for, a suite or |
| 2901 | reporters outside those bounds, and, with mode `report`, a `green_from` |
| 2902 | that is empty or `report` missing are 400 `invalid`, with a detail that |
| 2903 | says which: nothing is dropped without a word. With mode `off`, an empty |
| 2904 | `green_from` is accepted, as the hub gives it. A change counts toward the |
| 2905 | account's limits as an edit (section 12), and the log records it with the |
| 2906 | admin's login. Turning the policy `off` deletes both refs and forgets how |
| 2907 | the branch stood; turning it on again starts from `unknown`. A change of |
| 2908 | the suite or of the reporters clears red, as a reset does (the log records |
| 2909 | a `reset` whose `other` is `policy`), since the verdicts that set it no |
| 2910 | longer count; the branch turns red again only on verdicts under the new |
| 2911 | policy, and no `verify_fixed` notice goes out. |
| 2912 | |
| 2913 | **Reporting.** `POST /v1/r/{owner}/{name}/verify/report` takes |
| 2914 | `Idempotency-Key` (section 1) and a body of at most 4 KiB: |
| 2915 | |
| 2916 | ```json |
| 2917 | {"git_commit": "<40 hex>", "outcome": "pass", "suite": "ci"} |
| 2918 | ``` |
| 2919 | |
| 2920 | `outcome` is `pass`, `fail` or `flaky` (it failed, then passed when run |
| 2921 | again). The changeset is named by the git commit it exports to, as a |
| 2922 | mirror holds it, or by its id, as `"changeset": "<id>"`: exactly one of |
| 2923 | the two. The hub checks, in this order: |
| 2924 | |
| 2925 | 1. A token: 401 without one; a web session is 403. |
| 2926 | 2. That the caller may read the repository: 404 otherwise, as for one |
| 2927 | that does not exist. |
| 2928 | 3. A `verify:<glob>` right whose glob matches the default branch, of an |
| 2929 | account that may write to the repository (section 5, GitHub's answer |
| 2930 | included): 403 otherwise. |
| 2931 | 4. That no scope of the token that reaches the repository holds `write`, |
| 2932 | `admin`, `land:` or `interact`: 403 otherwise, saying to use a token |
| 2933 | with `read` and `verify:<glob>` only. |
| 2934 | 5. A policy whose mode is not `off`, with `report`, that names the |
| 2935 | account among its reporters: 403 otherwise. |
| 2936 | |
| 2937 | Then the suite must be the policy's (400 `invalid`), the git commit one |
| 2938 | the repository knows (404 `not_found`), and the changeset on the |
| 2939 | first-parent chain of the default branch's head, within 10,000 changesets |
| 2940 | (409 `not_on_branch`, with `head`). A changeset at or below green records |
| 2941 | nothing (`stale`). Otherwise the hub keeps the verdict, one per changeset, |
| 2942 | suite and reporter: the same verdict again is a `duplicate`, and another |
| 2943 | one marks the changeset flaky. It then decides how the branch stands, as |
| 2944 | below, and answers 201 when it kept a new verdict, 200 otherwise: |
| 2945 | |
| 2946 | ```json |
| 2947 | {"effect": "red_set | green_moved | red_cleared | recorded | duplicate | stale", |
| 2948 | "status": <the status, below>} |
| 2949 | ``` |
| 2950 | |
| 2951 | A report weighs 5; a repository takes at most 60 verdicts a minute, and an |
| 2952 | account posts at most 600 an hour (section 12). |
| 2953 | |
| 2954 | **How the hub decides.** After each verdict, reset and change of policy, |
| 2955 | and whenever the branch moves, the hub looks at the changesets above green |
| 2956 | along the head's first-parent chain. With no green yet, it looks at the |
| 2957 | newest 10,000 changesets of the branch: a fail older than those is never |
| 2958 | seen, and `no_green` and the naming of a culprit work within them. |
| 2959 | |
| 2960 | - A changeset's verdict is what its reporters said of the policy's suite: |
| 2961 | a fail with no pass is a fail; a pass with no fail is a pass; reporters |
| 2962 | that disagree, a flaky report, or a reporter that changed its verdict |
| 2963 | make it flaky. Verdicts of another suite do not count. |
| 2964 | - Green moves to the newest changeset with a pass, or with a flaky verdict |
| 2965 | under `flaky_moves_green`, and never backward but by a reset. |
| 2966 | - A fail that a later revert explains does not count: a changeset whose |
| 2967 | `reverts` field names an earlier changeset above green, and whose |
| 2968 | changes are exactly the inverse of that one's, explains every fail from |
| 2969 | the changeset it reverts up to the revert, the revert left out. A field |
| 2970 | that names a changeset without undoing it exactly explains nothing. |
| 2971 | Fails at or below a dismissal (a reset without `green`) do not count |
| 2972 | either. |
| 2973 | - The first fail left is where the branch is red. The newest of green, of |
| 2974 | a pass below the fail and of a revert at or below it is the lower bound |
| 2975 | of the window where the culprit is looked for. When the fail comes right |
| 2976 | after green or after a pass, the window holds it alone, and it is the |
| 2977 | culprit (`decided_by: single`). Otherwise the hub names none, and red |
| 2978 | marks the first fail; a revert as the lower bound names none either, |
| 2979 | until the revert itself passes. A flaky changeset is never a culprit. |
| 2980 | - With no fail left, red goes: the branch is `green` when green is its |
| 2981 | head, and `pending` until the changesets above green have a verdict. |
| 2982 | |
| 2983 | | State | What it means | |
| 2984 | |---|---| |
| 2985 | | `off` | the policy's mode is `off`: the hub verifies nothing | |
| 2986 | | `unknown` | the hub has not looked at the branch since the policy was turned on, or since it dropped green | |
| 2987 | | `green` | green is the head of the branch | |
| 2988 | | `pending` | no fail is left unexplained, and changesets above green wait for a verdict | |
| 2989 | | `red` | a fail is left unexplained: red is the culprit, or the first such fail | |
| 2990 | | `stuck` | red, and the hub can go no further by itself: `code` says why; a reset moves it on | |
| 2991 | |
| 2992 | A client takes any other state, such as `reverting`, `reverted` or |
| 2993 | `paused`, which this version of the protocol does not set, for one that |
| 2994 | is not green. |
| 2995 | |
| 2996 | | Code | What it means | |
| 2997 | |---|---| |
| 2998 | | `culprit_unknown` | more than one changeset separates the last pass from the first fail: no culprit is named | |
| 2999 | | `no_green` | the same, with no green to start from | |
| 3000 | | `hidden` | a revert fails itself, and so hides what it reverted: `stuck` | |
| 3001 | | `range_too_long` | more than 10,000 changesets are above green: `stuck`, red at the newest fail | |
| 3002 | | `green_off_chain` | green was no longer on the branch's first-parent chain, as when the branch was deleted and made again: both refs went, and the branch is `unknown` | |
| 3003 | | `flaky` | the newest verdict is flaky | |
| 3004 | |
| 3005 | **The status.** `GET /v1/r/{owner}/{name}/verify` (`read`, `Cache-Control: |
| 3006 | no-store`, weight 1) → how the default branch stands: |
| 3007 | |
| 3008 | ```json |
| 3009 | {"mode": "report", "branch": "main", "state": "red", "code": null, |
| 3010 | "head": "<id>", "green": "<id>", "red": "<id>", "culprit": "<id>", |
| 3011 | "decided_by": "single", "since": "<time>", |
| 3012 | "window": {"lower": "<id>", "lower_kind": "green", "upper": "<id>", |
| 3013 | "candidates": 1}, |
| 3014 | "pending": [], "round": null, "revert": null, "hold": null, |
| 3015 | "admin": {"lander": "<login>"}} |
| 3016 | ``` |
| 3017 | |
| 3018 | `head` is the head the hub last looked at; `green` and `red` are its refs, |
| 3019 | or `null`; `culprit` the changeset it blames, and `decided_by` how it |
| 3020 | named it (`single`), or both `null`; `since` when the branch turned red. |
| 3021 | `window`, while the branch is red, is where the culprit is looked for: the |
| 3022 | `candidates` changesets above `lower` (`lower_kind` says what it is: |
| 3023 | `green`, `pass`, `revert`, or `none` when there is no lower bound) up to |
| 3024 | `upper`. `admin` names who landed the culprit, to the repository's admins |
| 3025 | only, and is `null` for anyone else. `pending`, `round`, `revert` and |
| 3026 | `hold` are empty or `null` in this version of the protocol. With mode |
| 3027 | `off`, the answer is `{"mode": "off", "state": "off", …}`, every other |
| 3028 | field `null` or empty. The status reads what the hub keeps, and walks no |
| 3029 | history. |
| 3030 | |
| 3031 | **The log.** `GET /v1/r/{owner}/{name}/verify/log?after&limit` (`read`, |
| 3032 | weight 5) → `{"events": [{"id", "at", "code", "changeset", "other", |
| 3033 | "actor"}], "next"}`: what verification did, newest first, `limit` (1 to |
| 3034 | 100, 30 when it is left out) at a time. `after` is the `next` of the page |
| 3035 | before, the id of its last event, and `next` is `null` on the last page. |
| 3036 | `code` is `policy`, `green`, `red`, `culprit`, `fixed`, `stuck`, `reset` |
| 3037 | or `flaky`; `changeset` the changeset it is about, or `null`; `other` an |
| 3038 | id or a code that goes with it, or `null`; `actor` the login that did it, |
| 3039 | `null` for the hub, and for callers who are not the repository's admins. |
| 3040 | |
| 3041 | **Resets.** `POST /v1/r/{owner}/{name}/verify/reset` (`admin`, takes |
| 3042 | `Idempotency-Key`, a body of at most 4 KiB; 400 `invalid` while the |
| 3043 | policy is `off`, since there is nothing to reset): |
| 3044 | |
| 3045 | ```json |
| 3046 | {"green": "<id> | null", |
| 3047 | "expect": {"green": "<id> | null", "red": "<id> | null"} | null} |
| 3048 | ``` |
| 3049 | |
| 3050 | With `green`, green moves to that changeset, backward too; it must be on |
| 3051 | the first-parent chain of the head (400 `invalid` otherwise). The verdicts |
| 3052 | given before the reset on the changesets above it are forgotten, so that |
| 3053 | the reset holds: green moves on, and red comes back, only on verdicts |
| 3054 | given after it. Without `green`, the fails there are now are dismissed: |
| 3055 | they no longer count, and only a new one turns the branch red again. |
| 3056 | Either way red is cleared, and the log records a `reset` with the admin's |
| 3057 | login. With `expect`, the hub resets |
| 3058 | only while green and red are what it says, `null` for a ref that does not |
| 3059 | exist (409 `moved` otherwise). It answers the status. |
| 3060 | |
| 3061 | **Notices.** `verify_red`, `verify_fixed` and `verify_stuck` tell the |
| 3062 | repository's admins, and for a red branch with a culprit the account that |
| 3063 | landed it, in their inbox (section 21). A repository sends at most one |
| 3064 | every 10 minutes: a change within them is told once they are over, as the |
| 3065 | branch then stands. When the hub names a culprit, or another one, while |
| 3066 | the branch stays red, `verify_red` tells the account that landed it. |
| 3067 | |
| 3068 | **From CI.** A CI job reports with a token made for that alone, on the |
| 3069 | tokens page (section 14): `read` and `verify:<branch glob>` on the |
| 3070 | repository, and nothing more, of an account that may write to it and that |
| 3071 | the policy names as a reporter. It passes the token in `BRAID_TOKEN`, and |
| 3072 | the hub in `BRAID_HUB_URL`, from its secrets, and runs `braid hub verify |
| 3073 | report` (section 13) once its tests ran, with the git commit they ran on. |
| 3074 | Such a token reads the repository and says how its tests went, and does |
| 3075 | nothing more: it cannot upload, land, comment or approve. |