gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitea587d90ea587d90gitoria#44: reviews with inline threads, replies, resolve and the PR conversation for apps (lib/reviews.hl, tests/reviews.mjs)mreea587d90/project.hl

13.4 KB

  1. // project.hl — gitoria.worldapi.org: THE MAP. Config, routes and WHO HEARS WHAT; the logic lives in lib/. Hybriel on hl:web.
  2. //
  3. // WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):
  4. // repos: create, list, owner, main-branch setting, push rule lib/repos.hl (slug rules, rows, Markdown view: lib/repos-helpers.hl)
  5. // users, login through ident, display names lib/users.hl
  6. // git on the server (calls, branches, init, temp folder) lib/git.hl (paths, ids, |||PR / |||RL markers: lib/git-helpers.hl)
  7. // the repo homepage (README.md / $docs) lib/homepage.hl (Markdown → blocks: lib/markdown.hl)
  8. // browsing code (/code, /branch, /commit), "Make main" lib/code.hl
  9. // pull requests, the Merge button lib/pulls.hl
  10. // releases lib/releases.hl
  11. // a repo's tickets, connecting tickets, `#12` links both ways lib/tickets.hl (lib/tickets-helpers.hl)
  12. // push and pull over HTTPS (the git protocol's routes) lib/transport.hl (lib/transport-helpers.hl)
  13. // apps connected to a repo (gitoria#41) lib/apps.hl (URL allow-list, shapes: lib/apps-helpers.hl; the table: lib/apps-table.hl)
  14. // signed events to the apps (gitoria#43), the sender timer below lib/events.hl (uuid, signature, retry steps: lib/events-helpers.hl)
  15. // reviews, inline threads, replies, conversation (gitoria#44) lib/reviews.hl (shapes, paging, the diff's lines: lib/reviews-helpers.hl)
  16. // an app's one-hour token, who an API request is (gitoria#42) lib/app-tokens.hl, lib/app-auth.hl
  17. // access tokens / ssh keys lib/tokens.hl / lib/sshkeys.hl
  18. // function routes: API, /login/callback, /settings/connect…, /__git/… lib/api.hl (plumbing: lib/api-helpers.hl)
  19. // shared helpers (env, storage dir, addresses, lists, Vienna time) lib/util.hl
  20. // pages: shell, repo list, readme, code, pulls, releases, tickets, settings, tokens, keys components/*.hl; CSS components/styles.hl
  21. //
  22. // HOW A REPO GETS ITS ADDRESS (ticket #6, gitoria#16): nginx sends `gitoria.worldapi.org` AND every
  23. // `<slug>.gitoria.worldapi.org` to this one app. Every page component that declares `host = null` gets the
  24. // request's host (without port, hybriel#74) on the SERVER, on the first load and on every hl:web navigation:
  25. // the main address shows the repo list + "create" (components/index.hl → list.hl), `<slug>.` shows that repo —
  26. // each repo view is its own page component on its own route (readme, code, branch, commit, pulls, releases,
  27. // tickets), rendered on the server WITH its content: git is read with hl:proc run(), which waits (hybriel#80).
  28. // The session cookie carries `Domain=.<host>` (hl:web `sessionDomain`, hybriel#44) so one
  29. // login holds on every address; the login button always returns through the main address
  30. // (the only origin registered in ident) and then on to the repo the login started from.
  31. import WebFramework from 'hl:web'
  32. import { env } from 'hl:proc'
  33. import Styles from './components/styles.hl'
  34. import { dark, darker } from './shared/tokens.hl'
  35. import { hostOnly, domainFor, scheme } from './lib/util.hl'
  36. import { tagOf, userIdOfSession } from './lib/users.hl'
  37. import { repoBySlug, mayRead } from './lib/repos.hl'
  38. import { notFoundPage, orgRepoPage, notFoundApi, apiRepos, apiRepo, loginCallback, connectStart, connectBack, appConnectStart, appConnectConfirm, appExchange, appToken, appDeliveries, appRedeliver, appPulls, appPull, appReviews, appThreads, appReply, appResolve, appComments, gitKeys, gitAccess, gitPushed } from './lib/api.hl'
  39. import { apiPatterns } from './lib/api-helpers.hl'
  40. import { gitTransport } from './lib/transport.hl'
  41. import Index from './components/index.hl'
  42. import Code from './components/code.hl'
  43. import Branch from './components/branch.hl'
  44. import Commit from './components/commit.hl'
  45. import Pulls from './components/pulls.hl'
  46. import Releases from './components/releases.hl'
  47. import Tickets from './components/tickets.hl'
  48. import Settings from './components/settings.hl'
  49. import LoginFailed from './components/loginfailed.hl'
  50. import NotFound from './components/notfound.hl'
  51. import { exit } from 'hl:proc'
  52. import { every } from 'hl:time'
  53. import { sendDue } from './lib/events.hl'
  54. import { tickSeconds } from './lib/events-helpers.hl'
  55. static siteName = "gitoria"
  56. appTitle = siteName
  57. styles = Styles
  58. // ---- THE INSTALLABLE APP (mission 046), the same way calendar.worldapi.org and tracker do it: hl:web's own web app
  59. // manifest (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service
  60. // worker (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg is the source, the PNGs
  61. // are rendered from it with rsvg-convert, README "PWA"). The theme colour is the header's background (darker), the
  62. // splash background the page's (dark) — both off the tokens. Every repo address is its own origin, so each one gets
  63. // its own manifest and worker (start_url / = that repo's Readme).
  64. appThemeColor = darker.value
  65. appBackgroundColor = dark.value
  66. appIcons = [
  67. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  68. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  69. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  70. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  71. ]
  72. appTouchIcon = '/icons/apple-touch-icon.png'
  73. appFavicon = '/icons/favicon.svg'
  74. // OFFLINE: only the shell and `/` (components/main.hl says "You are offline" while the browser has no network). `/`
  75. // is kept as last seen (the worker is network-first and refreshes its copy on every online visit): the repo list on
  76. // the main address, the Readme on a repo address. Every other page (code, commits, pulls, …) needs the network and
  77. // gets hl:web's "Unavailable offline" page.
  78. offline = [ Index ]
  79. // EVERY REPO VIEW IS ITS OWN PAGE (gitoria#16); `/` is the list on the main address, the Readme on a repo address.
  80. routes = [
  81. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  82. // the installable app (mission 046): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  83. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  84. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  85. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  86. { pattern = "/icons/favicon.svg" file = "./icons/favicon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  87. // the login button's return and the tickets connection write the session: the request and the store go BY REFERENCE (lib/api.hl)
  88. { pattern = "/login/callback" function = (route, req) => { return loginCallback(route, &req, &server.sessions) } }
  89. { pattern = "/login/failed" component = LoginFailed }
  90. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  91. { pattern = "/api/repos" function = apiRepos }
  92. // connecting an app to a repo (gitoria#41, lib/apps.hl): the exchange on the repo's address, and on an organization's address in both spellings of the API base
  93. for (p of apiPatterns('/apps/exchange')) { { pattern = p function = appExchange } }
  94. // a token for an app's key (gitoria#42); every later apps API route is listed the same way (lib/api-helpers.hl apiPatterns)
  95. for (p of apiPatterns('/apps/token')) { { pattern = p function = appToken } }
  96. // the app's delivery log and redelivery (gitoria#43)
  97. for (p of apiPatterns('/deliveries')) { { pattern = p function = appDeliveries } }
  98. for (p of apiPatterns('/deliveries/:id/redeliver')) { { pattern = p function = appRedeliver } }
  99. // the PRs, reviews with inline threads, replies, resolving and the conversation (gitoria#44)
  100. for (p of apiPatterns('/pulls')) { { pattern = p function = appPulls } }
  101. for (p of apiPatterns('/pulls/:n')) { { pattern = p function = appPull } }
  102. for (p of apiPatterns('/pulls/:n/reviews')) { { pattern = p function = appReviews } }
  103. for (p of apiPatterns('/pulls/:n/threads')) { { pattern = p function = appThreads } }
  104. for (p of apiPatterns('/pulls/:n/threads/:id/replies')) { { pattern = p function = appReply } }
  105. for (p of apiPatterns('/pulls/:n/threads/:id/resolve')) { { pattern = p function = appResolve } }
  106. for (p of apiPatterns('/pulls/:n/comments')) { { pattern = p function = appComments } }
  107. { pattern = "/api/repos/:slug" function = apiRepo }
  108. { pattern = "/" component = Index }
  109. { pattern = "/code" component = Code }
  110. { pattern = "/code/*path" component = Code }
  111. { pattern = "/branch/*path" component = Branch }
  112. { pattern = "/commit/*path" component = Commit }
  113. { pattern = "/pulls" component = Pulls }
  114. { pattern = "/releases" component = Releases }
  115. { pattern = "/tickets" component = Tickets }
  116. { pattern = "/settings" component = Settings }
  117. { pattern = "/settings/connect" function = (route, req) => { return connectStart(route, &req, &server.sessions) } }
  118. { pattern = "/settings/apps/connect" function = (route, req) => { return appConnectStart(route, &req, &server.sessions) } }
  119. { pattern = "/settings/apps/confirm" function = (route, req) => { return appConnectConfirm(route, &req, &server.sessions) } }
  120. { pattern = "/settings/connected" function = (route, req) => { return connectBack(route, &req, &server.sessions) } }
  121. // ---- AN ORGANIZATION'S ADDRESS (GO34): <org>.<domain>/<repo>/… are the repo pages, the same components with the first segment as `orepo`
  122. { pattern = "/:orepo" function = (route, req) => { return orgRepoPage(route, req, &server, Index, NotFound) } }
  123. { pattern = "/:orepo/code" component = Code }
  124. { pattern = "/:orepo/code/*path" component = Code }
  125. { pattern = "/:orepo/branch/*path" component = Branch }
  126. { pattern = "/:orepo/commit/*path" component = Commit }
  127. { pattern = "/:orepo/pulls" component = Pulls }
  128. { pattern = "/:orepo/releases" component = Releases }
  129. { pattern = "/:orepo/tickets" component = Tickets }
  130. { pattern = "/:orepo/settings" component = Settings }
  131. { pattern = "/:orepo/settings/connect" function = (route, req) => { return connectStart(route, &req, &server.sessions) } }
  132. { pattern = "/:orepo/settings/apps/connect" function = (route, req) => { return appConnectStart(route, &req, &server.sessions) } }
  133. { pattern = "/:orepo/settings/apps/confirm" function = (route, req) => { return appConnectConfirm(route, &req, &server.sessions) } }
  134. { pattern = "/:orepo/settings/connected" function = (route, req) => { return connectBack(route, &req, &server.sessions) } }
  135. { pattern = "/__git/keys" function = gitKeys }
  136. { pattern = "/__git/access" function = gitAccess }
  137. { pattern = "/__git/pushed" function = gitPushed }
  138. { pattern = "/:repo/info/refs" function = gitTransport }
  139. { pattern = "/:repo/git-upload-pack" function = gitTransport }
  140. { pattern = "/:repo/git-receive-pack" function = gitTransport }
  141. // THE LAST ROUTES: any other path → the shell's 404 page (the API: a JSON 404)
  142. { pattern = "/api/*" function = notFoundApi }
  143. { pattern = "/*" function = (route, req) => { return notFoundPage(route, req, &server, NotFound) } }
  144. ]
  145. // WHO GETS THE PUSH: a new repo reaches every open page (the list follows live)
  146. // `gitoriaSignedIn` / `gitoriaSignedOut` go to the tabs of ONE session: the one whose login carries
  147. // that random tag (session.data.tag, set at login, users.hl tagOf) — every open page of it switches without a reload.
  148. audience = {
  149. // a private repo's creation / tickets reach only the sessions that may see it (GO34)
  150. repoCreated = (row, session) => { r = repoBySlug(row.slug) return r != null && mayRead(userIdOfSession(session), r) }
  151. ticketOpened = (slug, row, session) => { r = repoBySlug(slug) return r != null && mayRead(userIdOfSession(session), r) }
  152. gitoriaSignedIn = (tag, info, session) => { return tag != null && tagOf(session) == tag }
  153. gitoriaSignedOut = (tag, session) => { return tag != null && tagOf(session) == tag }
  154. }
  155. sessionDir = env('GITORIA_SESSIONS') != null ? env('GITORIA_SESSIONS') : null
  156. port = env('GITORIA_PORT') != null ? toNumber(env('GITORIA_PORT')) : 8360
  157. // HL_HOST = the interface hl:web binds (hybriel #24, fixed upstream): 127.0.0.1 on Byrodin behind nginx;
  158. // unset = 0.0.0.0 (dev on Loreana). GITORIA_WATCH=0 = no dev watcher. The session cookie is `gitoriasid` (hybriel #10).
  159. watching = env('GITORIA_WATCH') != '0'
  160. sessionCookie = 'gitoriasid'
  161. // the cookie's Domain (hybriel#44): every <slug>.<host> shares the login (util.hl domainFor; '' = host-only → null)
  162. sessionDomain = domainFor(hostOnly) != '' ? domainFor(hostOnly) : null
  163. // SECURITY (mission SG): the session cookie is `Secure` when the public address is https (the proxy speaks http to us, so the app says so);
  164. // no face of ours takes a file, so /__hl/upload (open to anyone, held in memory) refuses every file with a size (uploadMax = 0)
  165. sessionSecure = scheme == 'https'
  166. uploadMax = 0
  167. server = new WebFramework(routes = routes, styles = styles, minify = true, port = port, watchMode = watching, sessionCookie = sessionCookie, sessionDomain = sessionDomain, sessionSecure = sessionSecure, uploadMax = uploadMax, sessionMaxAge = 3122064000)
  168. // THE SENDER (gitoria#43): every few seconds the due delivery rows are POSTed to the apps (lib/events.hl sendDue); raising an event only writes a row
  169. sender = every(tickSeconds())
  170. on sender.tick() { sendDue() }
  171. on Error(e) {
  172. if (e.phase == 'startup') { console.log('gitoria: startup error: ' + e.message) exit(1) }
  173. console.log('error absorbed: ' + e.message)
  174. }

Branches

Latest commits

  • ea587d90gitoria#44: reviews with inline threads, replies, resolve and the PR conversation for apps (lib/reviews.hl, tests/reviews.mjs)mre
  • 49533a50gitoria#43: signed events to connected apps (merge w43-events)mre
  • 1a1e87d5gitoria#43: the sender never writes the apps row; Settings shows the newest deliverymre
  • cd442066gitoria#43: app-auth unit test reads the apps table from its new filemre
  • 5dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre
  • 8c8805f3merge main (gitoria#42), delivery log and redelivery routes, sweep fixmre
  • 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
  • afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
  • 15e01e94gitoria#43: tests/events.mjs and its probemre
  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • b5d696fegitoria#42: app tokens (gat_, one hour), appOfRequest, app token as the git read passwordmre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
  • 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre
  • fdb9ed28gitoria#41: repo owners can connect an app (merge w41-apps-connect)mre
  • 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
  • 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
  • b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
  • 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
  • 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
  • c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre