gitoria
All repositories: gitoria
4.3 KB
// lib/tickets-helpers.hl — what lib/tickets.hl looks up: where tickets lives, the shapes of its answers, and the// `#12` ticket references in commit subjects and pull request titles (links both ways). Statics only, no fetch here.// Config (environment, or `.env` beside project.hl — never printed): GITORIA_TICKETS_URL, default https://tickets.worldapi.orgimport { envOr, isDigit } from './util.hl'static ticketsRaw = envOr('GITORIA_TICKETS_URL', 'https://tickets.worldapi.org')static ticketsUrl = ticketsRaw.endsWith('/') ? ticketsRaw.slice(0, ticketsRaw.length - 1) : ticketsRawstatic maxRows = 200static agent = 'gitoria.worldapi.org (tickets)'// a code tickets sent back: letters, digits, `-` and `_`static isCode = (s) => {if (s == null || hlTypeName(s) != 'String' || s.length == 0 || s.length > 200) { return false }let i = 0while (i < s.length) {c = s.charCodeAt(i)if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 122) || (c >= 65 && c <= 90) || c == 45 || c == 95)) { return false }i = i + 1}return true}static ticketHref = (project, n) => { return ticketsUrl + '/projects/' + project + '/' + n }// one row for the page (a state's words are shown as tickets writes them)static viewOf = (t) => {return { number = t.number subject = t.subject state = t.state stateSlug = t.stateSlug created = t.created updated = t.updated url = ticketsUrl + t.href }}// ---- a write as a person: its headers, the reason of a refusal ----------------------------------------static writeHeaders = (c, identity) => {return { 'user-agent' = agent 'authorization' = 'Bearer ' + c.key 'x-tickets-identity' = identity }}static whyOf = (r) => {j = r.json()return j != null && j.error != null ? ': ' + j.error : ''}// ---- "#12" in a text ---------------------------------------------------------------------------------static isWordCode = (c) => { return (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95 }// every `#N` of a text (N = 1–9 digits, not glued to a word before it): [{ at, len, n }]static refsOf = (text) => {out = []if (text == null || hlTypeName(text) != 'String') { return out }let i = 0while (i < text.length) {if (text[i] == '#' && (i == 0 || !isWordCode(text.charCodeAt(i - 1)))) {let j = i + 1while (j < text.length && j - i - 1 < 9 && isDigit(text.charCodeAt(j))) { j = j + 1 }stop = j >= text.length || !isWordCode(text.charCodeAt(j))if (j > i + 1 && stop && text.slice(i + 1, i + 2) != '0') { out.push({ at = i len = j - i n = toNumber(text.slice(i + 1, j)) }) }i = j} else {i = i + 1}}return out}// a text as pieces for a View: [{ text, href, isLink, isText }] — `#N` becomes a link when the repo is connectedstatic refParts = (text, project) => {out = []t = text == null ? '' : '' + textrefs = project == null || project == '' ? [] : refsOf(t)let pos = 0for (x of refs) {if (x.at > pos) { out.push({ text = t.slice(pos, x.at) href = '' isLink = false isText = true }) }out.push({ text = t.slice(x.at, x.at + x.len) href = ticketHref(project, x.n) isLink = true isText = false })pos = x.at + x.len}if (pos < t.length || out.length == 0) { out.push({ text = t.slice(pos) href = '' isLink = false isText = true }) }return out}// the numbers a text says it fixes: "fixes #3", "closes #4, #5"? — only the word directly before `#N` countsstatic fixedBy = (text) => {out = []t = text == null ? '' : ('' + text).toLowerCase()for (x of refsOf(t)) {before = t.slice(0, x.at).trimEnd()let ok = falsefor (w of ['fix', 'fixes', 'fixed', 'close', 'closes', 'closed', 'resolve', 'resolves', 'resolved']) {if (before.endsWith(w) && (before.length == w.length || !isWordCode(before.charCodeAt(before.length - w.length - 1)))) { ok = true }}if (ok && !out.includes(x.n)) { out.push(x.n) }}return out}// the commit list of a code page with pieces for the subjects (the View draws links from `parts`)static withRefParts = (data, project) => {if (data == null || data.isMessage) { return data }d = datad.subjectParts = refParts(d.subject, project)cs = []for (c of d.commits) {q = cq.parts = refParts(c.subject, project)cs.push(q)}d.commits = csreturn d}static withPullParts = (list, project) => {out = []for (p of list) {q = pq.parts = refParts(p.title, project)out.push(q)}return out}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 097c52baStyle the login error through its View idmre
- c6d9c86aOwn the not-found code rule in its componentmre
- 055424c2Record W61 replacement theme gates, sidebar repro and baselinemre
- 2ed09441Use layouts theme 17e0f03 for W61 compatibilitymre
- b8609a91Merge branch 'main' into w61-stylemre
- 4639caf7Report W61 theme startup blocker and day39 Style probemre
- 81f0a0bbREADME: two caches were restored by 90b4f72; log W62mre
- 4a3f557eImport layouts theme ebd00b6 for W61 (startup blocked)mre
- ab12a257Merge W62: #25 commit page measurements and proc repromre
- 41323e49gitoria#25: measure commit request costs and reproduce blocking process waitsmre
- 53ca42b2log: W60 merged, W61 W62 startedmre
- 80870a33mission W61: style passmre
- 560fd208Merge W60: helpers, bound forms, login in topics, two form fixes (gitoria#28 #32 #33)mre
- ac5ba6a4log: W60, #25 measuredmre
- 220f6342W60: record corrected form proof, full AE and remaining gapsmre
- 7e31cac5gitoria#28: restrict reply form layout to reply formsmre
- ae373cfdgitoria#28: keep each reply draft in its thread componentmre
- eeeebd5agitoria: insert a newly created organization oncemre
- 34d2d5cagitoria: clear the bound public-key textarea after creationmre
- 119e54c0W60: restore conductor-owned tracking filesmre