tickets
All repositories: gitoria
4.5 KB
// Projection and capped Markdown for ticket #51. Relevance uses stable user ids except textual mentions.import { eventRecord, eventRecordsOf } from './events.hl'import { ticketRecord } from './tickets.hl'import { payloadOf } from './stream.hl'import { oneLine } from './util.hl'// Creation events predate summary snapshots. The earliest edit keeps the original summary.static creationSummary = (t) => {let seq = nulllet original = t.summaryfor (e of eventRecordsOf(t.id)) {if (e.kind == 'edit' && (seq == null || e.seq < seq)) { seq = e.seq original = e.oldSummary }}return original}static deltaTickets = (rows, user) => {byId = {}order = []for (r of rows) {e = eventRecord(r.event)t = ticketRecord(r.ticket)if (e != null && t != null) {let item = byId[r.ticket]if (item == null) {p = payloadOf(r)item = { project = p.project number = r.number ref = p.ref subject = t.subject href = p.href changes = {} relevance = [] actors = [] lastAt = p.at }order.push(r.ticket)}c = item.changesif (r.kind == 'created') { c.created = true }if (r.kind == 'state') {if (c.state == null) { c.state = { from = e.from to = e.to } } else { c.state.to = e.to }}if (r.kind == 'edit') {if (e.oldSubject != e.subject) { c.titleEdited = true }if (e.oldSummary != e.summary) { c.summaryEdited = true }}if (r.kind == 'assign') {if (c.assignee == null) { c.assignee = { from = r.previous to = r.assignee } } else { c.assignee.to = r.assignee }}if (r.kind == 'comment') {c.comments = c.comments == null ? 1 : c.comments + 1c.lastComment = e.text.slice(0, 200)}if (r.kind == 'link') {if (c.links == null) { c.links = [] }c.links.push({ kind = e.linkKind action = e.action other = e.other project = e.otherProject number = e.otherNumber })}if ((t.assignee == user.id || r.assignee == user.id || r.previous == user.id) && !item.relevance.includes('assigned')) { item.relevance.push('assigned') }if (t.createdBy == user.id && !item.relevance.includes('own')) { item.relevance.push('own') }text = r.kind == 'comment' ? e.text : ((r.kind == 'edit' || r.kind == 'created') ? (r.kind == 'created' ? creationSummary(t) : e.summary) : '')if (user.name != '' && text != null && text.toLowerCase().includes(user.name.toLowerCase()) && !item.relevance.includes('mention')) { item.relevance.push('mention') }if (!item.actors.includes(r.actor)) { item.actors.push(r.actor) }item.lastAt = payloadOf(r).atitem.changes = cbyId[r.ticket] = item}}out = []for (id of order) { if (byId[id].relevance.length > 0) { out.push(byId[id]) } }for (id of order) { if (byId[id].relevance.length == 0) { out.push(byId[id]) } }return out}static newline = ""static ticketLine = (t) => {c = t.changesbits = []if (c.created == true) { bits.push('created') }if (c.state != null) { bits.push(c.state.from + ' → ' + c.state.to) }if (c.titleEdited == true) { bits.push('title edited') }if (c.summaryEdited == true) { bits.push('summary edited') }if (c.assignee != null) { bits.push('assignee ' + c.assignee.from + ' → ' + c.assignee.to) }if (c.comments != null) { bits.push(c.comments + ' comments: ' + oneLine(c.lastComment)) }if (c.links != null) { bits.push(c.links.length + ' links changed') }return '- ' + t.project + t.ref + ' ' + oneLine(t.subject).slice(0, 160) + ': ' + bits.join('; ') + (t.relevance.length > 0 ? ' [' + t.relevance.join(', ') + ']' : '') + ' ' + t.href + newline}static overflowLine = (tickets, start) => {counts = {}projects = []let i = startwhile (i < tickets.length) {p = tickets[i].projectif (counts[p] == null) { counts[p] = 0 projects.push(p) }counts[p] = counts[p] + 1i = i + 1}parts = []let omittedProjects = 0let omittedTickets = 0for (p of projects) {part = p + ' (' + counts[p] + ')'if (toBytes(parts.join(', ') + part).length <= 2000) { parts.push(part) } else {omittedProjects = omittedProjects + 1omittedTickets = omittedTickets + counts[p]}}if (omittedProjects > 0) { parts.push(omittedProjects + ' other projects (' + omittedTickets + ')') }return '… and ' + (tickets.length - start) + ' more tickets in ' + parts.join(', ') + newline}static deltaMarkdown = (tickets) => {let out = ''let i = 0while (i < tickets.length) {line = ticketLine(tickets[i])tail = i + 1 < tickets.length ? overflowLine(tickets, i + 1) : ''if (toBytes(out + line + tail).length > 4096) { return out + overflowLine(tickets, i) }out = out + linei = i + 1}return out == '' ? 'No new ticket changes.' + newline : out}
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