gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite7af3ecee7af3eceMerge branch 'w52b-approval-followup' into mainGitoriae7af3ece/project.hl

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

Branches

Latest commits

  • 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
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre
  • 55c84779Merge branch 'gp-gate-ports' into mainGitoria
  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria