gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3ae94b863ae94b86Record browser failures and verify owned tab cleanupmre3ae94b86/lib/approvals.hl

1.6 KB

  1. // Person approvals, keyed by record id and scoped to repository, PR number and head.
  2. // Every write to approvals.db is here; callers re-check the real session's push rights.
  3. import { MPackDB } from 'hl:mpackdb'
  4. import { now, timestamp } from 'hl:time'
  5. import { storageDir, countOfList } from './util.hl'
  6. import { nameOfUser } from './users.hl'
  7. static approvalsTable = new MPackDB(file = storageDir + '/approvals.db', primaryKey = '@id', indexes = ['rid'])
  8. static approvalsOf = (String rid, Number number) => {
  9. out = []
  10. rows = approvalsTable.find('rid', rid)
  11. if (countOfList(rows) > 0) { for (r of rows) { if (r.number == number) { out.push(r) } } }
  12. return out
  13. }
  14. static approvalsJson = (String rid, Number number, String head) => {
  15. out = []
  16. for (r of approvalsOf(rid, number)) {
  17. current = r.head == head
  18. out.push({ user = { id = r.userId name = nameOfUser(r.userId) } head = r.head created = timestamp(r.created) current = current })
  19. }
  20. return out
  21. }
  22. static hasApproval = (String rid, Number number, String userId, String head) => {
  23. for (r of approvalsOf(rid, number)) { if (r.userId == userId && r.head == head) { return true } }
  24. return false
  25. }
  26. static setApproval = (String rid, Number number, String userId, String head, Boolean wanted) => {
  27. if (!wanted) {
  28. for (r of approvalsOf(rid, number)) { if (r.userId == userId && r.head == head) { approvalsTable.delete(r.id) } }
  29. return { ok = true }
  30. }
  31. if (hasApproval(rid, number, userId, head)) { return { ok = true } }
  32. id = approvalsTable.put({ rid = rid number = number userId = userId head = head created = now() })
  33. return id == null ? { error = 'could not store the approval' } : { ok = true }
  34. }

Branches

Latest commits

  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre
  • 55c84779Merge branch 'gp-gate-ports' into mainGitoria
  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria
  • 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
  • 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
  • 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria
  • 698458e2|||PR No session for cookieless login errors: READMEmre
  • cce7b785|||PR No session for cookieless login errorsmre
  • 678d6303Merge branch 'v59' into mainGitoria
  • 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria