gitoria

kunibert

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2a44bd542a44bd54Runner CLI: --review-user/--codex-bin/--work-dir work in every modeKunibert2a44bd54/lib/gitcache.hl

2.9 KB

  1. $mode = 'static'
  2. import { run } from 'hl:proc'
  3. import { mkDir, writeFile, exists, remove, realPath, readFile } from 'hl:fs'
  4. import { toBase64 } from 'hl:crypto'
  5. import { require } from './review-output.hl'
  6. // ONE place for the remote ref names (gitoria will confirm them) and the limits.
  7. prHeadRemote = (Number n) => { return 'refs/pull/' + n + '/head' }
  8. prHeadLocal = (Number n) => { return 'refs/kunibert/pr/' + n }
  9. baseRemote = (String base) => { return 'refs/heads/' + base }
  10. baseLocal = (String base) => { return 'refs/kunibert/base/' + base }
  11. maxDiffBytes = 400000
  12. fetchTimeout = 120
  13. // Remote URL -> one URL-safe directory name.
  14. repoKey = (String url) => { return encodeURIComponent(url).replaceAll('%', '_').replaceAll('.', '_2e') }
  15. // The ONLY place that knows the token. It goes into the environment of the git child (http.extraHeader through
  16. // GIT_CONFIG_COUNT): never the repo config, the URL, argv or a log. Null token file -> no extra environment.
  17. authEnv = (String tokenFile) => {
  18. if (tokenFile == null) { return {} }
  19. token = readToken(tokenFile)
  20. return { GIT_CONFIG_COUNT = '1', GIT_CONFIG_KEY_0 = 'http.extraHeader', GIT_CONFIG_VALUE_0 = 'Authorization: Basic ' + toBase64('app:' + token), GIT_TERMINAL_PROMPT = '0' }
  21. }
  22. readToken = (String file) => {
  23. lines = readFile(file).split('\n')
  24. token = lines[0].trim()
  25. require(token != '', 'token file is empty')
  26. return token
  27. }
  28. gitIn = (String dir, Hybrid argv, Hybrid env = null, Number timeout = 30) => {
  29. r = run(['git'] + argv, { cwd = dir, env = env, timeout = timeout })
  30. require(r.exit == 0, 'git failed (' + r.exit + '): ' + r.stderr.join(' '))
  31. return r.lines
  32. }
  33. // Bare cache repo for a remote, created on first use.
  34. cacheRepo = (String data, String url) => {
  35. mkDir(data + '/git')
  36. path = realPath(data) + '/git/' + repoKey(url) + '.git'
  37. if (!exists(path + '/HEAD')) { gitIn(realPath(data) + '/git', ['init', '--bare', '--quiet', path]) }
  38. return path
  39. }
  40. // Fetch only the two refs of a job, forced, no tags.
  41. fetchRefs = (String cache, String url, Number pr, String base, String tokenFile) => {
  42. gitIn(cache, ['fetch', '--quiet', '--no-tags', '--force', url, '+' + prHeadRemote(pr) + ':' + prHeadLocal(pr), '+' + baseRemote(base) + ':' + baseLocal(base)], authEnv(tokenFile), fetchTimeout)
  43. }
  44. // Fresh detached worktree of a commit at <data>/work/<key>/<pr>. A leftover from a crashed run is removed first.
  45. worktreePath = (String data, String url, Number pr) => { return realPath(data) + '/work/' + repoKey(url) + '/' + pr }
  46. addWorktree = (String cache, String path, String sha) => {
  47. removeWorktree(cache, path)
  48. mkDir(path + '/..')
  49. gitIn(cache, ['worktree', 'add', '--detach', '--force', path, sha])
  50. }
  51. removeWorktree = (String cache, String path) => {
  52. if (exists(path)) { run(['git', 'worktree', 'remove', '--force', path], { cwd = cache, timeout = 30 }) }
  53. if (exists(path)) { run(['rm', '-rf', path], { timeout = 30 }) }
  54. run(['git', 'worktree', 'prune'], { cwd = cache, timeout = 30 })
  55. return !exists(path)
  56. }

Branches

Latest commits

  • 2a44bd54Runner CLI: --review-user/--codex-bin/--work-dir work in every modeKunibert
  • 2177f66fReview model runs as its own unix user (reviewUser, codexBin, workDir)Kunibert
  • 35df8306Records: live service on byrodin, real proof part 1Kunibert
  • 7480a98dkunibert.service: SIGTERM stop is a clean exitKunibert
  • 3a8d93f9gitoria client: parse only JSON answers, accept a plain-text errorKunibert
  • c9b48bfeVendor Hybriel plugins; deploy ships bin/ from zig-outKunibert
  • a41ba15fKunibert: event intake, git cache, review runner, posting, linked tickets, deploy filesKunibert