gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfd23726afd23726aAdd subscription delta API and signed wake bridgemrefd23726a/lib/subscriptions-format.hl

3.8 KB

  1. // Projection and capped Markdown for ticket #51. Relevance uses stable user ids except textual mentions.
  2. import { eventRecord } from './events.hl'
  3. import { ticketRecord } from './tickets.hl'
  4. import { payloadOf } from './stream.hl'
  5. import { oneLine } from './util.hl'
  6. static deltaTickets = (rows, user) => {
  7. byId = {}
  8. order = []
  9. for (r of rows) {
  10. e = eventRecord(r.event)
  11. t = ticketRecord(r.ticket)
  12. if (e != null && t != null) {
  13. let item = byId[r.ticket]
  14. if (item == null) {
  15. p = payloadOf(r)
  16. item = { project = p.project number = r.number ref = p.ref subject = t.subject href = p.href changes = {} relevance = [] actors = [] lastAt = p.at }
  17. order.push(r.ticket)
  18. }
  19. c = item.changes
  20. if (r.kind == 'created') { c.created = true }
  21. if (r.kind == 'state') {
  22. if (c.state == null) { c.state = { from = e.from to = e.to } } else { c.state.to = e.to }
  23. }
  24. if (r.kind == 'edit') {
  25. if (e.oldSubject != e.subject) { c.titleEdited = true }
  26. if (e.oldSummary != e.summary) { c.summaryEdited = true }
  27. }
  28. if (r.kind == 'assign') {
  29. if (c.assignee == null) { c.assignee = { from = r.previous to = r.assignee } } else { c.assignee.to = r.assignee }
  30. }
  31. if (r.kind == 'comment') {
  32. c.comments = c.comments == null ? 1 : c.comments + 1
  33. c.lastComment = e.text.slice(0, 200)
  34. }
  35. if (r.kind == 'link') {
  36. if (c.links == null) { c.links = [] }
  37. c.links.push({ kind = e.linkKind action = e.action other = e.other project = e.otherProject number = e.otherNumber })
  38. }
  39. if ((r.assignee == user.id || r.previous == user.id) && !item.relevance.includes('assigned')) { item.relevance.push('assigned') }
  40. if (t.createdBy == user.id && !item.relevance.includes('own')) { item.relevance.push('own') }
  41. text = r.kind == 'comment' ? e.text : ((r.kind == 'edit' || r.kind == 'created') ? (e.summary != null ? e.summary : t.summary) : '')
  42. if (user.name != '' && text != null && text.toLowerCase().includes(user.name.toLowerCase()) && !item.relevance.includes('mention')) { item.relevance.push('mention') }
  43. if (!item.actors.includes(r.actor)) { item.actors.push(r.actor) }
  44. item.lastAt = payloadOf(r).at
  45. item.changes = c
  46. byId[r.ticket] = item
  47. }
  48. }
  49. out = []
  50. for (id of order) { if (byId[id].relevance.length > 0) { out.push(byId[id]) } }
  51. for (id of order) { if (byId[id].relevance.length == 0) { out.push(byId[id]) } }
  52. return out
  53. }
  54. static newline = "
  55. "
  56. static ticketLine = (t) => {
  57. c = t.changes
  58. bits = []
  59. if (c.created == true) { bits.push('created') }
  60. if (c.state != null) { bits.push(c.state.from + ' → ' + c.state.to) }
  61. if (c.titleEdited == true) { bits.push('title edited') }
  62. if (c.summaryEdited == true) { bits.push('summary edited') }
  63. if (c.assignee != null) { bits.push('assignee ' + c.assignee.from + ' → ' + c.assignee.to) }
  64. if (c.comments != null) { bits.push(c.comments + ' comments: ' + oneLine(c.lastComment)) }
  65. if (c.links != null) { bits.push(c.links.length + ' links changed') }
  66. return '- ' + t.project + t.ref + ' ' + oneLine(t.subject).slice(0, 160) + ': ' + bits.join('; ') + (t.relevance.length > 0 ? ' [' + t.relevance.join(', ') + ']' : '') + ' ' + t.href + newline
  67. }
  68. static overflowLine = (tickets, from) => {
  69. counts = {}
  70. projects = []
  71. let i = from
  72. while (i < tickets.length) {
  73. p = tickets[i].project
  74. if (counts[p] == null) { counts[p] = 0 projects.push(p) }
  75. counts[p] = counts[p] + 1
  76. i = i + 1
  77. }
  78. parts = []
  79. for (p of projects) { parts.push(p + ' (' + counts[p] + ')') }
  80. return '… and ' + (tickets.length - from) + ' more tickets in ' + parts.join(', ') + newline
  81. }
  82. static deltaMarkdown = (tickets) => {
  83. let out = ''
  84. let i = 0
  85. while (i < tickets.length) {
  86. line = ticketLine(tickets[i])
  87. tail = i + 1 < tickets.length ? overflowLine(tickets, i + 1) : ''
  88. if (toBytes(out + line + tail).length > 4096) { return out + overflowLine(tickets, i) }
  89. out = out + line
  90. i = i + 1
  91. }
  92. return out == '' ? 'No new ticket changes.' + newline : out
  93. }

Branches

Latest commits

  • fd23726aAdd subscription delta API and signed wake bridgemre
  • c5d28fb5Tickets conductor: S51 startedmre
  • fd6ca1e6Tickets conductor: brief 027 waker design, push-test projectmre
  • e448e656Tickets conductor: STATUS #51mre
  • 1c10857bTickets conductor: P51 eval, brief 027mre
  • e725969dTickets conductor: #51 directionmre
  • 1b5c63ddTickets conductor: P51 startedmre
  • 9f13fbdaTickets conductor: brief 026 prioritymre
  • acc477d9Tickets conductor: brief 026 + Vinzenz recommendationsmre
  • 9233a734Tickets conductor: brief 026 completemre
  • 5da589fdTickets conductor: brief 026 + Gitoria's answermre
  • a3cd5329Tickets conductor: tickets#51 opened, brief 026 draftmre
  • 6f6e5797Tickets conductor: STATUS wordingmre
  • 957de51fTickets conductor: T36 live, #36 review, #50 donemre
  • bc2fde32Merge branch 'main' into t36-stylemre
  • b7ca093atests: wait for the new row and normalize editor marker spacesmre
  • 41da3525Tickets conductor: flake cause, T36 deploy stepmre
  • 64c477e6Tickets conductor: deploy waits for Arachnemre
  • 467d7286Tickets conductor: T36 done, deploy questionmre
  • fed5ca81ticket_list: remove repeated selected-state coloursmre