gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit1997e77d1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre1997e77d/project.hl

11.5 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)
  14. // access tokens / ssh keys lib/tokens.hl / lib/sshkeys.hl
  15. // function routes: API, /login/callback, /settings/connect…, /__git/… lib/api.hl (plumbing: lib/api-helpers.hl)
  16. // shared helpers (env, storage dir, addresses, lists, Vienna time) lib/util.hl
  17. // pages: shell, repo list, readme, code, pulls, releases, tickets, settings, tokens, keys components/*.hl; CSS components/styles.hl
  18. //
  19. // HOW A REPO GETS ITS ADDRESS (ticket #6, gitoria#16): nginx sends `gitoria.worldapi.org` AND every
  20. // `<slug>.gitoria.worldapi.org` to this one app. Every page component that declares `host = null` gets the
  21. // request's host (without port, hybriel#74) on the SERVER, on the first load and on every hl:web navigation:
  22. // the main address shows the repo list + "create" (components/index.hl → list.hl), `<slug>.` shows that repo —
  23. // each repo view is its own page component on its own route (readme, code, branch, commit, pulls, releases,
  24. // tickets), rendered on the server WITH its content: git is read with hl:proc run(), which waits (hybriel#80).
  25. // The session cookie carries `Domain=.<host>` (hl:web `sessionDomain`, hybriel#44) so one
  26. // login holds on every address; the login button always returns through the main address
  27. // (the only origin registered in ident) and then on to the repo the login started from.
  28. import WebFramework from 'hl:web'
  29. import { env } from 'hl:proc'
  30. import Styles from './components/styles.hl'
  31. import { dark, darker } from './shared/tokens.hl'
  32. import { hostOnly, domainFor, scheme } from './lib/util.hl'
  33. import { tagOf, userIdOfSession } from './lib/users.hl'
  34. import { repoBySlug, mayRead } from './lib/repos.hl'
  35. import { notFoundPage, orgRepoPage, notFoundApi, apiRepos, apiRepo, loginCallback, connectStart, connectBack, appConnectStart, appConnectConfirm, appExchange, gitKeys, gitAccess, gitPushed } from './lib/api.hl'
  36. import { gitTransport } from './lib/transport.hl'
  37. import Index from './components/index.hl'
  38. import Code from './components/code.hl'
  39. import Branch from './components/branch.hl'
  40. import Commit from './components/commit.hl'
  41. import Pulls from './components/pulls.hl'
  42. import Releases from './components/releases.hl'
  43. import Tickets from './components/tickets.hl'
  44. import Settings from './components/settings.hl'
  45. import LoginFailed from './components/loginfailed.hl'
  46. import NotFound from './components/notfound.hl'
  47. import { exit } from 'hl:proc'
  48. static siteName = "gitoria"
  49. appTitle = siteName
  50. styles = Styles
  51. // ---- THE INSTALLABLE APP (mission 046), the same way calendar.worldapi.org and tracker do it: hl:web's own web app
  52. // manifest (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service
  53. // worker (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg is the source, the PNGs
  54. // are rendered from it with rsvg-convert, README "PWA"). The theme colour is the header's background (darker), the
  55. // splash background the page's (dark) — both off the tokens. Every repo address is its own origin, so each one gets
  56. // its own manifest and worker (start_url / = that repo's Readme).
  57. appThemeColor = darker.value
  58. appBackgroundColor = dark.value
  59. appIcons = [
  60. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  61. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  62. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  63. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  64. ]
  65. appTouchIcon = '/icons/apple-touch-icon.png'
  66. appFavicon = '/icons/favicon.svg'
  67. // OFFLINE: only the shell and `/` (components/main.hl says "You are offline" while the browser has no network). `/`
  68. // is kept as last seen (the worker is network-first and refreshes its copy on every online visit): the repo list on
  69. // the main address, the Readme on a repo address. Every other page (code, commits, pulls, …) needs the network and
  70. // gets hl:web's "Unavailable offline" page.
  71. offline = [ Index ]
  72. // EVERY REPO VIEW IS ITS OWN PAGE (gitoria#16); `/` is the list on the main address, the Readme on a repo address.
  73. routes = [
  74. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }
  75. // the installable app (mission 046): the icons (manifest and service worker are hl:web's own, from appIcons / offline)
  76. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }
  77. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }
  78. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }
  79. { pattern = "/icons/favicon.svg" file = "./icons/favicon.svg" headers = { 'Cache-Control' = 'no-cache' } }
  80. // the login button's return and the tickets connection write the session: the request and the store go BY REFERENCE (lib/api.hl)
  81. { pattern = "/login/callback" function = (route, req) => { return loginCallback(route, &req, &server.sessions) } }
  82. { pattern = "/login/failed" component = LoginFailed }
  83. { pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }
  84. { pattern = "/api/repos" function = apiRepos }
  85. // 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
  86. { pattern = "/api/apps/exchange" function = appExchange }
  87. { pattern = "/api/:orepo/apps/exchange" function = appExchange }
  88. { pattern = "/:orepo/api/apps/exchange" function = appExchange }
  89. { pattern = "/api/repos/:slug" function = apiRepo }
  90. { pattern = "/" component = Index }
  91. { pattern = "/code" component = Code }
  92. { pattern = "/code/*path" component = Code }
  93. { pattern = "/branch/*path" component = Branch }
  94. { pattern = "/commit/*path" component = Commit }
  95. { pattern = "/pulls" component = Pulls }
  96. { pattern = "/releases" component = Releases }
  97. { pattern = "/tickets" component = Tickets }
  98. { pattern = "/settings" component = Settings }
  99. { pattern = "/settings/connect" function = (route, req) => { return connectStart(route, &req, &server.sessions) } }
  100. { pattern = "/settings/apps/connect" function = (route, req) => { return appConnectStart(route, &req, &server.sessions) } }
  101. { pattern = "/settings/apps/confirm" function = (route, req) => { return appConnectConfirm(route, &req, &server.sessions) } }
  102. { pattern = "/settings/connected" function = (route, req) => { return connectBack(route, &req, &server.sessions) } }
  103. // ---- AN ORGANIZATION'S ADDRESS (GO34): <org>.<domain>/<repo>/… are the repo pages, the same components with the first segment as `orepo`
  104. { pattern = "/:orepo" function = (route, req) => { return orgRepoPage(route, req, &server, Index, NotFound) } }
  105. { pattern = "/:orepo/code" component = Code }
  106. { pattern = "/:orepo/code/*path" component = Code }
  107. { pattern = "/:orepo/branch/*path" component = Branch }
  108. { pattern = "/:orepo/commit/*path" component = Commit }
  109. { pattern = "/:orepo/pulls" component = Pulls }
  110. { pattern = "/:orepo/releases" component = Releases }
  111. { pattern = "/:orepo/tickets" component = Tickets }
  112. { pattern = "/:orepo/settings" component = Settings }
  113. { pattern = "/:orepo/settings/connect" function = (route, req) => { return connectStart(route, &req, &server.sessions) } }
  114. { pattern = "/:orepo/settings/apps/connect" function = (route, req) => { return appConnectStart(route, &req, &server.sessions) } }
  115. { pattern = "/:orepo/settings/apps/confirm" function = (route, req) => { return appConnectConfirm(route, &req, &server.sessions) } }
  116. { pattern = "/:orepo/settings/connected" function = (route, req) => { return connectBack(route, &req, &server.sessions) } }
  117. { pattern = "/__git/keys" function = gitKeys }
  118. { pattern = "/__git/access" function = gitAccess }
  119. { pattern = "/__git/pushed" function = gitPushed }
  120. { pattern = "/:repo/info/refs" function = gitTransport }
  121. { pattern = "/:repo/git-upload-pack" function = gitTransport }
  122. { pattern = "/:repo/git-receive-pack" function = gitTransport }
  123. // THE LAST ROUTES: any other path → the shell's 404 page (the API: a JSON 404)
  124. { pattern = "/api/*" function = notFoundApi }
  125. { pattern = "/*" function = (route, req) => { return notFoundPage(route, req, &server, NotFound) } }
  126. ]
  127. // WHO GETS THE PUSH: a new repo reaches every open page (the list follows live)
  128. // `gitoriaSignedIn` / `gitoriaSignedOut` go to the tabs of ONE session: the one whose login carries
  129. // that random tag (session.data.tag, set at login, users.hl tagOf) — every open page of it switches without a reload.
  130. audience = {
  131. // a private repo's creation / tickets reach only the sessions that may see it (GO34)
  132. repoCreated = (row, session) => { r = repoBySlug(row.slug) return r != null && mayRead(userIdOfSession(session), r) }
  133. ticketOpened = (slug, row, session) => { r = repoBySlug(slug) return r != null && mayRead(userIdOfSession(session), r) }
  134. gitoriaSignedIn = (tag, info, session) => { return tag != null && tagOf(session) == tag }
  135. gitoriaSignedOut = (tag, session) => { return tag != null && tagOf(session) == tag }
  136. }
  137. sessionDir = env('GITORIA_SESSIONS') != null ? env('GITORIA_SESSIONS') : null
  138. port = env('GITORIA_PORT') != null ? toNumber(env('GITORIA_PORT')) : 8360
  139. // HL_HOST = the interface hl:web binds (hybriel #24, fixed upstream): 127.0.0.1 on Byrodin behind nginx;
  140. // unset = 0.0.0.0 (dev on Loreana). GITORIA_WATCH=0 = no dev watcher. The session cookie is `gitoriasid` (hybriel #10).
  141. watching = env('GITORIA_WATCH') != '0'
  142. sessionCookie = 'gitoriasid'
  143. // the cookie's Domain (hybriel#44): every <slug>.<host> shares the login (util.hl domainFor; '' = host-only → null)
  144. sessionDomain = domainFor(hostOnly) != '' ? domainFor(hostOnly) : null
  145. // 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);
  146. // no face of ours takes a file, so /__hl/upload (open to anyone, held in memory) refuses every file with a size (uploadMax = 0)
  147. sessionSecure = scheme == 'https'
  148. uploadMax = 0
  149. server = new WebFramework(routes = routes, styles = styles, minify = true, port = port, watchMode = watching, sessionCookie = sessionCookie, sessionDomain = sessionDomain, sessionSecure = sessionSecure, uploadMax = uploadMax, sessionMaxAge = 3122064000)
  150. on Error(e) {
  151. if (e.phase == 'startup') { console.log('gitoria: startup error: ' + e.message) exit(1) }
  152. console.log('error absorbed: ' + e.message)
  153. }

Branches

Latest commits

  • 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
  • c50d17efKeep function-route not-found style in shared stylesheetmre
  • e42d78d3Preserve ticket state CSS and document function-route style gapmre
  • c6b7154eWIP gitoria#26: move styles into nested component blocksmre
  • 77a2c31cgitoria#31: plain declarations instead of needless let in lib/ and tools/ (103 let removed, 137 kept because reassigned); no other changemre
  • 4b98ab62gitoria: an ident access key (idt_) works as the git password; read key clones only, bad key 401, ident down 503 (ident#27); gate tests/ident-access-gitoria.mjs in deploy.shmre
  • 1185f686gitoria#36: a failed return from tickets shows a note on the settings page and leaves one log line per outcome; no code is exchangedmre
  • 5d2c385agitoria: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 71+5 failing → 76 passed; deploy.sh runs tests/private.mjs toomre
  • 241ef3f9deploy.sh: rebuild the sshd image before up -d (GO34c)mre
  • 821cdbb1gitoria#34b: styles, create-repo tool, docs, push/ssh gates sign in through the selector, shots scriptmre
  • a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
  • 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre