gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8a460b168a460b16mission 014: Apollo's 'stream opened right after the start gets no live events' is not a tickets bug — events.mjs checks early streamsmre8a460b16/lib/events.hl

6.8 KB

  1. // lib/events.hl — THE HISTORY OF A TICKET: an append-only event per change. Statics only, the server realm.
  2. // eventsTable pk @id index @ticket APPEND ONLY: { ticket (ticket @id), seq
  3. // (1, 2, … per ticket), kind, author, user?, text, from, to, created, oldId? }
  4. // kind = 'created' | 'comment' | 'state' | 'edit' | 'link' | 'assign'
  5. // 'assign' (ticket #20): { assignee (users @id, '' = unassigned), previous (users @id, '') }
  6. // 'link' (ticket #4, mission 017): { linkKind ('parent' | 'blockedBy'), action
  7. // ('set' | 'removed'), other, otherProject, otherNumber, previous?, previousProject?,
  8. // previousNumber? } — on the CHILD / the BLOCKED ticket (the one whose relation changed).
  9. // 'edit' (ticket #8, mission 014): { oldSubject, oldSummary, subject, summary } —
  10. // the values before AND after; the ticket record then carries the new ones.
  11. // `user` (users @id, users.hl) since ticket #7: the event's author is that
  12. // user's CURRENT display name; `author` keeps the name at writing time.
  13. // tickets.hl writes the events (putEvent) together with the ticket record; this file shapes and reads them.
  14. import { MPackDB } from 'hl:mpackdb'
  15. import { storageDir, countOf, localStamp, ticketHref } from './util.hl'
  16. import { nameOfUser } from './users.hl'
  17. import { projectSlugOf } from './projects.hl'
  18. import { slugOf } from './tickets-helpers.hl'
  19. import { markdownBlocks } from './markdown.hl'
  20. static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['@ticket'])
  21. // ---- writing -------------------------------------------------------------------------------------
  22. // appends one event record (built field by field by tickets.hl); answers its id, or null (eventsError says why)
  23. static putEvent = (rec) => { return eventsTable.put(rec) }
  24. static eventsError = () => { return eventsTable.lastError() }
  25. // one stored event record, or null (the event stream numbers it, lib/stream.hl)
  26. static eventRecord = (eventId) => { return eventId == null ? null : eventsTable.fetch(eventId) }
  27. // the API row of a stored event
  28. static eventRowAt = (eventId, t) => { return eventRowOf(eventsTable.fetch(eventId), t) }
  29. // ---- reading -------------------------------------------------------------------------------------
  30. // the history of a ticket (a record), oldest first: by stored time, then seq
  31. static historyOf = (t) => {
  32. out = []
  33. all = eventsTable.find('ticket', t.id)
  34. if (countOf(all) == 0) { return out }
  35. for (e of all) { out.push(eventRowOf(e, t)) }
  36. let i = 1
  37. while (i < out.length) {
  38. let cur = out[i]
  39. let j = i - 1
  40. while (j >= 0 && (out[j].createdMs > cur.createdMs || (out[j].createdMs == cur.createdMs && out[j].seq > cur.seq))) {
  41. out[j + 1] = out[j]
  42. j = j - 1
  43. }
  44. out[j + 1] = cur
  45. i = i + 1
  46. }
  47. return out
  48. }
  49. // a ticket from before the login has no createdBy: the free-text author of its 'created' event
  50. static creatorNameOf = (t) => {
  51. all = eventsTable.find('ticket', t.id)
  52. if (countOf(all) == 0) { return '' }
  53. for (e of all) { if (e.kind == 'created') { return e.author != null ? e.author : '' } }
  54. return ''
  55. }
  56. // ---- the shapes ----------------------------------------------------------------------------------
  57. static eventRowOf = (e, t) => {
  58. let kind = e.kind
  59. // computed BEFORE the literal: inside a literal that has an `id` entry, a called function's
  60. // parameter named `id` read that entry instead (mission 011, reported as a Hybriel issue)
  61. who = e.user != null ? nameOfUser(e.user) : e.author
  62. let label = kind == 'created' ? 'opened the ticket' : (kind == 'state' ? 'changed the state' : (kind == 'edit' ? 'edited the ticket' : 'commented'))
  63. if (kind == 'link') { label = linkLabelOf(e) }
  64. let assignedTo = ''
  65. let assignedWas = ''
  66. if (kind == 'assign') {
  67. assignedTo = e.assignee != null && e.assignee != '' ? nameOfUser(e.assignee) : ''
  68. assignedWas = e.previous != null && e.previous != '' ? nameOfUser(e.previous) : ''
  69. label = assignedTo != '' ? 'assigned the ticket to ' + assignedTo : 'unassigned the ticket' + (assignedWas != '' ? ' (was ' + assignedWas + ')' : '')
  70. }
  71. row = {
  72. id = e.id
  73. ticket = e.ticket
  74. project = t != null ? projectSlugOf(t) : ''
  75. number = t != null ? t.number : 0
  76. seq = e.seq != null ? e.seq : 0
  77. kind = kind
  78. author = who
  79. userId = e.user != null ? e.user : ''
  80. text = e.text != null ? e.text : ''
  81. hasText = e.text != null && e.text != ''
  82. from = e.from != null ? e.from : ''
  83. to = e.to != null ? e.to : ''
  84. toSlug = slugOf(e.to)
  85. isState = kind == 'state'
  86. isComment = kind == 'comment'
  87. isCreated = kind == 'created'
  88. label = label
  89. when = localStamp(e.created)
  90. createdMs = e.created
  91. }
  92. // ticket #8: only an edit event carries these (the JSON of every other event is unchanged)
  93. if (kind == 'edit') {
  94. row.isEdit = true
  95. row.oldSubject = e.oldSubject != null ? e.oldSubject : ''
  96. row.oldSummary = e.oldSummary != null ? e.oldSummary : ''
  97. row.newSubject = e.subject != null ? e.subject : ''
  98. row.newSummary = e.summary != null ? e.summary : ''
  99. row.subjectChanged = row.oldSubject != row.newSubject
  100. row.summaryChanged = row.oldSummary != row.newSummary
  101. }
  102. // ticket #4: only a link event carries these
  103. if (kind == 'link') {
  104. row.isLink = true
  105. row.linkKind = e.linkKind
  106. row.linkAction = e.action
  107. row.otherRef = e.otherProject + ' #' + e.otherNumber
  108. row.otherHref = ticketHref(e.otherProject, e.otherNumber)
  109. row.previousRef = e.previous != null ? e.previousProject + ' #' + e.previousNumber : ''
  110. }
  111. // ticket #20: only an assign event carries these
  112. if (kind == 'assign') {
  113. row.isAssign = true
  114. row.assignee = assignedTo
  115. row.previousAssignee = assignedWas
  116. }
  117. return row
  118. }
  119. // "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …
  120. static linkLabelOf = (e) => {
  121. other = e.otherProject + ' #' + e.otherNumber
  122. if (e.linkKind == 'parent') {
  123. if (e.action == 'removed') { return 'removed the parent ' + other }
  124. was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''
  125. return 'set the parent to ' + other + was
  126. }
  127. if (e.action == 'removed') { return 'removed the blocker ' + other }
  128. return 'marked it blocked by ' + other
  129. }
  130. // THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an
  131. // edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket
  132. // page takes it over live). Only pages and pushes carry these — the JSON API does not.
  133. static pageEventOf = (ev) => {
  134. out = {}
  135. for (k of ev.keys()) { out[k] = ev[k] }
  136. out.md = markdownBlocks(ev.text)
  137. if (ev.isEdit == true) {
  138. out.oldSummaryMd = markdownBlocks(ev.oldSummary)
  139. out.summaryMd = markdownBlocks(ev.newSummary)
  140. }
  141. return out
  142. }
  143. static pageEventsOf = (evs) => {
  144. out = []
  145. for (ev of evs) { out.push(pageEventOf(ev)) }
  146. return out
  147. }

Branches

Latest commits

  • 8a460b16mission 014: Apollo's 'stream opened right after the start gets no live events' is not a tickets bug — events.mjs checks early streamsmre
  • 6309ca81mission brief 014mre
  • c1161469mission 013: GitHub pipe tables on ticket pages (lib/markdown.hl + View + CSS) and re-vendor hybriel master a832f73bmre
  • a30b5d12mission brief (w13)mre
  • b50a6f93w9 (tickets): re-vendor hybriel 9f912f3b (#146 emit in a lib static, #147) — the 12 live-push emits in lib/api.hl compile as they are; cold start (#148): tests wait TICKETS_COLD_MS for every start, deploy.sh gates browser + events and waits up to 120 s for the URL, container /tmp tmpfs + hybriel-cache volume; events-client stops at EVENTS_MAX inside a chunk; connect.mjs ports by env. bin/hybriel sha256 7421907868ac07d8a7d08296b083c6f8b20407d0e099ce4bebbf7ae053d9060a. Gates (8720–8739): browser 315/0 (+ all-cold 315/0), events 48/0 cold, connect 60/0, short-id 19/0; real-data copy old 0e8a41c vs new: 2,425 reads + 72 writes identical after masking ?v hashes, offline at, route order; event stream on the copy delivers. Not deployed.mre
  • 43be6578w9: re-vendor hybriel master edfd400a; event stream imports sseStart/sseSend/sseAlive from hl:http1 (hybriel#144), useTransport gone; tools/import.hl plain declarations. BLOCKED: hybriel-native refuses `emit client` in a static (lib/api.hl) — the server does not compile on edfd400a, gates fail at start; scratch copy without those emits: events 48/0, gate 254 ok up to the first live pushmre
  • 0e8a41caw6 (ticket #26): event stream for programs — GET /api/events (Server-Sent Events)mre
  • bb64d57cmission 012 (ticket #25 API part): every /api/projects/<x>/… route takes the project's id (12-char record id) as well as its slug, same answers byte for byte; tickets stay under their project, no global /api/tickets/<x>. gate 315/0 (old code: the 13 id checks fail), connect 60/0, live-data copy old vs new 1,484 identical, slug vs id 772 identicalmre
  • 7538b034mission 011 (ticket #25 web part): short page URLs /<slug> and /<slug>/<number>; /projects/<slug>, /projects/<slug>/<n>, /projects/<slug>/tickets/<n> and /tickets/<ref> answer 301 (current slug); slug pages moved behind hl:web's own routes after construction (they answered /__hl/* and /components/*.hl); reserved slugs refused; API paths unchanged. gate 293/0, connect 60/0, live-data copy 187/0, API old vs new: only page links differmre
  • 0369106emission 010 (code order) 4/4: README file map + import order + 'Same output' test, STATUS (entry, lessons, how to verify), LOG, report; tests/realdata-baseline.mjs + realdata-compare*.py (a cleanup answers the same on live data), tests/letcount.pymre
  • a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemre
  • e9d5c618mission 010 (code order) 2/4: one lib/ file per topic — store.hl split into projects / tickets (+ relations) / events / tickets-helpers, util.hl shared helpers (env, storage dir, URLs, sorts, Vienna time), the function routes out of project.hl into lib/api.hl (thin; auth/filters/Accept in api-helpers.hl), invite + member-removal logic out of the faces/routes into invites.hl / tickets.hl; project.hl is the map. /login/callback gets req + the session store by reference. gate 249/0, connect 60/0, real-data reads identicalmre
  • 97e269b5mission 010 (code order) 1/4: .hl files out of the root — lib/ (store, users, connections, invites, migrate, markdown, mdview, import = ticketfile, util = localtime, jsoncheck, api-helpers = api), tools/import.hl, components/styles.hl; import paths only. gate 249/0, connect 60/0, real-data reads identicalmre
  • 38f9d10ftickets: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gate 249/0, connect 60/0mre
  • d3db6139tickets: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 249/0, connect 60/0mre
  • bce182e3tickets: Hybriel master 7eea0d32 (#126 memory, #48 lambda copies its argument); migrate.hl lambdas take &logmre
  • 4137be0fantcolony#40: mission references point to the moved missionsmre
  • 9bfba36aantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • c7bd2645tickets: Hybriel master 73267707 (#122 fixed); compactNow workaround removed (#110 covered)mre
  • 2ab91ee9tickets: gate checks rows appear once (session sync); re-vendor to ff51cf46 stopped on hybriel#122, stays 837fe120mre