gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3a8b2fb83a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre3a8b2fb8/lib/approvals.hl

2.2 KB

  1. // Person approvals: @id records, indexed by repository id + PR number.
  2. // All writes and the one-time backfill of pre-index rows belong here.
  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 = ['pullKey'])
  8. static indexed = false
  9. static indexOldApprovals = () => {
  10. if (indexed) { return true }
  11. rows = approvalsTable.find(null, null)
  12. if (countOfList(rows) > 0) {
  13. for (r of rows) {
  14. if (r.pullKey == null) {
  15. changed = approvalsTable.update(r.id, { rid = r.rid number = r.number userId = r.userId head = r.head created = r.created pullKey = r.rid + '#' + r.number })
  16. if (changed != 1) { hlError('could not index the earlier approvals') }
  17. }
  18. }
  19. }
  20. indexed = true
  21. return true
  22. }
  23. static approvalsOf = (String rid, Number number) => {
  24. indexOldApprovals()
  25. rows = approvalsTable.find('pullKey', rid + '#' + number)
  26. return countOfList(rows) == 0 ? [] : rows
  27. }
  28. static approvalsJson = (Hybrid rows, String head) => {
  29. out = []
  30. for (r of rows) {
  31. current = r.head == head
  32. out.push({ user = { id = r.userId name = nameOfUser(r.userId) } head = r.head created = timestamp(r.created) current = current })
  33. }
  34. return out
  35. }
  36. static hasApproval = (Hybrid rows, String userId, String head) => {
  37. for (r of rows) { if (r.userId == userId && r.head == head) { return true } }
  38. return false
  39. }
  40. static setApproval = (String rid, Number number, String userId, String head, Boolean wanted) => {
  41. rows = approvalsOf(rid, number)
  42. if (!wanted) {
  43. for (r of rows) {
  44. if (r.userId == userId && r.head == head) {
  45. deleted = approvalsTable.delete(r.id)
  46. if (deleted != 1 || approvalsTable.fetch(r.id) != null) { return { error = 'could not withdraw the approval' } }
  47. }
  48. }
  49. if (hasApproval(approvalsOf(rid, number), userId, head)) { return { error = 'could not withdraw the approval' } }
  50. return { ok = true }
  51. }
  52. if (hasApproval(rows, userId, head)) { return { ok = true } }
  53. id = approvalsTable.put({ rid = rid number = number userId = userId head = head created = now() pullKey = rid + '#' + number })
  54. return id == null ? { error = 'could not store the approval' } : { ok = true }
  55. }

Branches

Latest commits

  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 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