gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit01fad59301fad593inbox: format Style with nested language rulesmre01fad593/tools/import.hl

3.0 KB

  1. // tools/import.hl — import AntColony ticket files into the RUNNING app, over its JSON API.
  2. //
  3. // bin/hybriel tools/import.hl (default folder: import/tickets of the app — relative paths
  4. // resolve against THIS script's folder, hence '../import/tickets')
  5. // TICKETS_IMPORT_DIR=/some/dir TICKETS_URL=http://127.0.0.1:8350 bin/hybriel tools/import.hl
  6. //
  7. // WRITES NEED A TOKEN (ticket #7): TICKETS_TOKEN = an API token (log in with ident, /you →
  8. // "Create a token"); the imported tickets are opened by that token's user.
  9. //
  10. // A ticket file is `project:` and `subject:` header lines, a blank line, the summary
  11. // (hard-wrapped lines are joined into paragraphs, blank line = new paragraph —
  12. // lib/import.hl).
  13. // Each file is POSTed to /api/tickets with `source` = its file name; the app answers a
  14. // known source with the ticket it already has (200, existed) instead of a second one
  15. // (201), so running this twice imports nothing twice. Going through the API (not the
  16. // tables) means the running server stays the only writer and open browsers see the
  17. // imported tickets arrive live.
  18. import { listDir, readFile } from 'hl:fs'
  19. import { env } from 'hl:proc'
  20. import { fetch } from 'hl:fetch'
  21. import { parse } from '../lib/import.hl'
  22. static dir = env('TICKETS_IMPORT_DIR') != null ? env('TICKETS_IMPORT_DIR') : '../import/tickets'
  23. static base = env('TICKETS_URL') != null ? env('TICKETS_URL') : 'http://127.0.0.1:8350'
  24. static token = env('TICKETS_TOKEN') != null ? env('TICKETS_TOKEN') : ''
  25. if (token == '') { console.log('import: TICKETS_TOKEN is not set — API writes need a token (log in, /you → Create a token)') }
  26. // a > b for two strings (strings order by code point, hybriel#2; still no list sort())
  27. static after = (a, b) => { return a > b }
  28. // file names, sorted, so an empty store numbers each project's tickets in file order
  29. names = []
  30. for (n of listDir(dir)) {
  31. name = hlTypeName(n) == 'String' ? n : n.name
  32. if (name.endsWith('.md')) { names.push(name) }
  33. }
  34. let i = 1
  35. while (i < names.length) {
  36. cur = names[i]
  37. let j = i - 1
  38. while (j >= 0 && after(names[j], cur)) {
  39. names[j + 1] = names[j]
  40. j = j - 1
  41. }
  42. names[j + 1] = cur
  43. i = i + 1
  44. }
  45. created = 0
  46. existed = 0
  47. failed = 0
  48. for (name of names) {
  49. t = parse(readFile(dir + '/' + name))
  50. if (t.error != null) {
  51. console.log('SKIP ' + name + ': ' + t.error)
  52. failed = failed + 1
  53. } else {
  54. res = fetch(base + '/api/tickets', { method = 'POST' headers = { authorization = 'Bearer ' + token } json = { project = t.project subject = t.subject summary = t.summary source = name } })
  55. if (res.status == 201) {
  56. created = created + 1
  57. tk = res.json().ticket
  58. console.log('NEW ' + name + ' → ' + tk.project + ' ' + tk.ref)
  59. } else if (res.status == 200) {
  60. existed = existed + 1
  61. tk = res.json().ticket
  62. console.log('HAVE ' + name + ' = ' + tk.project + ' ' + tk.ref)
  63. } else {
  64. failed = failed + 1
  65. console.log('FAIL ' + name + ': ' + res.status + ' ' + res.text())
  66. }
  67. }
  68. }
  69. console.log('import: ' + created + ' new, ' + existed + ' already there, ' + failed + ' failed (' + dir + ' → ' + base + ')')

Branches

Latest commits

  • 01fad593inbox: format Style with nested language rulesmre
  • 79dc9392you: format Style with nested language rulesmre
  • 78073baamain: format Style with nested language rulesmre
  • 5499c290Sync theme unchanged from layouts 17e0f03mre
  • fd33ee21Sync reviewed components from 8176eb1mre
  • 93348453Re-vendor tickets to Hybriel set day35mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre
  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre