gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain5d144817Merge branch 'records-t40' into mainTicketsmain/lib/subscriptions-format.hl

4.5 KB

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

Branches

Latest commits

  • 5d144817Merge branch 'records-t40' into mainTickets
  • 44ee6f06|||PR records: #43 #45 livemre
  • b8fdeee9Merge branch 'p39-routes' into mainTickets
  • a0187a0a|||PR Remove redundant route-order loopmre
  • 369e4b9cMerge branch 'k40-lists' into mainTickets
  • 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
  • 610d8e8aMerge branch 'records-t39' into mainTickets
  • 32bcdf24|||PR records: GO P39 K40mre
  • 4123c6d1Merge branch 'records-t38' into mainTickets
  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre