gitoria
All repositories: gitoria
2.2 KB
// Person approvals: @id records, indexed by repository id + PR number.// All writes and the one-time backfill of pre-index rows belong here.import { MPackDB } from 'hl:mpackdb'import { now, timestamp } from 'hl:time'import { storageDir, countOfList } from './util.hl'import { nameOfUser } from './users.hl'static approvalsTable = new MPackDB(file = storageDir + '/approvals.db', primaryKey = '@id', indexes = ['pullKey'])static indexed = falsestatic indexOldApprovals = () => {if (indexed) { return true }rows = approvalsTable.find(null, null)if (countOfList(rows) > 0) {for (r of rows) {if (r.pullKey == null) {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 })if (changed != 1) { hlError('could not index the earlier approvals') }}}}indexed = truereturn true}static approvalsOf = (String rid, Number number) => {indexOldApprovals()rows = approvalsTable.find('pullKey', rid + '#' + number)return countOfList(rows) == 0 ? [] : rows}static approvalsJson = (Hybrid rows, String head) => {out = []for (r of rows) {current = r.head == headout.push({ user = { id = r.userId name = nameOfUser(r.userId) } head = r.head created = timestamp(r.created) current = current })}return out}static hasApproval = (Hybrid rows, String userId, String head) => {for (r of rows) { if (r.userId == userId && r.head == head) { return true } }return false}static setApproval = (String rid, Number number, String userId, String head, Boolean wanted) => {rows = approvalsOf(rid, number)if (!wanted) {for (r of rows) {if (r.userId == userId && r.head == head) {deleted = approvalsTable.delete(r.id)if (deleted != 1 || approvalsTable.fetch(r.id) != null) { return { error = 'could not withdraw the approval' } }}}if (hasApproval(approvalsOf(rid, number), userId, head)) { return { error = 'could not withdraw the approval' } }return { ok = true }}if (hasApproval(rows, userId, head)) { return { ok = true } }id = approvalsTable.put({ rid = rid number = number userId = userId head = head created = now() pullKey = rid + '#' + number })return id == null ? { error = 'could not store the approval' } : { ok = true }}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
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