gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit097c52ba097c52baStyle the login error through its View idmre097c52ba/lib/repos-helpers.hl

5.2 KB

  1. // lib/repos-helpers.hl — what lib/repos.hl looks up: the slug's rules, the row a page shows, a whole record with some
  2. // fields changed, the tab title, the Markdown read view of the API. Statics only, no table access.
  3. import { NL, isDigit, localStamp, repoOrigin } from './util.hl'
  4. import { nameOfUser } from './users.hl'
  5. // names that are addresses of the system itself, or that would read as one (never a repo)
  6. // only technical host names; the creator's own apps (ident, tickets, hybriel, …) are repos here too (creator 2026-09-25)
  7. static reserved = ['www' 'api' 'git' 'ssh' 'http' 'https' 'ftp' 'mail' 'smtp' 'imap' 'admin' 'root' 'cdn' 'static' 'assets' 'login' 'logout' 'new' 'repos']
  8. static isLower = (c) => { return c >= 97 && c <= 122 }
  9. // the slug's rules → null (fine) or the complaint. A DNS label: 2–40 characters, a–z 0–9 and
  10. // single hyphens, starting and ending with a letter or digit ("--" is refused: xn-- is punycode)
  11. static slugError = (slug) => {
  12. if (slug == null || hlTypeName(slug) != 'String') { return 'the address must be text' }
  13. if (slug.length < 2 || slug.length > 40) { return 'the address must have 2–40 characters' }
  14. let i = 0
  15. while (i < slug.length) {
  16. c = slug.charCodeAt(i)
  17. ok = isLower(c) || isDigit(c) || (c == 45 && i > 0 && i < slug.length - 1)
  18. if (!ok) { return 'the address may only have lowercase letters a–z, digits and hyphens, and starts and ends with a letter or digit' }
  19. i = i + 1
  20. }
  21. if (slug.includes('--')) { return 'the address must not have two hyphens in a row' }
  22. if (reserved.includes(slug)) { return "'" + slug + "' is reserved for the system" }
  23. return null
  24. }
  25. // names an organization's repo may not have: its address would collide with a page of the organization's address
  26. static orgReserved = ['code' 'branch' 'commit' 'pulls' 'releases' 'tickets' 'settings' 'api' 'login' 'icons' '__git' '__hl' 'favicon' 'favicon.ico']
  27. // the rules for a repo's full name: `name` (slugError) or `org/name` (both parts valid, the repo name not a page word)
  28. static fullNameError = (full) => {
  29. if (full == null || hlTypeName(full) != 'String') { return 'the address must be text' }
  30. i = full.indexOf('/')
  31. if (i < 0) { return slugError(full) }
  32. bad = slugError(full.slice(0, i))
  33. if (bad != null) { return bad }
  34. name = full.slice(i + 1)
  35. bad2 = slugError(name)
  36. if (bad2 != null) { return bad2 }
  37. if (orgReserved.includes(name)) { return "'" + name + "' is reserved inside an organization" }
  38. return null
  39. }
  40. // what a page and the API show of a repo (never the tickets key); `eff` = the repo is private (its own flag or its organization's)
  41. static rowOf = (r, eff) => {
  42. org = r.org != null ? r.org : ''
  43. return { id = r.id slug = r.slug org = org inOrg = org != '' isPrivate = eff isPublic = !eff 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) + '/' }
  44. }
  45. // a repo's whole record with some fields changed (update() replaces the record: every field must be given again)
  46. static withChange = (r, change) => {
  47. 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 : '' org = r.org != null ? r.org : '' priv = r.priv == true }
  48. for (k of change.keys()) { o[k] = change[k] }
  49. return o
  50. }
  51. // the repo tab a path belongs to (components/repo.hl marks it): '/' readme · code/branch/commit pages 'code' · pulls · releases ·
  52. // tickets · settings, else ''
  53. static tabOfPath = (path) => {
  54. if (path == '' || path == '/') { return 'readme' }
  55. if (path == '/code' || path.startsWith('/code/') || path.startsWith('/branch/') || path.startsWith('/commit/')) { return 'code' }
  56. if (path == '/pulls' || path.startsWith('/pulls/')) { return 'pulls' }
  57. if (path == '/releases') { return 'releases' }
  58. if (path == '/tickets') { return 'tickets' }
  59. if (path == '/settings') { return 'settings' }
  60. return ''
  61. }
  62. // a tab title: 'Code · alpha · gitoria', 'alpha · gitoria', 'gitoria'
  63. static pageTitle = (site, slug, what) => {
  64. t = slug != null && slug != '' ? slug + ' · ' + site : site
  65. return what != null && what != '' ? what + ' · ' + t : t
  66. }
  67. // ---- the Markdown read view (Accept: text/markdown) — for LLM readers ---------------------------
  68. static repoDocument = (row) => {
  69. let out = '# ' + row.slug + NL + NL
  70. if (row.described) { out = out + row.description + NL + NL }
  71. out = out + '- address: ' + row.address + NL + '- owner: ' + row.owner + NL + '- created: ' + row.created + NL
  72. return out
  73. }
  74. static listDocument = (rows) => {
  75. let out = '# Repositories (' + rows.length + ')' + NL + NL
  76. if (rows.length == 0) { out = out + 'No repository yet.' + NL }
  77. for (r of rows) { out = out + '- [' + r.slug + '](' + r.address + ')' + (r.described ? ' — ' + r.description : '') + NL }
  78. return out
  79. }

Branches

Latest commits

  • 097c52baStyle the login error through its View idmre
  • c6d9c86aOwn the not-found code rule in its componentmre
  • 055424c2Record W61 replacement theme gates, sidebar repro and baselinemre
  • 2ed09441Use layouts theme 17e0f03 for W61 compatibilitymre
  • b8609a91Merge branch 'main' into w61-stylemre
  • 4639caf7Report W61 theme startup blocker and day39 Style probemre
  • 81f0a0bbREADME: two caches were restored by 90b4f72; log W62mre
  • 4a3f557eImport layouts theme ebd00b6 for W61 (startup blocked)mre
  • ab12a257Merge W62: #25 commit page measurements and proc repromre
  • 41323e49gitoria#25: measure commit request costs and reproduce blocking process waitsmre
  • 53ca42b2log: W60 merged, W61 W62 startedmre
  • 80870a33mission W61: style passmre
  • 560fd208Merge W60: helpers, bound forms, login in topics, two form fixes (gitoria#28 #32 #33)mre
  • ac5ba6a4log: W60, #25 measuredmre
  • 220f6342W60: record corrected form proof, full AE and remaining gapsmre
  • 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
  • ae373cfdgitoria#28: keep each reply draft in its thread componentmre
  • eeeebd5agitoria: insert a newly created organization oncemre
  • 34d2d5cagitoria: clear the bound public-key textarea after creationmre
  • 119e54c0W60: restore conductor-owned tracking filesmre