gitoria
All repositories: gitoria
14.6 KB
// project.hl — gitoria.worldapi.org: THE MAP. Config, routes and WHO HEARS WHAT; the logic lives in lib/. Hybriel on hl:web.//// WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):// repos: create, list, owner, main-branch setting, push rule lib/repos.hl (slug rules, rows, Markdown view: lib/repos-helpers.hl)// users, login through ident, display names lib/users.hl// git on the server (calls, branches, init, temp folder) lib/git.hl (paths, ids, |||PR / |||RL markers: lib/git-helpers.hl)// the repo homepage (README.md / $docs) lib/homepage.hl (Markdown → blocks: lib/markdown.hl)// browsing code (/code, /branch, /commit), "Make main" lib/code.hl// pull requests, the Merge button lib/pulls.hl// a pull request's page: reviews, threads, comments, Review again (gitoria#45) lib/prpage.hl (the tables: lib/reviews.hl)// releases lib/releases.hl// a repo's tickets, connecting tickets, `#12` links both ways lib/tickets.hl (lib/tickets-helpers.hl)// push and pull over HTTPS (the git protocol's routes) lib/transport.hl (lib/transport-helpers.hl)// apps connected to a repo (gitoria#41) lib/apps.hl (URL allow-list, shapes: lib/apps-helpers.hl; the table: lib/apps-table.hl)// statuses an app sets on a commit, required before merge (gitoria#46) lib/statuses.hl// signed events to the apps (gitoria#43), the sender timer below lib/events.hl (uuid, signature, retry steps: lib/events-helpers.hl)// reviews, inline threads, replies, conversation (gitoria#44) lib/reviews.hl (shapes, paging, the diff's lines: lib/reviews-helpers.hl)// an app's one-hour token, who an API request is (gitoria#42) lib/app-tokens.hl, lib/app-auth.hl// access tokens / ssh keys lib/tokens.hl / lib/sshkeys.hl// function routes: API, /login/callback, /settings/connect…, /__git/… lib/api.hl (plumbing: lib/api-helpers.hl)// shared helpers (env, storage dir, addresses, lists, Vienna time) lib/util.hl// pages: shell, repo list, readme, code, pulls, releases, tickets, settings, tokens, keys components/*.hl; CSS components/styles.hl//// HOW A REPO GETS ITS ADDRESS (ticket #6, gitoria#16): nginx sends `gitoria.worldapi.org` AND every// `<slug>.gitoria.worldapi.org` to this one app. Every page component that declares `host = null` gets the// request's host (without port, hybriel#74) on the SERVER, on the first load and on every hl:web navigation:// the main address shows the repo list + "create" (components/index.hl → list.hl), `<slug>.` shows that repo —// each repo view is its own page component on its own route (readme, code, branch, commit, pulls, releases,// tickets), rendered on the server WITH its content: git is read with hl:proc run(), which waits (hybriel#80).// The session cookie carries `Domain=.<host>` (hl:web `sessionDomain`, hybriel#44) so one// login holds on every address; the login button always returns through the main address// (the only origin registered in ident) and then on to the repo the login started from.import WebFramework from 'hl:web'import { env } from 'hl:proc'import Styles from './components/styles.hl'import { dark, darker } from './shared/tokens.hl'import { hostOnly, domainFor, scheme } from './lib/util.hl'import { tagOf, userIdOfSession } from './lib/users.hl'import { repoBySlug, mayRead } from './lib/repos.hl'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'import { apiPatterns } from './lib/api-helpers.hl'import { gitTransport } from './lib/transport.hl'import Index from './components/index.hl'import Code from './components/code.hl'import Branch from './components/branch.hl'import Commit from './components/commit.hl'import Pulls from './components/pulls.hl'import PullPage from './components/pull.hl'import Releases from './components/releases.hl'import Tickets from './components/tickets.hl'import Settings from './components/settings.hl'import LoginFailed from './components/loginfailed.hl'import NotFound from './components/notfound.hl'import { exit } from 'hl:proc'import { every } from 'hl:time'import { sendDue } from './lib/events.hl'import { tickSeconds } from './lib/events-helpers.hl'static siteName = "gitoria"appTitle = siteNamestyles = Styles// ---- THE INSTALLABLE APP (mission 046), the same way calendar.worldapi.org and tracker do it: hl:web's own web app// manifest (/__hl/manifest.webmanifest, linked from every head with the apple-touch-icon and theme-color) and service// worker (/__hl/sw.js) from these settings — no JavaScript of ours. Icons in icons/ (icon.svg is the source, the PNGs// are rendered from it with rsvg-convert, README "PWA"). The theme colour is the header's background (darker), the// splash background the page's (dark) — both off the tokens. Every repo address is its own origin, so each one gets// its own manifest and worker (start_url / = that repo's Readme).appThemeColor = darker.valueappBackgroundColor = dark.valueappIcons = [{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }]appTouchIcon = '/icons/apple-touch-icon.png'appFavicon = '/icons/favicon.svg'// OFFLINE: only the shell and `/` (components/main.hl says "You are offline" while the browser has no network). `/`// is kept as last seen (the worker is network-first and refreshes its copy on every online visit): the repo list on// the main address, the Readme on a repo address. Every other page (code, commits, pulls, …) needs the network and// gets hl:web's "Unavailable offline" page.offline = [ Index ]// EVERY REPO VIEW IS ITS OWN PAGE (gitoria#16); `/` is the list on the main address, the Readme on a repo address.routes = [{ pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' } }// the installable app (mission 046): the icons (manifest and service worker are hl:web's own, from appIcons / offline){ pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/icons/favicon.svg" file = "./icons/favicon.svg" headers = { 'Cache-Control' = 'no-cache' } }// the login button's return and the tickets connection write the session: the request and the store go BY REFERENCE (lib/api.hl){ pattern = "/login/callback" function = (route, req) => { return loginCallback(route, &req, &server.sessions) } }{ pattern = "/login/failed" component = LoginFailed }{ pattern = "/login.js" file = "./login.js" headers = { 'Cache-Control' = 'no-cache' } }{ pattern = "/api/repos" function = apiRepos }// 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 basefor (p of apiPatterns('/apps/exchange')) { { pattern = p function = appExchange } }// a token for an app's key (gitoria#42); every later apps API route is listed the same way (lib/api-helpers.hl apiPatterns)for (p of apiPatterns('/apps/token')) { { pattern = p function = appToken } }// the app's delivery log and redelivery (gitoria#43)for (p of apiPatterns('/deliveries')) { { pattern = p function = appDeliveries } }for (p of apiPatterns('/deliveries/:id/redeliver')) { { pattern = p function = appRedeliver } }// the PRs, reviews with inline threads, replies, resolving and the conversation (gitoria#44)for (p of apiPatterns('/pulls')) { { pattern = p function = appPulls } }for (p of apiPatterns('/pulls/:n')) { { pattern = p function = appPull } }for (p of apiPatterns('/pulls/:n/merge')) { { pattern = p function = apiMergePull } }for (p of apiPatterns('/pulls/:n/reviews')) { { pattern = p function = appReviews } }for (p of apiPatterns('/pulls/:n/threads')) { { pattern = p function = appThreads } }for (p of apiPatterns('/pulls/:n/threads/:id/replies')) { { pattern = p function = appReply } }for (p of apiPatterns('/pulls/:n/threads/:id/resolve')) { { pattern = p function = appResolve } }for (p of apiPatterns('/pulls/:n/comments')) { { pattern = p function = appComments } }// an app sets the status of a commit (gitoria#46)for (p of apiPatterns('/statuses/:sha')) { { pattern = p function = appStatus } }{ pattern = "/api/repos/:slug" function = apiRepo }// 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// 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){ pattern = "/api/*" function = notFoundApi }{ pattern = "/:orepo/api/*" function = notFoundApi }{ pattern = "/" component = Index }{ pattern = "/code" component = Code }{ pattern = "/code/*path" component = Code }{ pattern = "/branch/*path" component = Branch }{ pattern = "/commit/*path" component = Commit }{ pattern = "/pulls" component = Pulls }{ pattern = "/pulls/:n" function = (route, req) => { return pullPage(route, req, &server, PullPage, NotFound) } }{ pattern = "/releases" component = Releases }{ pattern = "/tickets" component = Tickets }{ pattern = "/settings" component = Settings }{ pattern = "/settings/connect" function = (route, req) => { return connectStart(route, &req, &server.sessions) } }{ pattern = "/settings/apps/connect" function = (route, req) => { return appConnectStart(route, &req, &server.sessions) } }{ pattern = "/settings/apps/confirm" function = (route, req) => { return appConnectConfirm(route, &req, &server.sessions) } }{ pattern = "/settings/connected" function = (route, req) => { return connectBack(route, &req, &server.sessions) } }// ---- AN ORGANIZATION'S ADDRESS (GO34): <org>.<domain>/<repo>/… are the repo pages, the same components with the first segment as `orepo`{ pattern = "/:orepo" function = (route, req) => { return orgRepoPage(route, req, &server, Index, NotFound) } }{ pattern = "/:orepo/code" component = Code }{ pattern = "/:orepo/code/*path" component = Code }{ pattern = "/:orepo/branch/*path" component = Branch }{ pattern = "/:orepo/commit/*path" component = Commit }{ pattern = "/:orepo/pulls" component = Pulls }{ pattern = "/:orepo/pulls/:n" function = (route, req) => { return pullPage(route, req, &server, PullPage, NotFound) } }{ pattern = "/:orepo/releases" component = Releases }{ pattern = "/:orepo/tickets" component = Tickets }{ pattern = "/:orepo/settings" component = Settings }{ pattern = "/:orepo/settings/connect" function = (route, req) => { return connectStart(route, &req, &server.sessions) } }{ pattern = "/:orepo/settings/apps/connect" function = (route, req) => { return appConnectStart(route, &req, &server.sessions) } }{ pattern = "/:orepo/settings/apps/confirm" function = (route, req) => { return appConnectConfirm(route, &req, &server.sessions) } }{ pattern = "/:orepo/settings/connected" function = (route, req) => { return connectBack(route, &req, &server.sessions) } }{ pattern = "/__git/keys" function = gitKeys }{ pattern = "/__git/access" function = gitAccess }{ pattern = "/__git/pushed" function = gitPushed }{ pattern = "/:repo/info/refs" function = gitTransport }{ pattern = "/:repo/git-upload-pack" function = gitTransport }{ pattern = "/:repo/git-receive-pack" function = gitTransport }// THE LAST ROUTE: any other path → the shell's 404 page (the API's JSON 404 is above, before the page routes){ pattern = "/*" function = (route, req) => { return notFoundPage(route, req, &server, NotFound) } }]// WHO GETS THE PUSH: a new repo reaches every open page (the list follows live)// `gitoriaSignedIn` / `gitoriaSignedOut` go to the tabs of ONE session: the one whose login carries// that random tag (session.data.tag, set at login, users.hl tagOf) — every open page of it switches without a reload.audience = {// a private repo's creation / tickets reach only the sessions that may see it (GO34)repoCreated = (row, session) => { r = repoBySlug(row.slug) return r != null && mayRead(userIdOfSession(session), r) }ticketOpened = (slug, row, session) => { r = repoBySlug(slug) return r != null && mayRead(userIdOfSession(session), r) }gitoriaSignedIn = (tag, info, session) => { return tag != null && tagOf(session) == tag }gitoriaSignedOut = (tag, session) => { return tag != null && tagOf(session) == tag }}sessionDir = env('GITORIA_SESSIONS') != null ? env('GITORIA_SESSIONS') : nullport = env('GITORIA_PORT') != null ? toNumber(env('GITORIA_PORT')) : 8360// HL_HOST = the interface hl:web binds (hybriel #24, fixed upstream): 127.0.0.1 on Byrodin behind nginx;// unset = 0.0.0.0 (dev on Loreana). GITORIA_WATCH=0 = no dev watcher. The session cookie is `gitoriasid` (hybriel #10).watching = env('GITORIA_WATCH') != '0'sessionCookie = 'gitoriasid'// the cookie's Domain (hybriel#44): every <slug>.<host> shares the login (util.hl domainFor; '' = host-only → null)sessionDomain = domainFor(hostOnly) != '' ? domainFor(hostOnly) : null// 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);// no face of ours takes a file, so /__hl/upload (open to anyone, held in memory) refuses every file with a size (uploadMax = 0)sessionSecure = scheme == 'https'uploadMax = 0server = new WebFramework(routes = routes, styles = styles, minify = true, port = port, watchMode = watching, sessionCookie = sessionCookie, sessionDomain = sessionDomain, sessionSecure = sessionSecure, uploadMax = uploadMax, sessionMaxAge = 3122064000)// 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 rowsender = every(tickSeconds())on sender.tick() { sendDue() }on Error(e) {if (e.phase == 'startup') { console.log('gitoria: startup error: ' + e.message) exit(1) }console.log('error absorbed: ' + e.message)}
Branches
Latest commits
- 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
- 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
- 26117255|||PR apps API: review comments on files with spaces in their namemre
- b8796cecMerge branch 'f1-broken-json' into mainGitoria
- 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
- f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
- 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
- 16a3530fMerge branch 'heap-revert' into mainGitoria
- 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
- 13f0c342Merge branch 'hl25-records' into mainGitoria
- a002ecb7|||PR records: HL25 report, heap helper, logmre
- 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre
- 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
- c4f6d9e3reports: G25c growth huntmre