gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commiteef80f55eef80f55tickets (mission 016): comments through the shared Comments block (layouts#2) — edit (author, earlier versions kept), delete (author, asks; leaves one line in the history), like (members, toggle) on the server (lib/comments.hl, append-only tables), faces + API …/comments/:comment/{edit,delete,like}, push commentChanged; every run of comments is a block in place in the history; Markdown fields on the Hybriel MdEditor (shared/md-editor.js retired: it took over the block's <md-editor>); blocks copied verbatim from components.hybriel 9db927d (tools/sync-components.sh); gates browser 351/0 (old 326/0), events 52/0 (old 52/0)mreeef80f55/lib/events.hl

8.2 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. // 'comment' (mission 016): the event keeps the FIRST text; edits, a deletion and likes are kept by
  14. // lib/comments.hl, and the rows here show the comment as it is now (commentStateOf).
  15. // tickets.hl writes the events (putEvent) together with the ticket record; this file shapes and reads them.
  16. import { MPackDB } from 'hl:mpackdb'
  17. import { storageDir, countOf, localStamp, ticketHref } from './util.hl'
  18. import { nameOfUser } from './users.hl'
  19. import { projectSlugOf } from './projects.hl'
  20. import { slugOf } from './tickets-helpers.hl'
  21. import { markdownBlocks } from './markdown.hl'
  22. import { commentStateOf, likersOf } from './comments.hl'
  23. static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['@ticket'])
  24. // ---- writing -------------------------------------------------------------------------------------
  25. // appends one event record (built field by field by tickets.hl); answers its id, or null (eventsError says why)
  26. static putEvent = (rec) => { return eventsTable.put(rec) }
  27. static eventsError = () => { return eventsTable.lastError() }
  28. // one stored event record, or null (the event stream numbers it, lib/stream.hl)
  29. static eventRecord = (eventId) => { return eventId == null ? null : eventsTable.fetch(eventId) }
  30. // the API row of a stored event
  31. static eventRowAt = (eventId, t) => { return eventRowOf(eventsTable.fetch(eventId), t) }
  32. // ---- reading -------------------------------------------------------------------------------------
  33. // the history of a ticket (a record), oldest first: by stored time, then seq
  34. static historyOf = (t) => {
  35. out = []
  36. all = eventsTable.find('ticket', t.id)
  37. if (countOf(all) == 0) { return out }
  38. for (e of all) { out.push(eventRowOf(e, t)) }
  39. let i = 1
  40. while (i < out.length) {
  41. let cur = out[i]
  42. let j = i - 1
  43. while (j >= 0 && (out[j].createdMs > cur.createdMs || (out[j].createdMs == cur.createdMs && out[j].seq > cur.seq))) {
  44. out[j + 1] = out[j]
  45. j = j - 1
  46. }
  47. out[j + 1] = cur
  48. i = i + 1
  49. }
  50. return out
  51. }
  52. // a ticket from before the login has no createdBy: the free-text author of its 'created' event
  53. static creatorNameOf = (t) => {
  54. all = eventsTable.find('ticket', t.id)
  55. if (countOf(all) == 0) { return '' }
  56. for (e of all) { if (e.kind == 'created') { return e.author != null ? e.author : '' } }
  57. return ''
  58. }
  59. // ---- the shapes ----------------------------------------------------------------------------------
  60. static eventRowOf = (e, t) => {
  61. let kind = e.kind
  62. // computed BEFORE the literal: inside a literal that has an `id` entry, a called function's
  63. // parameter named `id` read that entry instead (mission 011, reported as a Hybriel issue)
  64. who = e.user != null ? nameOfUser(e.user) : e.author
  65. let label = kind == 'created' ? 'opened the ticket' : (kind == 'state' ? 'changed the state' : (kind == 'edit' ? 'edited the ticket' : 'commented'))
  66. if (kind == 'link') { label = linkLabelOf(e) }
  67. let assignedTo = ''
  68. let assignedWas = ''
  69. if (kind == 'assign') {
  70. assignedTo = e.assignee != null && e.assignee != '' ? nameOfUser(e.assignee) : ''
  71. assignedWas = e.previous != null && e.previous != '' ? nameOfUser(e.previous) : ''
  72. label = assignedTo != '' ? 'assigned the ticket to ' + assignedTo : 'unassigned the ticket' + (assignedWas != '' ? ' (was ' + assignedWas + ')' : '')
  73. }
  74. row = {
  75. id = e.id
  76. ticket = e.ticket
  77. project = t != null ? projectSlugOf(t) : ''
  78. number = t != null ? t.number : 0
  79. seq = e.seq != null ? e.seq : 0
  80. kind = kind
  81. author = who
  82. userId = e.user != null ? e.user : ''
  83. text = e.text != null ? e.text : ''
  84. hasText = e.text != null && e.text != ''
  85. from = e.from != null ? e.from : ''
  86. to = e.to != null ? e.to : ''
  87. toSlug = slugOf(e.to)
  88. isState = kind == 'state'
  89. isComment = kind == 'comment'
  90. isCreated = kind == 'created'
  91. label = label
  92. when = localStamp(e.created)
  93. createdMs = e.created
  94. }
  95. // ticket #8: only an edit event carries these (the JSON of every other event is unchanged)
  96. if (kind == 'edit') {
  97. row.isEdit = true
  98. row.oldSubject = e.oldSubject != null ? e.oldSubject : ''
  99. row.oldSummary = e.oldSummary != null ? e.oldSummary : ''
  100. row.newSubject = e.subject != null ? e.subject : ''
  101. row.newSummary = e.summary != null ? e.summary : ''
  102. row.subjectChanged = row.oldSubject != row.newSubject
  103. row.summaryChanged = row.oldSummary != row.newSummary
  104. }
  105. // ticket #4: only a link event carries these
  106. if (kind == 'link') {
  107. row.isLink = true
  108. row.linkKind = e.linkKind
  109. row.linkAction = e.action
  110. row.otherRef = e.otherProject + ' #' + e.otherNumber
  111. row.otherHref = ticketHref(e.otherProject, e.otherNumber)
  112. row.previousRef = e.previous != null ? e.previousProject + ' #' + e.previousNumber : ''
  113. }
  114. // mission 016: a comment as it is NOW (lib/comments.hl). Only a changed comment carries the extra keys: an edited one
  115. // `edited`, `editedWhen`, `earlier` ([{ when, text }], the versions before, oldest first) and the newest `text`; a
  116. // deleted one `deleted`, `deletedWhen`, no text, the label "commented (deleted …)"; a liked one `likes` (the count).
  117. // Every other comment row has exactly the keys it had before.
  118. if (kind == 'comment') {
  119. cs = commentStateOf(e)
  120. if (cs.edited) {
  121. row.text = cs.text
  122. row.hasText = cs.text != ''
  123. row.edited = true
  124. row.editedWhen = localStamp(cs.editedMs)
  125. row.earlier = versionsOf(cs.earlier)
  126. }
  127. if (cs.deleted) {
  128. row.text = ''
  129. row.hasText = false
  130. row.label = 'commented (deleted ' + localStamp(cs.deletedMs) + ')'
  131. row.deleted = true
  132. row.deletedWhen = localStamp(cs.deletedMs)
  133. }
  134. if (cs.likes > 0) { row.likes = cs.likes }
  135. }
  136. // ticket #20: only an assign event carries these
  137. if (kind == 'assign') {
  138. row.isAssign = true
  139. row.assignee = assignedTo
  140. row.previousAssignee = assignedWas
  141. }
  142. return row
  143. }
  144. static versionsOf = (list) => {
  145. out = []
  146. for (v of list) { out.push({ when = v.when text = v.text }) }
  147. return out
  148. }
  149. // "set the parent to ident.worldapi.org #1", "removed the blocker tickets.worldapi.org #6", …
  150. static linkLabelOf = (e) => {
  151. other = e.otherProject + ' #' + e.otherNumber
  152. if (e.linkKind == 'parent') {
  153. if (e.action == 'removed') { return 'removed the parent ' + other }
  154. was = e.previous != null ? ' (was ' + e.previousProject + ' #' + e.previousNumber + ')' : ''
  155. return 'set the parent to ' + other + was
  156. }
  157. if (e.action == 'removed') { return 'removed the blocker ' + other }
  158. return 'marked it blocked by ' + other
  159. }
  160. // THE PAGE'S EVENT ROW (ticket #6): the API row + its text as Markdown blocks (`md`), and for an
  161. // edit the previous summary's blocks (`oldSummaryMd`) and the new one's (`summaryMd`, the ticket
  162. // page takes it over live). Only pages and pushes carry these — the JSON API does not.
  163. static pageEventOf = (ev) => {
  164. out = {}
  165. for (k of ev.keys()) { out[k] = ev[k] }
  166. out.md = markdownBlocks(ev.text)
  167. // mission 016: who likes a comment (users @ids) — the page works out `liked` for the user looking
  168. if (ev.isComment == true) { out.likedBy = likersOf(ev.id) }
  169. if (ev.isEdit == true) {
  170. out.oldSummaryMd = markdownBlocks(ev.oldSummary)
  171. out.summaryMd = markdownBlocks(ev.newSummary)
  172. }
  173. return out
  174. }
  175. static pageEventsOf = (evs) => {
  176. out = []
  177. for (ev of evs) { out.push(pageEventOf(ev)) }
  178. return out
  179. }

Branches

Latest commits

  • eef80f55tickets (mission 016): comments through the shared Comments block (layouts#2) — edit (author, earlier versions kept), delete (author, asks; leaves one line in the history), like (members, toggle) on the server (lib/comments.hl, append-only tables), faces + API …/comments/:comment/{edit,delete,like}, push commentChanged; every run of comments is a block in place in the history; Markdown fields on the Hybriel MdEditor (shared/md-editor.js retired: it took over the block's <md-editor>); blocks copied verbatim from components.hybriel 9db927d (tools/sync-components.sh); gates browser 351/0 (old 326/0), events 52/0 (old 52/0)mre
  • eb7aeeb9mission brief 016mre
  • e4c34759paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 26efb23freport w6-events (events test)mre
  • c6bfab04mission 015: re-vendor Hybriel 0f396652 (static build), reportmre
  • b7ec5981mission brief 015mre
  • 5dc68731docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 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