tickets
All repositories: gitoria
3.0 KB
// tools/import.hl — import AntColony ticket files into the RUNNING app, over its JSON API.//// bin/hybriel tools/import.hl (default folder: import/tickets of the app — relative paths// resolve against THIS script's folder, hence '../import/tickets')// TICKETS_IMPORT_DIR=/some/dir TICKETS_URL=http://127.0.0.1:8350 bin/hybriel tools/import.hl//// WRITES NEED A TOKEN (ticket #7): TICKETS_TOKEN = an API token (log in with ident, /you →// "Create a token"); the imported tickets are opened by that token's user.//// A ticket file is `project:` and `subject:` header lines, a blank line, the summary// (hard-wrapped lines are joined into paragraphs, blank line = new paragraph —// lib/import.hl).// Each file is POSTed to /api/tickets with `source` = its file name; the app answers a// known source with the ticket it already has (200, existed) instead of a second one// (201), so running this twice imports nothing twice. Going through the API (not the// tables) means the running server stays the only writer and open browsers see the// imported tickets arrive live.import { listDir, readFile } from 'hl:fs'import { env } from 'hl:proc'import { fetch } from 'hl:fetch'import { parse } from '../lib/import.hl'static dir = env('TICKETS_IMPORT_DIR') != null ? env('TICKETS_IMPORT_DIR') : '../import/tickets'static base = env('TICKETS_URL') != null ? env('TICKETS_URL') : 'http://127.0.0.1:8350'static token = env('TICKETS_TOKEN') != null ? env('TICKETS_TOKEN') : ''if (token == '') { console.log('import: TICKETS_TOKEN is not set — API writes need a token (log in, /you → Create a token)') }// a > b for two strings (strings order by code point, hybriel#2; still no list sort())static after = (a, b) => { return a > b }// file names, sorted, so an empty store numbers each project's tickets in file ordernames = []for (n of listDir(dir)) {name = hlTypeName(n) == 'String' ? n : n.nameif (name.endsWith('.md')) { names.push(name) }}let i = 1while (i < names.length) {cur = names[i]let j = i - 1while (j >= 0 && after(names[j], cur)) {names[j + 1] = names[j]j = j - 1}names[j + 1] = curi = i + 1}created = 0existed = 0failed = 0for (name of names) {t = parse(readFile(dir + '/' + name))if (t.error != null) {console.log('SKIP ' + name + ': ' + t.error)failed = failed + 1} else {res = fetch(base + '/api/tickets', { method = 'POST' headers = { authorization = 'Bearer ' + token } json = { project = t.project subject = t.subject summary = t.summary source = name } })if (res.status == 201) {created = created + 1tk = res.json().ticketconsole.log('NEW ' + name + ' → ' + tk.project + ' ' + tk.ref)} else if (res.status == 200) {existed = existed + 1tk = res.json().ticketconsole.log('HAVE ' + name + ' = ' + tk.project + ' ' + tk.ref)} else {failed = failed + 1console.log('FAIL ' + name + ': ' + res.status + ' ' + res.text())}}}console.log('import: ' + created + ' new, ' + existed + ' already there, ' + failed + ' failed (' + dir + ' → ' + base + ')')
Branches
Latest commits
- 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
- 8542fc8aTickets conductor: T36 proof reviewedmre
- 35980936inbox: preserve desktop columns after list styles were scopedmre
- 2a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre
- c077a5cbstyles: format Style with nested language rulesmre
- ccdde2beticket: format Style with nested language rulesmre
- d083535bticket_list: nest Style rules and bare media queriesmre
- c24608ebmarkdown: format Style with nested language rulesmre
- de964b3bsettings: format Style with nested language rulesmre
- 03c1de05new_project: format Style with nested language rulesmre
- bd76cfa6connect: format Style with nested language rulesmre
- 01fad593inbox: format Style with nested language rulesmre