gitoria
All repositories: gitoria
4.4 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 } 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) {let 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 isDigitCode = (c) => { return c >= 48 && c <= 57 }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 && isDigitCode(text.charCodeAt(j))) { j = j + 1 }let 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)) {let 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) {let q = cq.parts = refParts(c.subject, project)cs.push(q)}d.commits = csreturn d}static withPullParts = (list, project) => {out = []for (p of list) {let 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
- a81abdc9gitoria#34: org page via function route, member-reachable orgs, selects, reportmre
- 17f031f0gitoria#34: private repos, organizations, members, move tool, gatemre
- 71b69343gitoria#23: the sidebar's Repositories link was a 404 after any in-page navigation (static menu re-evaluated publicUrl in the browser); the menu is an instance property now; gate taps it after a tab, folder, filemre
- 90b4f728gitoria#25: restore the homepage cache and the parsed-blocks cache (they store data under immutable keys, no HTML); the page key, the framework readme key and the textHash key stay removedmre
- a487248cgitoria#25: remove every cache that hid the page build (page key, Markdown render key, homepage cache, parsed-blocks cache) and the gate that only tested themmre
- 12f2f4fegitoria: re-vendor Hybriel set-day27b, a startup fault in on Error exits 1mre
- c21c084egitoria: write the standby service out in full so the boot gate can read the main servicemre
- e307d69agitoria: say what is per process during the hand-overmre
- f0cbe6a6gitoria: standby service on port 45014 and a deploy that hands over through it without a gapmre
- 727cd083gitoria#25: README: vendor notes for Hybriel c1b1010f and the page cachemre
- 61b72dedgitoria#25: re-vendor Hybriel master c1b1010f (W149 page cache), key the repo Readme page by slug and main commit, extend the readme-cache gatemre
- 5b0b4b9ereadme-cache gate: use the security gate's ports when no own ports are givenmre
- bc8f20d9gitoria#25: re-vendor Hybriel c09538bb with the W141 render cache, cache the homepage per commit, add the readme-cache gatemre
- 9feebbd3Re-vendor Hybriel to ded47c13 (W145: Firefox start script fix)mre
- 28ed41e5gitoria#24: one sign-in comes from hl:web batch 20, the /session/share workaround is gonemre
- 3b2669e4gs: drop the unbuildable legacy check, fix pwa fetchmre
- 2a2fdd77gs: C2 check before cookie experimentsmre
- 76e0587aWIP gs 2mre
- a80da7bdWIP gs: security gate for lazy sessions, g24 browser checksmre
- 23fb05d8re-vendor Hybriel aaa39e69 (hl:web batch 20: login emit and Sessions.mint, tab follows a login, signed-in session cookie wins among duplicates and is re-issued with the Domain, W85 faster render, lazy sessions)mre