gitoria

gitoria

All repositories: gitoria

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

4.3 KB

  1. // lib/tickets-helpers.hl — what lib/tickets.hl looks up: where tickets lives, the shapes of its answers, and the
  2. // `#12` ticket references in commit subjects and pull request titles (links both ways). Statics only, no fetch here.
  3. // Config (environment, or `.env` beside project.hl — never printed): GITORIA_TICKETS_URL, default https://tickets.worldapi.org
  4. import { envOr, isDigit } from './util.hl'
  5. static ticketsRaw = envOr('GITORIA_TICKETS_URL', 'https://tickets.worldapi.org')
  6. static ticketsUrl = ticketsRaw.endsWith('/') ? ticketsRaw.slice(0, ticketsRaw.length - 1) : ticketsRaw
  7. static maxRows = 200
  8. static agent = 'gitoria.worldapi.org (tickets)'
  9. // a code tickets sent back: letters, digits, `-` and `_`
  10. static isCode = (s) => {
  11. if (s == null || hlTypeName(s) != 'String' || s.length == 0 || s.length > 200) { return false }
  12. let i = 0
  13. while (i < s.length) {
  14. c = s.charCodeAt(i)
  15. if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 122) || (c >= 65 && c <= 90) || c == 45 || c == 95)) { return false }
  16. i = i + 1
  17. }
  18. return true
  19. }
  20. static ticketHref = (project, n) => { return ticketsUrl + '/projects/' + project + '/' + n }
  21. // one row for the page (a state's words are shown as tickets writes them)
  22. static viewOf = (t) => {
  23. return { number = t.number subject = t.subject state = t.state stateSlug = t.stateSlug created = t.created updated = t.updated url = ticketsUrl + t.href }
  24. }
  25. // ---- a write as a person: its headers, the reason of a refusal ----------------------------------------
  26. static writeHeaders = (c, identity) => {
  27. return { 'user-agent' = agent 'authorization' = 'Bearer ' + c.key 'x-tickets-identity' = identity }
  28. }
  29. static whyOf = (r) => {
  30. j = r.json()
  31. return j != null && j.error != null ? ': ' + j.error : ''
  32. }
  33. // ---- "#12" in a text ---------------------------------------------------------------------------------
  34. static isWordCode = (c) => { return (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95 }
  35. // every `#N` of a text (N = 1–9 digits, not glued to a word before it): [{ at, len, n }]
  36. static refsOf = (text) => {
  37. out = []
  38. if (text == null || hlTypeName(text) != 'String') { return out }
  39. let i = 0
  40. while (i < text.length) {
  41. if (text[i] == '#' && (i == 0 || !isWordCode(text.charCodeAt(i - 1)))) {
  42. let j = i + 1
  43. while (j < text.length && j - i - 1 < 9 && isDigit(text.charCodeAt(j))) { j = j + 1 }
  44. stop = j >= text.length || !isWordCode(text.charCodeAt(j))
  45. if (j > i + 1 && stop && text.slice(i + 1, i + 2) != '0') { out.push({ at = i len = j - i n = toNumber(text.slice(i + 1, j)) }) }
  46. i = j
  47. } else {
  48. i = i + 1
  49. }
  50. }
  51. return out
  52. }
  53. // a text as pieces for a View: [{ text, href, isLink, isText }] — `#N` becomes a link when the repo is connected
  54. static refParts = (text, project) => {
  55. out = []
  56. t = text == null ? '' : '' + text
  57. refs = project == null || project == '' ? [] : refsOf(t)
  58. let pos = 0
  59. for (x of refs) {
  60. if (x.at > pos) { out.push({ text = t.slice(pos, x.at) href = '' isLink = false isText = true }) }
  61. out.push({ text = t.slice(x.at, x.at + x.len) href = ticketHref(project, x.n) isLink = true isText = false })
  62. pos = x.at + x.len
  63. }
  64. if (pos < t.length || out.length == 0) { out.push({ text = t.slice(pos) href = '' isLink = false isText = true }) }
  65. return out
  66. }
  67. // the numbers a text says it fixes: "fixes #3", "closes #4, #5"? — only the word directly before `#N` counts
  68. static fixedBy = (text) => {
  69. out = []
  70. t = text == null ? '' : ('' + text).toLowerCase()
  71. for (x of refsOf(t)) {
  72. before = t.slice(0, x.at).trimEnd()
  73. let ok = false
  74. for (w of ['fix', 'fixes', 'fixed', 'close', 'closes', 'closed', 'resolve', 'resolves', 'resolved']) {
  75. if (before.endsWith(w) && (before.length == w.length || !isWordCode(before.charCodeAt(before.length - w.length - 1)))) { ok = true }
  76. }
  77. if (ok && !out.includes(x.n)) { out.push(x.n) }
  78. }
  79. return out
  80. }
  81. // the commit list of a code page with pieces for the subjects (the View draws links from `parts`)
  82. static withRefParts = (data, project) => {
  83. if (data == null || data.isMessage) { return data }
  84. d = data
  85. d.subjectParts = refParts(d.subject, project)
  86. cs = []
  87. for (c of d.commits) {
  88. q = c
  89. q.parts = refParts(c.subject, project)
  90. cs.push(q)
  91. }
  92. d.commits = cs
  93. return d
  94. }
  95. static withPullParts = (list, project) => {
  96. out = []
  97. for (p of list) {
  98. q = p
  99. q.parts = refParts(p.title, project)
  100. out.push(q)
  101. }
  102. return out
  103. }

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