gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitcb634512cb634512log: 2026-11-08 keyed lists livemrecb634512/lib/git-helpers.hl

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

Branches

Latest commits

  • cb634512log: 2026-11-08 keyed lists livemre
  • 07c98d4aLists: keyed rows with @id, remove(id) and one whole-list assignment instead of hand-rebuilt loopsmre
  • 0db0d81elog: 2026-11-08 day52 live, W30 startedmre
  • b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmre
  • 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
  • f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre
  • dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
  • 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
  • 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
  • 71b2fa4blog: hybriel#335mre
  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre
  • bf568e14log: V48 mergedmre
  • 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre