gitoria
All repositories: gitoria
7.7 KB
// repos.hl — THE REPOS (ticket gitoria#6). A repo is a SLUG that is unique in the whole system;// it lives at <slug>.<domain> (users.hl repoOrigin). One hl:mpackdb table, storage/mpackdb/repos.db:// pk @id index !slug, owner { slug, description, owner (users @id), created, branch (the main branch; '' / absent = default),// tktKey, tktProject, tktTitle, tktApi (the connected tickets project, gitoria#18; the key is a secret and never leaves the server) }// The unique index makes the slug unique for good (a second put of a taken slug fails); the// check below answers it in words first. A new repo also gets an empty bare git repository (git.hl); pushing arrives with gitoria#7.import { MPackDB } from 'hl:mpackdb'import { now } from 'hl:time'import { storageDir, userOfSession, countOfList, firstOf, plainError, userRecord, nameOfUser, repoOrigin, publicUrl } from './users.hl'import { localStamp } from './localtime.hl'import { initRepo } from './git.hl'static reposTable = new MPackDB(file = storageDir + '/repos.db', primaryKey = '@id', indexes = ['!slug', 'owner'])// names that are addresses of the system itself, or that would read as one (never a repo)// a newline (the language has no \n escape in a string: a literal line break, as in tickets mdview.hl)static NL = ""// only technical host names; the creator's own apps (ident, tickets, hybriel, …) are repos here too (creator 2026-09-25)static reserved = ['www' 'api' 'git' 'ssh' 'http' 'https' 'ftp' 'mail' 'smtp' 'imap' 'admin' 'root' 'cdn' 'static' 'assets' 'login' 'logout' 'new' 'repos']static isLower = (c) => { return c >= 97 && c <= 122 }static isDigit = (c) => { return c >= 48 && c <= 57 }// the slug's rules → null (fine) or the complaint. A DNS label: 2–40 characters, a–z 0–9 and// single hyphens, starting and ending with a letter or digit ("--" is refused: xn-- is punycode)static slugError = (slug) => {if (slug == null || hlTypeName(slug) != 'String') { return 'the address must be text' }if (slug.length < 2 || slug.length > 40) { return 'the address must have 2–40 characters' }let i = 0while (i < slug.length) {let c = slug.charCodeAt(i)let ok = isLower(c) || isDigit(c) || (c == 45 && i > 0 && i < slug.length - 1)if (!ok) { return 'the address may only have lowercase letters a–z, digits and hyphens, and starts and ends with a letter or digit' }i = i + 1}if (slug.includes('--')) { return 'the address must not have two hyphens in a row' }if (reserved.includes(slug)) { return "'" + slug + "' is reserved for the system" }return null}static repoBySlug = (slug) => {if (slug == null || hlTypeName(slug) != 'String' || slug == '') { return null }return firstOf(reposTable.find('slug', slug))}static rowOf = (r) => {return { id = r.id slug = r.slug description = r.description described = r.description != '' owner = nameOfUser(r.owner) branch = r.branch != null ? r.branch : '' ticketsOn = r.tktKey != null && r.tktKey != '' ticketsOff = r.tktKey == null || r.tktKey == '' ticketsProject = r.tktProject != null ? r.tktProject : '' ticketsTitle = r.tktTitle != null ? r.tktTitle : '' created = localStamp(r.created) createdMs = r.created address = repoOrigin(r.slug) + '/' }}// every repo, newest first (no sort(): hybriel #1)static repoRows = () => {let out = []let all = reposTable.find(null, null)if (countOfList(all) == 0) { return out }for (r of all) { out.push(rowOf(r)) }let i = 1while (i < out.length) {let cur = out[i]let j = i - 1while (j >= 0 && out[j].createdMs < cur.createdMs) {out[j + 1] = out[j]j = j - 1}out[j + 1] = curi = i + 1}return out}static repoRow = (slug) => {let r = repoBySlug(slug)return r == null ? null : rowOf(r)}// the repo a page stands on (users.hl slugOfHost): its row, or null for the main address / an unknown addressstatic repoAt = (slug) => {if (slug == null || slug == '' || slugError(slug) != null) { return null }return repoRow(slug)}// a tab title: 'Code · alpha · gitoria', 'alpha · gitoria', 'gitoria'static pageTitle = (site, slug, what) => {let t = slug != null && slug != '' ? slug + ' · ' + site : sitereturn what != null && what != '' ? what + ' · ' + t : t}// a new repo for a user: { repo } (the row) or { error, field }static createRepo = (userId, slug, description) => {let u = userRecord(userId)if (u == null) { return { error = 'log in with ident (top right) to create a repository' field = '' } }if (u.name == '') { return { error = 'choose a display name first (top of the page)' field = '' } }let s = slug == null ? '' : ('' + slug).trim()let bad = slugError(s)if (bad != null) { return { error = bad field = 'slug' } }let d = description == null ? '' : ('' + description).trim()let dbad = plainError(d, 200, 'the description')if (dbad != null) { return { error = dbad field = 'description' } }if (repoBySlug(s) != null) { return { error = "the address '" + s + "' is taken — every repository address is unique in the whole system" field = 'slug' } }let id = reposTable.put({ slug = s description = d owner = u.id created = now() })if (id == null) { return { error = 'could not store the repository (is the address taken?): ' + reposTable.lastError() field = 'slug' } }initRepo(s)return { repo = rowOf(reposTable.fetch(id)) }}// does this (real) session's user own the repo?static ownsRepo = (slug, session) => {let u = userOfSession(session)let row = repoBySlug(slug)return u != null && row != null && row.owner == u.id}// a repo's whole record with some fields changed (update() replaces the record: every field must be given again)static withChange = (r, change) => {let o = { id = r.id slug = r.slug description = r.description owner = r.owner created = r.created branch = r.branch != null ? r.branch : '' tktKey = r.tktKey != null ? r.tktKey : '' tktProject = r.tktProject != null ? r.tktProject : '' tktTitle = r.tktTitle != null ? r.tktTitle : '' tktApi = r.tktApi != null ? r.tktApi : '' }for (k of change.keys()) { o[k] = change[k] }return o}// the connection to a tickets project (gitoria#18); key '' = disconnected. The caller checked the owner.static setTicketsConnection = (slug, key, project, title, api) => {let r = repoBySlug(slug)if (r == null) { return { error = 'no such repository' } }reposTable.update(r.id, withChange(r, { tktKey = key tktProject = project tktTitle = title tktApi = api }))let after = reposTable.fetch(r.id)if (after == null || after.tktKey != key) { return { error = 'could not store the connection: ' + reposTable.lastError() } }return { repo = rowOf(after) }}// the owner's setting of the main branch (/code, the homepage). The caller checked the branch exists.static setMainBranch = (userId, slug, name) => {let r = repoBySlug(slug)if (r == null) { return { error = 'no such repository' } }if (userId == null || r.owner != userId) { return { error = 'only the owner can change the main branch' } }reposTable.update(r.id, withChange(r, { branch = name }))let after = reposTable.fetch(r.id)if (after == null || after.branch != name) { return { error = 'could not store the setting: ' + reposTable.lastError() } }return { repo = rowOf(after) }}// ---- the Markdown read view (Accept: text/markdown) — for LLM readers ---------------------------static repoDocument = (row) => {let out = '# ' + row.slug + NL + NLif (row.described) { out = out + row.description + NL + NL }out = out + '- address: ' + row.address + NL + '- owner: ' + row.owner + NL + '- created: ' + row.created + NLreturn out}static listDocument = (rows) => {let out = '# Repositories (' + rows.length + ')' + NL + NLif (rows.length == 0) { out = out + 'No repository yet.' + NL }for (r of rows) { out = out + '- [' + r.slug + '](' + r.address + ')' + (r.described ? ' — ' + r.description : '') + NL }return out}
Branches
- mainmain branch
Latest commits
- 09ce4f3fgitoria: mission 069 re-vendor hybriel 8efba065 stopped (big SSR pages grow + slow down); lambda audit clean; old vendor keptmre
- 3dc43108antcolony#40: mission references point to the moved missionsmre
- 8d9450fdantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
- 205d5fe4gitoria: Hybriel master ff51cf46; ssh keys/tokens no double rows (session sync); gates follow #20mre
- 9b27cb26gitoria#21: installable app (manifest, service worker, offline start page), own iconmre
- 68dcb603deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- e2deed6dgitoria#20: "Add code" only on the Code page of an empty repository, no collapsiblemre
- 8bb97ffddeploy.sh: never send .git or .gitignore to Byrodinmre
- fd981932State of 2026-09-27; bin/ no longer tracked (Hybriel commit is in README)mre
- 4a2d7125initial commitmre