gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9af07ece9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre9af07ece/lib/git-helpers.hl

4.5 KB

  1. // lib/git-helpers.hl — what the git readers look up: path and name checks, ids, tab-separated fields, sizes, and the
  2. // commit-subject markers of pull requests (`|||PR`) and releases (`|||RL`). Statics only, git itself is not called here.
  3. // a path we let through: printable, no leading dash, no backslash / quote / control characters
  4. static safePath = (path) => {
  5. if (path == null || path == '' || path.length > 300 || path.startsWith('-')) { return false }
  6. let i = 0
  7. while (i < path.length) {
  8. c = path.charCodeAt(i)
  9. if (c < 32 || c == 127 || c == 34 || c == 92 || c == 58) { return false }
  10. i = i + 1
  11. }
  12. return true
  13. }
  14. static safeName = (n) => { return safePath(n) && n.length <= 100 && !n.endsWith('/') && !n.includes('//') }
  15. // a URL path piece: percent-encoded, the slashes kept (encodeURIComponent is a global since hybriel #14)
  16. static enc = (s) => { return encodeURIComponent(s).replaceAll('%2F', '/') }
  17. static isHexId = (s) => {
  18. if (s == null || s.length < 4 || s.length > 40) { return false }
  19. let i = 0
  20. while (i < s.length) {
  21. c = s.charCodeAt(i)
  22. if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 102))) { return false }
  23. i = i + 1
  24. }
  25. return true
  26. }
  27. // tab-separated fields of a line git wrote. (split() / indexOf() do not find a tab in a line that
  28. // came from hl:proc, so scan by character code.)
  29. static tabAt = (line) => {
  30. let i = 0
  31. while (i < line.length) {
  32. if (line.charCodeAt(i) == 9) { return i }
  33. i = i + 1
  34. }
  35. return -1
  36. }
  37. static tabs = (line) => {
  38. out = []
  39. let start = 0
  40. let i = 0
  41. while (i < line.length) {
  42. if (line.charCodeAt(i) == 9) {
  43. out.push(line.slice(start, i))
  44. start = i + 1
  45. }
  46. i = i + 1
  47. }
  48. out.push(line.slice(start))
  49. return out
  50. }
  51. static sizeText = (n) => {
  52. if (n < 1024) { return n + ' B' }
  53. unit = n < 1048576 ? 1024 : 1048576
  54. t = (n * 10 - (n * 10) % unit) / unit
  55. return ((t - t % 10) / 10) + '.' + (t % 10) + (n < 1048576 ? ' KB' : ' MB')
  56. }
  57. // ---- the markers (pulls.hl, releases.hl) ----------------------------------------------------------
  58. // a commit subject → null (not a request) or { target: '' (= default) | name, title }
  59. static parsePull = (subject) => {
  60. if (subject == null) { return null }
  61. if (subject == '|||PR') { return { target = '' title = '' } }
  62. if (subject.startsWith('|||PR ')) { return { target = '' title = subject.slice(6).trim() } }
  63. if (subject.startsWith('|||PR|')) {
  64. close = subject.indexOf(']')
  65. if (close < 7) { return null }
  66. let target = subject.slice(6, close)
  67. rest = subject.slice(close + 1)
  68. if (rest != '' && !rest.startsWith(' ')) { return null }
  69. if (!safeName(target)) { return null }
  70. return { target = target title = rest.trim() }
  71. }
  72. return null
  73. }
  74. static isDigits = (s) => {
  75. if (s == '' || s.length > 9) { return false }
  76. let i = 0
  77. while (i < s.length) {
  78. c = s.charCodeAt(i)
  79. if (c < 48 || c > 57) { return false }
  80. i = i + 1
  81. }
  82. return true
  83. }
  84. // the part of a version after its patch digits: only letters, digits, `.` and `-`
  85. static suffixOk = (s) => {
  86. let i = 0
  87. while (i < s.length) {
  88. c = s.charCodeAt(i)
  89. if (!((c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 45 || c == 46)) { return false }
  90. i = i + 1
  91. }
  92. return true
  93. }
  94. // `1.2.3` or `1.2.3a` → { major, minor, patch, text } or null
  95. static parseVersion = (t) => {
  96. if (t == null || t.length > 32) { return null }
  97. parts = t.split('.')
  98. if (parts.length < 3) { return null }
  99. if (!isDigits(parts[0]) || !isDigits(parts[1])) { return null }
  100. rest = parts.slice(2).join('.')
  101. let n = 0
  102. while (n < rest.length && rest.charCodeAt(n) >= 48 && rest.charCodeAt(n) <= 57) { n = n + 1 }
  103. if (n == 0 || n > 9 || !suffixOk(rest.slice(n))) { return null }
  104. return { major = toNumber(parts[0]) minor = toNumber(parts[1]) patch = toNumber(rest.slice(0, n)) text = t }
  105. }
  106. // a commit subject → null (not a release) or { kind: 'patch' | 'med' | 'mj' | 'set', version, title }
  107. static parseRelease = (subject) => {
  108. if (subject == null) { return null }
  109. if (subject == '|||RL') { return { kind = 'patch' version = null title = '' } }
  110. if (subject.startsWith('|||RL ')) { return { kind = 'patch' version = null title = subject.slice(6).trim() } }
  111. if (subject.startsWith('|||RL|')) {
  112. body = subject.slice(6)
  113. sp = body.indexOf(' ')
  114. token = sp < 0 ? body : body.slice(0, sp)
  115. let title = sp < 0 ? '' : body.slice(sp + 1).trim()
  116. if (token == 'med') { return { kind = 'med' version = null title = title } }
  117. if (token == 'mj') { return { kind = 'mj' version = null title = title } }
  118. v = parseVersion(token)
  119. if (v == null) { return null }
  120. return { kind = 'set' version = v title = title }
  121. }
  122. return null
  123. }

Branches

Latest commits

  • 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
  • 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
  • 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
  • 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
  • a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
  • 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
  • c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre