gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainfe209ffeMerge branch 'w56-owner-members' into mainGitoriamain/reports/E38-push-api-eval.md

30.3 KB

  1. # E38 — Evaluation: a push API for outside apps (gitoria#38)
  2. Ticket: https://tickets.worldapi.org/gitoria.worldapi.org/38
  3. to interact with gitoria. first use case being a code reviewer. The external reviewer built the reference reviewer over the past two weeks, a code rabbit
  4. replacement for github. basically we want the external reviewer now to build a similar tool with gitoria and hybriel."
  5. This is an evaluation. No code was written. Read: WORKER-RULES, CONCEPT, DECISIONS, README, project.hl, docs/git-backend.md,
  6. fetch/crypto/time plugin READMEs. Not read: lib/code.hl and the commit page (see "not checked").
  7. ## 0. Short answer
  8. Recommendation: **Option B** — per-repo "apps" registered by the repo owner with the tickets-style connect flow, one
  9. signed HTTP POST per event, and a small token-checked back-channel (read diff, post comment, set a verdict). It costs
  10. about 10 work steps (medium). Gitoria today has NO diff, NO PR comments, NO PR verdict and NO event hook, so most of
  11. the work is the back-channel and the diff, not the push itself. Build the diff first: it is useful for gitoria's own UI too.
  12. Follow-up goal (section 9): the apps become reviewer AND deployer (a review container per PR). Option B still fits, with three
  13. additions that are now required, not optional: a stable PR number, a "preview" link/status on the PR, and event delivery that
  14. covers closed-without-merge. The deployer is a second app of the same kind and needs the same token/secret/back-channel.
  15. ## 1. What gitoria has today, and what a reviewer still needs
  16. Has (all verified in code):
  17. - **A PR is a commit.** lib/pulls.hl: a commit whose subject starts `|||PR ` (target = repo main branch) or `|||PR|<branch>] `.
  18. "Nothing is stored: the list is read from git each time" (`pulls()`, scans the last 500 commits, max 50 PRs, one per source
  19. branch). State is only `open` or `merged` (merged = the PR commit is an ancestor of the target). A PR has no id other than
  20. the 40-hex sha of its `|||PR` commit (`mergePullNow` finds it again by that sha). The sha changes if the PR commit is
  21. rewritten; there is no stable PR number.
  22. - **Merge** exists: `mergePullNow` (owner only, `merge-tree --write-tree` + `commit-tree` + `update-ref` with old value).
  23. Note: DECISIONS.md (2026-09-25, gitoria#13) says "no, the final button click comes from the dev" — it reads as "gitoria
  24. does not merge"; the code since gitoria#17 has a Merge button the owner clicks. Both fit "the dev clicks", but a reviewer
  25. app must never merge: the back-channel below does not offer merge.
  26. - **Users, tokens**: lib/tokens.hl — `gtr_` + 40 hex, per USER, only the sha256 stored, shown once, max 20, no scopes. A token
  27. acts as that user for git over HTTPS only (transport.hl `userOfToken`). `idt_` ident access keys (read/write) also work there.
  28. - **Rights**: lib/repos.hl `mayRead`, `mayPush` (= `isInside`: owner, repo member, org owner/org member), `ownsRepo(slug, session)`;
  29. private repos answer as "no such repository" (GO34, #34). Private means a push webhook payload and any diff are secrets.
  30. - **Function routes**: lib/api.hl + project.hl `routes` (`{ pattern function = (route, req) => … }`). Today's API is read-only:
  31. `GET /api/repos`, `GET /api/repos/:slug` (+ Markdown view). No write route exists except the connect flow and `/__git/*`.
  32. - **An "app registers with app" flow already exists** (tickets.hl `finishConnect`, see section 2).
  33. - **Git reading helpers**: `git()`/`gitRaw()` in lib/git.hl run the git binary in the bare repo; docs/git-backend.md lists
  34. `diff a...b`, `show`, `diff-tree -p --numstat` as "yes (#11)" — meaning feasible, not built.
  35. Missing for a reviewer:
  36. 1. **No diff.** README line 218: "Not built: … a diff of a commit". No PR diff either. (I did not open lib/code.hl; the README is
  37. the source.) The reviewer needs `git diff <target>...<source>` (three dots = what the PR adds) as unified text + a file list.
  38. 2. **No comments on a PR (or on anything).** Searched README, CONCEPT, pulls.hl: no comment store, no line comment. The only
  39. "comments" are posted TO tickets by notifyPush. A review result needs a place to live: either a new table in gitoria
  40. (`reviewsTable`: slug, pr-sha, app, file, line, text, created) or comments pushed into the linked ticket (see option C).
  41. 3. **No status/verdict** on a PR (e.g. "reviewed: 3 notes", "approved", "changes requested").
  42. 4. **No event hook.** transport.hl says "No hook: pull requests and releases are read from the commits when their page is built."
  43. docs/git-backend.md planned `post-receive → /__git/pushed` and "Webhooks / CI triggers: fan-out from post-receive — later";
  44. it is not built. The only hook-like point is `notifyPush(slug, false)` in transport.hl after a receive-pack answer, and in
  45. the Merge button (README ~line 238).
  46. 5. **No new-commit detection per PR.** The PR is a commit on a branch; "a new commit on the PR branch" is a ref moving, which
  47. gitoria never records. notifyPush de-duplicates with `seenTable` (key `slug commit sha n`) — the same trick can store the
  48. last seen tip per PR branch.
  49. 6. **Server-side event raising has no old/new ids** (the push body goes straight to `git receive-pack`; gitoria does not parse
  50. the ref updates). Two ways: parse the pkt-line commands at the start of the request body (before calling git), or compare
  51. `for-each-ref` snapshots before and after the call (simple, costs two git calls per push).
  52. 7. **No outgoing-app registry** and no hook for the owner to list or remove apps.
  53. ## 2. Registration
  54. Facts: tickets' connect flow (antcolony-docs/docs/tickets-connect-apps.md, gitoria tickets.hl/api.hl):
  55. 1. owner clicks Connect in the repo's settings → `/settings/connect` parks a nonce in the session (bound to the repo, owner only
  56. via `ownsRepo`) and redirects the browser to the other app's `/connect?app&label&return&state`;
  57. 2. the other app logs the person in (ident), asks for confirmation, redirects back to `return?code=&state=`; code valid 5 min, once;
  58. 3. gitoria's SERVER exchanges the code (`POST /api/connect/exchange {code}` → `{key, project, title, api}`), stores the key per repo
  59. (never shown to a page); every write carries `Authorization: Bearer <key>` + `X-Tickets-Identity`;
  60. 4. the admin on the tickets side can disconnect (key dies); a re-connect of the same app+label replaces the key.
  61. The tickets flow runs in the direction "gitoria is the CLIENT of tickets". For a reviewer app the roles reverse: **gitoria is the
  62. SERVER, the reviewer is the client.** The pattern still fits (browser redirect, one-time code, server-side exchange, key shown
  63. once) with gitoria playing tickets' role. Where it fits and where it does not:
  64. - Fits: owner-confirmed, no secret in a URL, no copy-paste, code is one-time, state is a nonce, `return` restricted to
  65. `worldapi.org` and subdomains (tickets does this; reuse the same rule — it also blunts SSRF and open redirect).
  66. - Does not fit as is: gitoria's `tktKey` is stored per repo in `repos.db` as a single connection; a repo may need several
  67. apps (reviewer, CI, ...). So a new table `appsTable` (not extra fields in `repos.db`): `{ repo, name, label, hookUrl, secretHash/secret,
  68. tokenHash, rights, createdBy, created, lastDelivery, lastStatus }`.
  69. Three registration shapes:
  70. - **R1 per repo, by its owner, connect flow (recommended).** Owner opens Settings → "Apps" → Add; the app's start URL
  71. `https://<app>/connect-gitoria?repo=<slug>&return=…&state=…`. Permission = owner (`ownsRepo`), same as the tickets connect.
  72. Exchange returns `{ token (gap_… 40 hex), secret (webhook signing key), api: https://<slug>.gitoria…/api/… }`.
  73. - R2 per user (the user makes an app token like `gtr_` tokens). Simple but a user token reaches ALL the user's repos, including
  74. private ones (#34). Too much for a reviewer. Reject for apps; keep for scripts.
  75. - R3 manual form: owner types a hook URL and gets a secret + token shown once (GitHub/Gitea webhook style). No second app is
  76. involved, so no confirmation roundtrip. Cheapest; good fallback when the app is not a WorldAPI app.
  77. What the app gets: an **app token** of its own kind (`gap_` + 40 hex; store sha256 only, as tokens.hl does) bound to ONE repo
  78. and a list of rights: `read` (diff, files, PR list), `comment` (post review comments), `status` (set a verdict). No `push`,
  79. no `merge`, no `settings`, no other repo, no tickets key. Token check = a new `appOfToken(secret)` next to `userOfToken` in a new
  80. lib/apps.hl; the route additionally compares the token's repo to the URL's repo. Private repo: the token's repo is the only one
  81. it sees, so GO34 holds. Do NOT reuse `gtr_` user tokens for the back-channel: they carry the owner's full rights.
  82. Posting identity: comments are authored "app: <name>" (a bot), not as the owner (unlike notifyPush, which acts as the owner).
  83. Removal: Settings → Apps → Remove deletes the row: token and secret die at once; pending deliveries are dropped. Also "Rotate
  84. secret". An app can remove itself with `DELETE /api/repos/:slug/apps/self`. The ident id of the owner stays in the row for audit.
  85. Who may register: the repo owner only (DECISIONS: "owner"); members are not asked; an org repo → its org owner (open question 5).
  86. ## 3. Push (events out)
  87. Events (names after GitHub's `X-GitHub-Event` for easy porting):
  88. | event | when | raised where |
  89. |---|---|---|
  90. | `push` | any ref moved (branch created/updated/deleted), includes push to main | transport.hl, in the `git-receive-pack` branch where `notifyPush(slug, false)` is called today |
  91. | `pull_request` `opened` | a `|||PR` commit appears on a branch that had none | same place; diff the PR list (`pullsNow`) before/after |
  92. | `pull_request` `synchronize` | the PR's source branch got new commits | same place; compare branch tip to last seen tip (store in a table like `seenTable`) |
  93. | `pull_request` `closed` + `merged:true` | Merge button, or `git merge` + push | api/components merge face (`mergePullNow` returns ok) and the push path |
  94. | `ping` | right after registration | the exchange step |
  95. Payload (JSON, small; the app reads details through the back-channel, not from the payload):
  96. ```
  97. { "event":"pull_request", "action":"opened", "delivery":"<uuid>", "time":"2026-10-31T12:00:00Z",
  98. "repo":{"slug":"reviewer","private":false,"api":"https://reviewer.gitoria.worldapi.org/api"},
  99. "pull":{"id":"<sha of the |||PR commit>","title":"…","source":"feature-x","target":"main","head":"<tip sha>","base":"<merge-base sha>"},
  100. "sender":{"name":"<display name of pusher>"} }
  101. ```
  102. For `push`: `{ref, before, after, commits:[{id, subject, author}] (max 20)}`. No file contents in a payload (size, secrets).
  103. The PR id problem (section 1): use the `|||PR` commit sha as `pull.id` for now; a stable number is an open question.
  104. Delivery:
  105. - HTTP POST, `Content-Type: application/json`, headers `X-Gitoria-Event`, `X-Gitoria-Delivery` (uuid, same on redelivery),
  106. `X-Gitoria-Signature-256: sha256=<hex HMAC-SHA256(secret, raw body)>`, `User-Agent: gitoria`. Same shape as GitHub's
  107. (GitHub docs: delivery id header guards replay; secret should be high entropy; 2xx within 10 s else counted as failed;
  108. GitHub does NOT retry automatically, redelivery is manual or by script — checked on docs.github.com 2026-10-31).
  109. - **Timeout 10 s, no redirects followed** (fetch has `maxRedirects`; 0 returns the 3xx as the response — plugins/fetch).
  110. - **Retries** (gitoria should do better than GitHub): queue row per delivery in `deliveriesTable`
  111. `{app, event, body, tries, nextAt, status}`; retry after 1 min, 5 min, 30 min, 2 h, then mark `failed`. The app can also
  112. list missed deliveries and redeliver: `GET /api/repos/:slug/deliveries`, `POST …/deliveries/:id/redeliver`.
  113. Retention 7 days, max 200 rows per app, otherwise a dead app fills the disk.
  114. - **App down**: push is never failed or slowed by it (like notifyPush: "Failures are silent (the push has succeeded)"). After
  115. N failed days the app is shown red in Settings; the app reconciles by asking `GET …/pulls` (state is derivable from git at
  116. any time because PRs are stored nowhere). This makes lost events harmless: the app should poll once on start.
  117. - Idempotency: the app must treat the same `delivery` id as already done. Receiver should be quick (ack, then work).
  118. ## 4. Back-channel (app → gitoria), token check on every route
  119. Auth for all: `Authorization: Bearer gap_…`; the route finds the app, checks the token's repo == the URL's repo and the right.
  120. Base: `https://<slug>.gitoria.worldapi.org/api/…` (org repos: `<org>.gitoria…/api/<repo>/…`, same as the page paths in GO34).
  121. Answers are JSON; 404 for a repo/PR the token does not reach (same "does not exist" rule as GO34).
  122. | route | right | what |
  123. |---|---|---|
  124. | `GET /api/pulls` | read | the PR list (JSON form of `pulls()`: id, title, source, target, state, head, base) |
  125. | `GET /api/pulls/:id` | read | one PR, id = the `|||PR` commit sha |
  126. | `GET /api/pulls/:id/diff` | read | unified diff `target...source` as text, with `?files=1` file list and `?max=` size cap; truncated flag |
  127. | `GET /api/files?ref=&path=` | read | one file at a commit (`git show ref:path`), cap 1 MB; for context beyond the diff |
  128. | `GET /api/commits/:sha` | read | message + parents + diff of one commit |
  129. | `POST /api/pulls/:id/comments` | comment | `{text, file?, line?, side?, commit?}` general or line comment (Markdown, max 20000 chars) |
  130. | `POST /api/pulls/:id/reviews` | comment | `{verdict: "comment"|"approve"|"changes", summary, comments:[…]}`, one review in one call |
  131. | `PUT /api/pulls/:id/status` | status | `{state: "pending"|"success"|"failure", label, text, url?}` shown as a badge on /pulls |
  132. | `GET /api/deliveries`, `POST /api/deliveries/:id/redeliver` | read | missed events |
  133. Not offered: merge, push, delete branch, settings, tickets. The owner clicks Merge.
  134. Where a comment goes: **gitoria#1 data**. A new `commentsTable` (pk @id, indexes `pr`, `app`); rendered on /pulls under the PR
  135. and a PR page. A verdict also becomes a status row. Since PRs are not stored, comments are keyed by `pr sha` and a line comment
  136. keeps `commit` (the head sha it was written against) so a moved branch shows "outdated" instead of lying.
  137. Output hygiene: comment text is Markdown rendered by lib/markdown.hl — check that it escapes HTML (not checked here).
  138. Rate limit: per app token, e.g. 60 writes/min and 200 reads/min (gap: see section 6).
  139. ## 5. Options
  140. ### Option A — Minimal: signed webhook + read API, no stored comments (small, ~5 steps)
  141. Steps: (1) `appsTable` + R3 manual registration in Settings (URL, secret shown once, token shown once); (2) event raise in
  142. transport.hl + HMAC sign + one-shot POST; (3) `GET /api/pulls`, `…/diff`; (4) `/api/…` token check; (5) remove/rotate.
  143. The reviewer posts its review as a **ticket comment** through the tickets connect it already knows? No — only gitoria holds the
  144. tickets key. So in A the reviewer has no way to show results inside gitoria; it must show them on its own site. Weak first use case.
  145. Risks: small. Use when only a CI trigger is wanted.
  146. ### Option B — Recommended: per-repo apps with connect flow, retry queue, comments and status (medium, ~10 steps)
  147. 1. `lib/diff.hl`: PR diff + file list + commit diff (`git diff --no-color --no-ext-diff -M target...source`, size caps).
  148. Needed for gitoria's own UI too (README says "Not built").
  149. 2. `lib/apps.hl`: `appsTable`, token `gap_`, `appOfToken`, rights, create/remove/rotate.
  150. 3. Connect flow (R1) routes in api.hl + project.hl: `/settings/apps/add`, `/settings/apps/connected`, `/api/apps/exchange`
  151. (the same state/nonce/`ownsRepo` pattern as `connectStart`/`connectBack`); R3 as manual fallback.
  152. 4. Event raising: parse before/after refs in transport.hl; PR opened / synchronize / merged detection (tip table).
  153. 5. `deliveriesTable` + sender: HMAC-SHA256, POST, retry schedule, retention (framework gap: where does it run? see section 6).
  154. 6. `commentsTable`, `statusTable`; routes of section 4 with token check and rights.
  155. 7. Render comments and status badges on /pulls (components/pulls.hl) with owner delete.
  156. 8. Settings → Apps page (list, last delivery status, remove, rotate, redeliver).
  157. 9. Tests: HMAC vector, SSRF guard, token of repo A refused on repo B, private repo, retry after downtime, duplicate delivery.
  158. 10. Docs: `docs/apps-api.md` for the external reviewer (events, payloads, curl examples) and README/DECISIONS entries.
  159. 11. (Goal of section 9) A stable PR number per repo, a `closed` event for a PR whose branch is deleted or force-moved, the
  160. `preview` link field on the status route and its badge on /pulls. About +3 steps: B is then ~13 steps.
  161. Also split: steps 1 and 2–6 can ship in two PRs.
  162. ### Option C — Full GitHub-App clone with generic scopes and a marketplace (large, 20+ steps)
  163. Per-app identities, user installation across many repos, scopes, org-wide install, event subscriptions per app, app manifest,
  164. OAuth-style user tokens, webhooks for every gitoria object (issues, releases), pagination and versioned API. Nothing in
  165. the task asks for it. Do later, if more than one app exists and a second use case shows what a scope should be.
  166. ### Variant of B: comments go into the linked ticket
  167. If the repo is connected to tickets, the review could be posted by gitoria as a comment on the ticket named by the PR (`fixes #N`),
  168. using `commentTicket`. Pro: no comment table. Con: only PRs with a ticket reference; a review per line does not fit; tickets'
  169. role rules apply and the comment would be posted as the owner. Use as an add-on only, not the base.
  170. ### Risks (all options)
  171. - **Secrets**: hook secret and token shown ONCE and stored hashed (token) / encrypted or at least never sent to a page
  172. (the HMAC secret must be readable by the server to sign: store it in `apps.db` file with mode 0600 like `tktKey` today,
  173. which sits in repos.db in plain text — same exposure class; flag it, don't hide it). Never log tokens (follow `connectLog`:
  174. "never the code, the state value or a key"). Timing: compare hashes, not strings, as `userOfToken` does via index lookup.
  175. - **SSRF through the registered hook URL** (gitoria's server will POST to a URL a user typed in R3): restrict to `https://`,
  176. host must resolve to a public address (refuse 127/8, 10/8, 172.16/12, 192.168/16, 169.254/16, ::1, fc00::/7, and the docker
  177. network names); re-check at send time (DNS rebinding), do not follow redirects, cap response read, fixed timeout, no custom
  178. headers from the owner. The connect flow R1 narrows this to `worldapi.org` and subdomains (tickets rule) — a strong
  179. reason to prefer R1. FRAMEWORK GAP: hl:fetch README shows no way to pin the resolved address or refuse private ranges —
  180. the check has to be done before the call by resolving separately; hl has no documented DNS resolve call → ask Hybriel.
  181. - **Private repos (#34)**: a payload for a private repo goes only to an app the owner registered; the diff route answers 404
  182. to any other token; an app token never works across repos; a repo turned private later keeps its apps (decide: keep, owner's
  183. choice); a repo moved with `tools/move-repo.hl` (name changes, "the old name forwards") — the app row must follow the repo's
  184. id (`repo.id`), not the slug, and payloads must carry the new slug. The org case: apps of a private org see only the repo registered.
  185. - **Prompt injection / abuse by content**: the reviewer app (an LLM tool) reads attacker-controlled diffs; it must not hold
  186. any right beyond comment and status, which is why `merge` and `push` are not in the list.
  187. - **Load**: a diff of a huge commit blocks the single server (git runs by `hl:proc`, `callGit` has 300 s). Cap output, cap
  188. concurrency per token.
  189. - **Replay**: delivery id + timestamp in a header; the receiver should reject bodies older than 5 minutes.
  190. - **Comment spam**: per-app rate limit and a max number of comments per PR; owner can delete and remove the app.
  191. - **DECISIONS.md**: no decision of the creator covers apps. Section "pull requests" says the dev does the final click: the
  192. plan respects it (no app merge).
  193. ## 6. Framework gaps (Hybriel / hl:web) — checked in HL-PRIMER and the plugin READMEs; not guessed
  194. 1. **Background work / queue**: the primer says "Every call is awaited. There is no async". `hl:time` has `every(s)`, `after(s)`
  195. timers and `hl:proc` has `spawn`. A delivery sender must not run inside the push request (a slow app would delay `git push`;
  196. `fetch` blocks until answer or `timeoutMs`). A timer (`every(30)`) that reads `deliveriesTable` is likely the way; nothing
  197. in the primer says a function route may spawn work that outlives its request. **Gap line: no documented request-detached
  198. task.** Fallback: send deliveries from an `every` tick only, and let the push route just write a row (cheap, no blocking).
  199. 2. **HMAC**: crypto README documents ES256, ECDH, HKDF, AES-GCM, base64url. Gitoria already uses `sha256` and `randomBytes` from
  200. hl:crypto, and the primer lists `hash`/`verify`. **HMAC-SHA256 is not documented.** HMAC can be built from sha256 by hand
  201. (ipad/opad with the 64-byte block; needs bytes XOR) but a built-in is safer. Gap. Alternative in tokens-style: send the
  202. secret as a header (`Authorization: Bearer`) — weaker (the secret travels), only if HMAC is not available.
  203. 3. **SSRF guard / DNS**: no resolve or "refuse private ranges" option in hl:fetch (see section 5). Gap.
  204. 4. **Raw request body in a function route**: transport.hl already reads `req.body` (a String of raw bytes) — fine for a POST with
  205. JSON. No gap. Request-body size limit exists (`uploadMax`) in WebFramework.
  206. 5. **Response for a long diff**: no streaming; the diff is built in memory by `gitRaw` (capped by `lines`?) → needs an explicit cap.
  207. 6. **Rate limit**: no limiter in the primer; build with a table or in memory by token and minute. Minor gap.
  208. 7. **Function routes for write** with the session store by reference are described in api.hl (`&req, &sessions`); a bearer-token
  209. route needs no session, so ordinary `(route, req) =>` works (as `gitKeys` and `gitAccess` do). No gap.
  210. 8. **Dev tests**: no HTTP mock receiver in the repo's tests that I read (not checked tests/); a hook receiver for tests needs a tiny
  211. 9. (Goal of section 9) **Timers in the app**: docker-compose.yml says "gitoria has no background jobs or timers". The retry queue
  212. and any expiry job would be the first. A timer is documented in hl:time (`every`), but is untested in gitoria and the
  213. standby swap (two processes on one bind mount, see deploy.sh step 4) would run it twice: a job needs a lock row. Gap.
  214. 10. (Goal of section 9) **Starting containers is not gitoria's job and not hl:web's**: no framework feature is involved; the
  215. deployer is a separate service with its own access to docker. Not a gap, but it means Option B has no framework support for it.
  216. local route. Minor.
  217. ## 7. Open questions (one word each)
  218. 1. Who builds the reviewer and where does it run — the external reviewer in a separate repo, or a module inside gitoria? (the external reviewer decides; the plan assumes separate.)
  219. 2. Reviewer hosted on worldapi.org (subdomain) or elsewhere? (decides whether R1 `return` can be limited to worldapi.org: yes/no)
  220. 3. May the reviewer app merge PRs ever? (plan says no — yes/no)
  221. 4. Must reviews also show inside gitoria's pages (/pulls), or may the app show them on its own site? (inside/outside)
  222. 5. Org repos: may the org owner register an app for the whole org (all repos)? (yes/no)
  223. 6. Private repos: does the reviewer (an LLM service, code leaves the server) get private repos too? (yes/no)
  224. 7. Need a stable PR number (#1, #2…) instead of the commit sha? (yes/no)
  225. 8. Should apps also be allowed for a second use (CI, notifier) from day one, or reviewer only? (reviewer/more)
  226. 9. Does hybriel get HMAC and request-detached tasks, or does gitoria build around them? (hybriel/gitoria)
  227. 10. Is the hook secret allowed in plain text in storage (like `tktKey`)? (yes/no)
  228. ## 8. Not checked
  229. lib/code.hl and the commit component (whether a commit diff view exists despite the README line), components/pulls.hl,
  230. markdown.hl HTML escaping, tests/, the fetch plugin README beyond its header, CodeRabbit's own docs (the GitHub App shape is
  231. known from GitHub's docs only: webhook + installation token + REST review comments), Gitea/Forgejo webhook docs
  232. (shape follows GitHub's: `X-Gitea-Signature` HMAC-SHA256 hex — taken from memory, not fetched here, treat as unverified).
  233. ## 9. PR-focused development: review containers
  234. caramboleyo's goal (unchanged): "with the code reviwere in the making we then start to move to a PR focused development. full goal
  235. here is to auto deploy PRs in an own review container. features can then be merged by me, when i accept them. smaller and utility
  236. things directly from you." Read for this: deploy.sh, docker-compose.yml, Dockerfile, CONCEPT.md.
  237. ### (a) Does option B still fit?
  238. Yes. A deployer is a second registered app: same registration, token, signed events. What changes: a lost `closed` event leaves a
  239. container running, so the retry queue (section 3) is a must, and the deployer reconciles at start (`GET /api/pulls` vs its running
  240. containers; state is derivable from git). Events that drive it: `opened` → build + start `pr-<n>`, status pending→success with url;
  241. `synchronize` → rebuild, replace; `closed` merged → remove container and data; `closed` not merged → same. Gitoria has no "closed
  242. without merge" today (a PR is only `open` or `merged`, pulls.hl): new, raised when the source branch disappears.
  243. ### (b) What the deployer needs from gitoria
  244. 1. Events with `number` and `head` sha (payload of section 3 plus `number`).
  245. 2. **A stable PR number.** None today: the id is the sha of the `|||PR` commit and changes when that commit is rewritten. Container
  246. name/address `pr-<n>` needs a number never changed or reused: table `{repo, source branch, target → n}`, n = max+1 at first sight (~1 step).
  247. 3. Read access to the code at `head`: an app right `clone` (read-only, this repo only, as the HTTPS git password like `idt_` keys) or
  248. `GET /api/archive?ref=<sha>` (tar, size cap).
  249. 4. A status with a link: `PUT /api/pulls/:id/status {state, label, text, url}` shown as "preview: <url>" on /pulls. `url` must be https
  250. on the preview zone the owner set for that app (no other host, no javascript:), so an app cannot put a foreign link on a repo page.
  251. 5. Env/secrets for review containers: not stored by gitoria (question).
  252. ### (c) How deploy works today (deploy.sh, docker-compose.yml, Dockerfile)
  253. - deploy.sh runs ON LOREANA: 6 gates (node tests, check-theme, Chrome) → backup of live storage/.sessions/.env to /media/SLOW1TB2 →
  254. rsync of the CODE (never storage/.env) to [email protected]:/CONTAINERS/projects/gitoria.worldapi.org → standby swap (standby on
  255. 45014 answers 200, main 45004 restarts, standby stops) → sshd container rebuilt → public URL must answer 200 (up to 120 s).
  256. - The Dockerfile has no code (debian:12-slim + libssl3 + ca-certificates + git + openssh-client). Code = bind mount `./:/home/gitoria`,
  257. `bin/hybriel project.hl` compiles at each start (~20 s). `network_mode: host`, `HL_HOST=127.0.0.1`, port 45004. nginx ends TLS; vhost
  258. `gitoria.worldapi.org *.gitoria.worldapi.org`; wildcard DNS and certificate are the architect's. Ident knows ONE origin for login.
  259. compose says "gitoria has no background jobs or timers".
  260. - CONCEPT.md: "deploy.sh yes, until gitoria does it automatically" — automatic deploy is the stated end state, nothing says how.
  261. - A human runs the gates today; a PR deploy has nobody at the keyboard.
  262. Per-PR container, nothing built — it needs:
  263. - **Code**: `git archive <head>` into a folder on Byrodin; the bind-mount pattern needs no image build.
  264. - **Port**: one per container on 127.0.0.1 from a range with a used-ports table (main 45004, standby main+10).
  265. - **Address**: `pr-<n>.<slug>.gitoria.worldapi.org` has TWO labels below `*.gitoria…`: the wildcard cert covers one label, and gitoria reads
  266. the first label as a repo/org slug (`slugOfHost`; one shared namespace, `pr-3` could clash). Prefer a separate zone with its own wildcard
  267. DNS, cert and an nginx map host→port (architect's, like today).
  268. - **Data**: its own empty storage, never the live bind mount or live `.env`; copying live data would copy users and private repos (#34).
  269. - **Login**: a review address is a new ident origin, or no login there (ident's rule, not gitoria's).
  270. - **Cleanup**: on closed/merged, plus a timer (older than N days, global cap); free folder, port, vhost; reconcile at deployer start.
  271. - **Security**: a PR runs its author's code on Byrodin. No live storage mount, no docker socket, and NOT `network_mode: host`
  272. (that would reach ident :45002 and gitoria :45004 on loopback). Cap concurrent builds.
  273. - **Who runs it**: not gitoria (no timers, no docker). A deployer service on Byrodin that talks to gitoria only through the API.
  274. ### (d) "merged by me, when i accept them"
  275. - Code: the Merge button (`mergePullNow`, gitoria#17) works only for the repo owner (`withMerge`: `canMerge = owner && mergeable`).
  276. DECISIONS.md 2026-09-25 #13: "no, the final button click comes from the dev"; the "means" line (librarian's reading, not his words)
  277. says gitoria has no Merge button. His words fit an owner-click button; the code matches his words, the reading is off.
  278. "merged by me" = the same: no code change; the librarian may fix the reading (not done here).
  279. - Reviewer and deployer never merge: no `merge` right, no such route. A `success` status is information only. Members can push but
  280. not merge (owner only).
  281. - Both merge paths (button, `git merge` + push) must raise `closed`+`merged`.
  282. ### (e) "smaller and utility things directly from you"
  283. - Direct pushes to main by the owner's agents stay allowed (`mayPush`; no protected branches, docs/git-backend.md "later"). Do not add any here.
  284. - Events: it is a `push` event with `ref = refs/heads/main`; no PR, so no review container and no `pull_request` event. The reviewer
  285. sees it only if it also listens to `push` on main.
  286. - Whether a push to main (merge or direct) deploys LIVE is decided by nobody. Today it is a hand-run deploy.sh with gates and backup;
  287. an auto deploy would skip them unless the deployer repeats them. Question only; gitoria's part is the event.
  288. ### New open questions (one word each; numbers continue section 7)
  289. 11. Where does the deployer run and who builds it? (who) 12. Review address: separate zone or under `*.gitoria…`? (zone/gitoria)
  290. 13. Login in review containers? (login/none) 14. Copy of live data into reviews? (yes/no; plan: no)
  291. 15. Push to main deploys LIVE automatically? (yes/no) 16. Reviewer also looks at direct pushes to main? (yes/no)
  292. 17. Merge disabled while status is `failure`? (yes/no) 18. Deploy gates per PR? (gates/none)
  293. 19. Stable PR numbers #1, #2… never reused (replaces question 7)? (yes/no) 20. Containers for PRs of members, not only the owner? (yes/no)

Branches

Latest commits

  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre