gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9af8e7809af8e780|||PR Use keyed list mutations for live ticket updatesmre9af8e780/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

  • 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
  • 6dea1c60Merge branch 'r35-day72' into mainTickets
  • 7bcfdc22|||PR drop worker edits to conductor recordsmre
  • 2617b6ee|||PR dialogs: host flag cleared on close, dialog gate (tickets#40)mre
  • 6e701371|||PR record partial day72 dialog validationmre
  • b9fb9a91|||PR bind ticket dialog visibility to member flagsmre