gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6e03be0a6e03be0apull state: keep the resync marker until the sync ran (#56)mre6e03be0a/lib/pullsync.hl

21.4 KB

  1. // lib/pullsync.hl — PULL REQUEST RECORDS (gitoria#40, part of the push API #38; contract docs/apps-api.md §3, §4).
  2. // A pull request is still a commit whose subject starts `|||PR` (git-helpers.hl parsePull), but now it is also STORED, so it has
  3. // a number that never changes and is never reused. Two tables, both keyed by the repo's ID (never the slug: a repo can be renamed):
  4. // pullRecs pk @id index !key, !shaKey, repo { rid (the repo's @id), number, key "<repo>#<n>", shaKey "<repo> <sha>", sha (the |||PR commit), source,
  5. // target, implicit (the target is the repo's main branch), state open|closed|merged, head, authorId, authorName,
  6. // heads (every head the PR has had, oldest first: an app may review an earlier one), createdMs, updatedMs } storage/mpackdb/pullrecs.db
  7. // pullInit pk @id index !repo { rid } a repo whose PRs were numbered once (the numbers of the old ones, oldest first)
  8. // ensurePulls(slug) numbers the PRs a repo already has, once, without changes (before the first push / page view)
  9. // syncPulls(slug, userId) compares git with the records → the CHANGES (opened|reopened|synchronize|closed|merged), each with the
  10. // ref refs/pull/<n>/head already pointing at the new head; logChange writes them (until gitoria#43 sends events)
  11. // pullObject(slug, n) the contract's `pull` JSON; withNumbers(list, slug) puts "#N" on the rows of /pulls.
  12. // A record is found again by the sha of its |||PR commit (that is what identifies a PR to git); its source branch may be renamed.
  13. // Merged is final. Nothing here throws: a failed git call skips that PR until the next sync.
  14. import { syncAndRaise } from './events.hl'
  15. import { MPackDB } from 'hl:mpackdb'
  16. import { now, timestamp } from 'hl:time'
  17. import { appendFile, mkDir, exists, readFile, listDir } from 'hl:fs'
  18. import { run } from 'hl:proc'
  19. import { randomBytes } from 'hl:crypto'
  20. import { NL, storageDir, countOfList, firstOf, repoOrigin, px } from './util.hl'
  21. import { repoBySlug } from './repos.hl'
  22. import { nameOfUser } from './users.hl'
  23. import { gitRaw, pickDefault } from './git.hl'
  24. import { tabs, isHexId, safeName, parsePull } from './git-helpers.hl'
  25. import { bodyOfLines, ticketNames } from './pullsync-helpers.hl'
  26. import { approvalsOf } from './approvals.hl'
  27. import { approvalsJson } from './approvals-helpers.hl'
  28. import { statusesOf, statusJson, requiredOf, approversOf } from './statuses.hl'
  29. static pullRecs = new MPackDB(file = storageDir + '/pullrecs.db', primaryKey = '@id', indexes = ['!key', '!shaKey', 'rid'])
  30. static pullInit = new MPackDB(file = storageDir + '/pullinit.db', primaryKey = '@id', indexes = ['!rid'])
  31. static changeLog = storageDir + '/pull-changes.log'
  32. static maxNew = 50
  33. static scan = 500
  34. static zeroId = '0000000000000000000000000000000000000000'
  35. // Atomic mkdir owns a PR's read/replace section across containers.
  36. // A short flock guard serializes lease creation, expiry and release, including owner-file setup.
  37. // The directory expires after a minute if a worker dies; the token prevents an old release removing a new lease.
  38. static pullClaimDir = storageDir + '/pull-claims'
  39. static claimPull = (String id) => {
  40. mkDir(pullClaimDir, 448)
  41. path = pullClaimDir + '/' + id
  42. token = randomBytes(12, 'hex')
  43. script = 'if [ -d "$1" ] && [ -n "$(find "$1" -maxdepth 0 -mmin +1 -print)" ]; then rm -f "$1/owner"; rmdir "$1" || exit 1; fi
  44. mkdir "$1" 2>/dev/null || exit 1
  45. printf "%s" "$2" > "$1/owner"'
  46. r = run(['flock', pullClaimDir + '/guard', 'sh', '-c', script, 'sh', path, token], { timeout = 5 })
  47. return r != null && r.exit == 0 ? { path = path token = token } : null
  48. }
  49. static releasePull = (Hybrid claim) => {
  50. script = 'if [ "$(cat "$1/owner" 2>/dev/null)" = "$2" ]; then rm -f "$1/owner"; rmdir "$1"; fi'
  51. run(['flock', pullClaimDir + '/guard', 'sh', '-c', script, 'sh', claim.path, claim.token], { timeout = 5 })
  52. return null
  53. }
  54. // Like pullInit, this is a per-repo marker; directories make it visible to both containers.
  55. // Consume by rename before syncing, so another busy write can leave a new marker safely.
  56. static resyncDir = storageDir + '/pull-resync'
  57. static resyncing = {}
  58. static markPullResync = (Hybrid repo, String userId) => {
  59. mkDir(resyncDir, 448)
  60. mkDir(pullClaimDir, 448)
  61. script = 'if mkdir "$1" 2>/dev/null; then printf "%s" "$2" > "$1/request"; fi'
  62. run(['flock', pullClaimDir + '/guard', 'sh', '-c', script, 'sh', resyncDir + '/' + repo.id, JSON.stringify({ userId = userId })])
  63. return null
  64. }
  65. static resumePullResync = (String slug) => {
  66. repo = repoBySlug(slug)
  67. if (repo == null || resyncing[repo.id] == true) { return null }
  68. path = resyncDir + '/' + repo.id
  69. if (!exists(resyncDir)) { return null }
  70. let pending = exists(path)
  71. if (!pending) {
  72. for (entry of listDir(resyncDir)) {
  73. if (entry.name.startsWith(repo.id + '.')) { pending = true }
  74. }
  75. }
  76. if (!pending) { return null }
  77. resyncing[repo.id] = true
  78. taken = path + '.' + randomBytes(12, 'hex')
  79. script = 'if [ -d "$1" ]; then mv "$1" "$2" && touch "$2"; exit $?; fi
  80. for old in "$1".*; do
  81. if [ -d "$old" ] && [ -n "$(find "$old" -maxdepth 0 -mmin +2 -print)" ]; then mv "$old" "$2" && touch "$2"; exit $?; fi
  82. done
  83. exit 1'
  84. r = run(['flock', pullClaimDir + '/guard', 'sh', '-c', script, 'sh', path, taken])
  85. if (r != null && r.exit == 0) {
  86. request = JSON.tryParse(readFile(taken + '/request'))
  87. syncAndRaise(slug, request == null ? null : request.userId)
  88. run(['rm', '-r', taken])
  89. }
  90. delete resyncing[repo.id]
  91. return null
  92. }
  93. // ---- small git answers -------------------------------------------------------------------------------------
  94. // the first line of a git call's output, or '' (failed, nothing, or not a plain id when `hexOnly`)
  95. static firstLine = (slug, args) => {
  96. r = gitRaw(slug, args)
  97. if (r == null || r.exit != 0 || r.lines.length == 0) { return '' }
  98. return r.lines[0]
  99. }
  100. static isAncestor = (slug, a, b) => {
  101. if (a == null || b == null || a == '' || b == '') { return false }
  102. r = gitRaw(slug, ['merge-base', '--is-ancestor', a, b])
  103. return r != null && r.exit == 0
  104. }
  105. // { name: tip sha } of every branch, and the names in order
  106. static branchTips = (slug) => {
  107. tips = {}
  108. names = []
  109. r = gitRaw(slug, ['for-each-ref', '--format=%(refname:short)%09%(objectname)', 'refs/heads'])
  110. if (r != null && r.exit == 0) {
  111. for (l of r.lines) {
  112. f = tabs(l)
  113. if (f.length == 2 && safeName(f[0]) && isHexId(f[1])) {
  114. tips[f[0]] = f[1]
  115. names.push(f[0])
  116. }
  117. }
  118. }
  119. return { tips = tips names = names ok = r != null && r.exit == 0 }
  120. }
  121. // The recorded source wins while it contains the marker. Without one, prefer the known head's
  122. // branch before another branch that merely contains the marker (for example a later PR).
  123. static sourceOf = (String slug, String sha, String target, String preferred, String head) => {
  124. return sourceResult(slug, sha, target, preferred, head).source
  125. }
  126. // The list cache also needs to know whether EVERY git read succeeded. Keep sourceOf's string contract.
  127. static sourceResult = (String slug, String sha, String target, String preferred, String head) => {
  128. r = gitRaw(slug, ['for-each-ref', '--contains', sha, '--format=%(refname:short)%09%(objectname)', 'refs/heads'])
  129. if (r == null || r.exit != 0) { return { source = '' ok = false } }
  130. candidates = []
  131. for (l of r.lines) {
  132. f = tabs(l)
  133. if (f.length == 2 && safeName(f[0]) && f[0] != target && isHexId(f[1])) {
  134. if (f[0] == preferred) { return { source = f[0] ok = true } }
  135. candidates.push({ name = f[0] tip = f[1] })
  136. }
  137. }
  138. knownHead = head == null || head == '' ? sha : head
  139. for (c of candidates) { if (c.tip == knownHead) { return { source = c.name ok = true } } }
  140. let complete = true
  141. for (c of candidates) {
  142. ancestor = gitRaw(slug, ['merge-base', '--is-ancestor', knownHead, c.tip])
  143. if (ancestor == null || (ancestor.exit != 0 && ancestor.exit != 1)) { complete = false }
  144. if (ancestor != null && ancestor.exit == 0) { return { source = c.name ok = complete } }
  145. }
  146. return { source = candidates.length > 0 ? candidates[0].name : '' ok = complete }
  147. }
  148. // the commit that put the PR into the target: the first one on the target's first-parent line that has the PR commit as an ancestor
  149. // (the merge commit of the Merge button; a fast-forward's commit itself); the target's tip when git cannot say
  150. static mergeCommitOf = (slug, sha, targetTip) => {
  151. r = gitRaw(slug, ['rev-list', '--first-parent', '--ancestry-path', '--reverse', sha + '..' + targetTip])
  152. if (r != null && r.exit == 0 && r.lines.length > 0 && isHexId(r.lines[0])) { return r.lines[0] }
  153. return targetTip
  154. }
  155. // ---- the refs/pull/N/head ref (and refs/pull/N/heads/<sha> for every head it ever had) ----------------------------------------------------------------------------
  156. // point it at `head`, with the old value given (a ref that is not there must not be there). → true when it points there afterwards
  157. static setPullRef = (slug, n, head) => {
  158. ref = 'refs/pull/' + n + '/head'
  159. cur = firstLine(slug, ['rev-parse', '--verify', '-q', ref])
  160. if (cur == head) { return true }
  161. r = gitRaw(slug, ['update-ref', '-m', 'pull request ' + n, ref, head, cur == '' ? zeroId : cur])
  162. if (r == null || r.exit != 0) { return false }
  163. // every head stays referenced (refs/pull/N/heads/<sha>, hidden like the rest of refs/pull): an app may review an earlier head, git gc must not drop it
  164. gitRaw(slug, ['update-ref', '-m', 'pull request ' + n + ' head', 'refs/pull/' + n + '/heads/' + head, head])
  165. return true
  166. }
  167. // ---- the records -------------------------------------------------------------------------------------------
  168. static recordsOf = (repoId) => {
  169. all = pullRecs.find('rid', repoId)
  170. return countOfList(all) == 0 ? [] : all
  171. }
  172. static recordBySha = (repoId, sha) => { return firstOf(pullRecs.find('shaKey', repoId + ' ' + sha)) }
  173. static recordByNumber = (repoId, n) => { return firstOf(pullRecs.find('key', repoId + '#' + n)) }
  174. // the next number: one more than the highest (records are never removed, so a number is never used twice)
  175. static nextNumber = (repoId) => {
  176. let top = 0
  177. for (r of recordsOf(repoId)) { if (r.number > top) { top = r.number } }
  178. return top + 1
  179. }
  180. // every head the record has had (a list of shas); the current one is always in it
  181. static headsOf = (rec) => {
  182. out = []
  183. if (rec.heads != null && countOfList(rec.heads) > 0) { for (h of rec.heads) { out.push(h) } }
  184. if (rec.head != null && !out.includes(rec.head)) { out.push(rec.head) }
  185. return out
  186. }
  187. static withHead = (rec, head) => {
  188. out = headsOf(rec)
  189. if (!out.includes(head)) { out.push(head) }
  190. return out
  191. }
  192. // was this sha ever a head of pull request N of the repo? (gitoria#44: a review of an earlier head is fine, only a sha that never was one is stale)
  193. static wasHeadOf = (slug, n, sha) => {
  194. repo = repoBySlug(slug)
  195. if (repo == null || n == null || sha == null || hlTypeName(sha) != 'String') { return false }
  196. rec = recordByNumber(repo.id, n)
  197. return rec != null && headsOf(rec).includes(sha)
  198. }
  199. static isInitialized = (repoId) => { return firstOf(pullInit.find('rid', repoId)) != null }
  200. static changeOf = (rec, action, before, after, forced, mergeCommit, pusherId) => {
  201. let sender = null
  202. if (pusherId != null) { sender = { id = pusherId name = nameOfUser(pusherId) } }
  203. return { number = rec.number action = action before = before after = after forced = forced mergeCommit = mergeCommit sender = sender }
  204. }
  205. // the commits of the repo that start a pull request, oldest first, not yet stored: [{ sha, ct, author, parsed }]
  206. static newCandidates = (slug, repoId) => {
  207. out = []
  208. lg = gitRaw(slug, ['log', '-' + scan, '--branches', '--format=%H%x09%ct%x09%an%x09%s'])
  209. if (lg == null || lg.exit != 0) { return out }
  210. for (l of lg.lines) {
  211. f = tabs(l)
  212. if (f.length >= 4 && isHexId(f[0]) && f[0].length == 40) {
  213. pr = parsePull(f.slice(3).join(' '))
  214. if (pr != null && out.length < maxNew && recordBySha(repoId, f[0]) == null) {
  215. out.push({ sha = f[0] ct = toNumber(f[1]) * 1000 author = f[2] parsed = pr })
  216. }
  217. }
  218. }
  219. // commit time, oldest first (an insertion sort: no sort(), hybriel #1)
  220. let i = 1
  221. while (i < out.length) {
  222. cur = out[i]
  223. let j = i - 1
  224. while (j >= 0 && out[j].ct > cur.ct) {
  225. out[j + 1] = out[j]
  226. j = j - 1
  227. }
  228. out[j + 1] = cur
  229. i = i + 1
  230. }
  231. return out
  232. }
  233. // the whole comparison. quiet = number the existing PRs and return no changes (ensurePulls). → the changes (a list)
  234. static syncNow = (slug, pusherId, quiet) => {
  235. changes = []
  236. repo = repoBySlug(slug)
  237. if (repo == null) { return changes }
  238. bt = branchTips(slug)
  239. if (!bt.ok) { if (resyncing[repo.id] == true) { markPullResync(repo, pusherId) } return changes }
  240. dflt = pickDefault(bt.names, repo.branch)
  241. stamp = now()
  242. // 1. the PRs we know
  243. for (rec of recordsOf(repo.id)) {
  244. if (rec.state != 'merged') {
  245. target = rec.implicit == true && dflt != null ? dflt : rec.target
  246. targetTip = bt.tips[target]
  247. let source = rec.source
  248. let tip = source != '' ? bt.tips[source] : null
  249. let onBranch = tip != null && isAncestor(slug, rec.sha, tip)
  250. if (!onBranch) {
  251. // the commit may sit on another branch now (the branch was renamed)
  252. other = sourceOf(slug, rec.sha, target, rec.source, rec.head)
  253. if (other != '' && bt.tips[other] != null) {
  254. source = other
  255. tip = bt.tips[other]
  256. onBranch = true
  257. }
  258. }
  259. u = rec
  260. u.target = target
  261. u.source = source
  262. let action = ''
  263. let before = rec.head
  264. let after = rec.head
  265. let forced = false
  266. let mergeCommit = null
  267. if (targetTip != null && isAncestor(slug, rec.sha, targetTip)) {
  268. action = 'merged'
  269. u.state = 'merged'
  270. if (onBranch) { after = tip }
  271. mergeCommit = mergeCommitOf(slug, rec.sha, targetTip)
  272. } else if (onBranch && rec.state == 'closed' && rec.manualClosedBy == null) {
  273. action = 'reopened'
  274. u.state = 'open'
  275. after = tip
  276. } else if (onBranch && tip != rec.head) {
  277. action = 'synchronize'
  278. after = tip
  279. forced = !isAncestor(slug, rec.head, tip)
  280. } else if (!onBranch && rec.state == 'open') {
  281. action = 'closed'
  282. u.state = 'closed'
  283. }
  284. u.head = after
  285. u.heads = withHead(rec, after)
  286. if (action != '' || source != rec.source || target != rec.target) {
  287. // the ref first: an event is only sent for a head that can be fetched
  288. if (action == '' || setPullRef(slug, rec.number, after)) {
  289. // Git calls yield: another request/container may have closed or reopened this PR.
  290. // Read after the final git call, immediately before replacing the row.
  291. let claim = claimPull(rec.id)
  292. let tries = 0
  293. while (claim == null && tries < 10) {
  294. run(['sleep', '0.3'])
  295. tries = tries + 1
  296. claim = claimPull(rec.id)
  297. }
  298. if (claim == null) {
  299. console.log('pull-sync busy ' + slug + '#' + rec.number + ': queued for resync')
  300. markPullResync(repo, pusherId)
  301. continue
  302. }
  303. latest = pullRecs.fetch(rec.id)
  304. if (latest == null || latest.state == 'merged') { releasePull(claim) continue }
  305. u.manualClosedBy = latest.manualClosedBy
  306. u.manualClosedMs = latest.manualClosedMs
  307. if (u.state != 'merged' && latest.manualClosedBy != null) {
  308. u.state = 'closed'
  309. if (action == 'reopened') { action = '' }
  310. } else if (u.state != 'merged' && onBranch && rec.manualClosedBy != null && latest.manualClosedBy == null) {
  311. u.state = latest.state
  312. }
  313. u.heads = withHead(latest, after)
  314. u.updatedMs = stamp
  315. pullRecs.update(rec.id, u)
  316. releasePull(claim)
  317. if (action != '' && !quiet) { changes.push(changeOf(u, action, before, after, forced, mergeCommit, pusherId)) }
  318. }
  319. }
  320. }
  321. }
  322. // 2. the PRs we have not seen, oldest first (numbers follow the commit time)
  323. for (c of newCandidates(slug, repo.id)) {
  324. target = c.parsed.target == '' ? dflt : c.parsed.target
  325. targetTip = bt.tips[target]
  326. source = sourceOf(slug, c.sha, target)
  327. merged = targetTip != null && isAncestor(slug, c.sha, targetTip)
  328. if (merged || (source != '' && bt.tips[source] != null)) {
  329. head = !merged && source != '' ? bt.tips[source] : c.sha
  330. n = nextNumber(repo.id)
  331. author = quiet || pusherId == null ? null : pusherId
  332. rec = { rid = repo.id number = n key = repo.id + '#' + n shaKey = repo.id + ' ' + c.sha sha = c.sha source = source target = target implicit = c.parsed.target == '' state = merged ? 'merged' : 'open' head = head heads = [head] authorId = author authorName = author != null ? nameOfUser(author) : c.author createdMs = quiet ? c.ct : stamp updatedMs = quiet ? c.ct : stamp }
  333. if (setPullRef(slug, n, head)) {
  334. id = pullRecs.put(rec)
  335. if (id != null && !quiet) {
  336. saved = pullRecs.fetch(id)
  337. changes.push(changeOf(saved, merged ? 'merged' : 'opened', null, head, false, merged ? mergeCommitOf(slug, c.sha, targetTip) : null, pusherId))
  338. }
  339. }
  340. }
  341. }
  342. return changes
  343. }
  344. // number the PRs a repo already has, ONCE (quiet); call it before a push is taken and when /pulls is built
  345. static ensurePulls = (slug) => {
  346. repo = repoBySlug(slug)
  347. if (repo == null || isInitialized(repo.id)) { return null }
  348. syncNow(slug, null, true)
  349. // an empty repo (no branch yet) has nothing to number and is initialized too: its first PR is a live one
  350. pullInit.put({ rid = repo.id })
  351. return null
  352. }
  353. // THE ENTRY: compare git with the records. Never fails the caller: whatever goes wrong yields the changes found so far (none).
  354. // userId = the gitoria user who pushed or merged (null when unknown). Every change is logged (logChange) and returned.
  355. static syncPulls = (slug, userId) => {
  356. ensurePulls(slug)
  357. changes = syncNow(slug, userId, false)
  358. for (c of changes) { logChange(slug, c) }
  359. return changes
  360. }
  361. // All writes to pull records stay in this topic file. Callers check mayPush first.
  362. static setManualPull = (String userId, String slug, Number number, Boolean closed) => {
  363. repo = repoBySlug(slug)
  364. ensurePulls(slug)
  365. found = repo == null ? null : recordByNumber(repo.id, number)
  366. if (found == null) { return { error = 'no such pull request' code = 404 } }
  367. claim = claimPull(found.id)
  368. if (claim == null) { return { error = 'this pull request is being updated; try again' code = 409 reason = 'busy' } }
  369. result = writeManualPull(userId, slug, found.id, closed)
  370. releasePull(claim)
  371. return result
  372. }
  373. // Only called while holding this PR's claim; no git calls between the fresh read and replacement.
  374. static writeManualPull = (String userId, String slug, String id, Boolean closed) => {
  375. rec = pullRecs.fetch(id)
  376. if (rec == null) { return { error = 'no such pull request' code = 404 } }
  377. if (rec.state == 'merged') { return { error = 'this pull request is already merged' code = 409 reason = 'already_merged' } }
  378. if ((closed && rec.state != 'open') || (!closed && (rec.state != 'closed' || rec.manualClosedBy == null))) {
  379. return { error = 'this pull request cannot change to that state' code = 409 reason = 'invalid_state' }
  380. }
  381. u = rec
  382. u.state = closed ? 'closed' : 'open'
  383. u.manualClosedBy = closed ? userId : null
  384. u.manualClosedMs = closed ? now() : null
  385. u.updatedMs = now()
  386. pullRecs.update(rec.id, u)
  387. change = changeOf(u, closed ? 'closed' : 'reopened', rec.head, rec.head, false, null, userId)
  388. logChange(slug, change)
  389. return { ok = true change = change }
  390. }
  391. // the change log until gitoria#43 sends events: one JSON line in storage/pull-changes.log (and the console)
  392. static logChange = (slug, c) => {
  393. repo = repoBySlug(slug)
  394. line = JSON.stringify({ time = timestamp(now()) repoId = repo != null ? repo.id : null slug = slug number = c.number action = c.action before = c.before after = c.after forced = c.forced mergeCommit = c.mergeCommit sender = c.sender })
  395. appendFile(changeLog, line + NL, 384)
  396. console.log('pull-change ' + line)
  397. return null
  398. }
  399. // ---- the contract's `pull` object (§4) --------------------------------------------------------------------
  400. static pullObject = (String slug, Number n, Hybrid approvalRows = null) => {
  401. repo = repoBySlug(slug)
  402. if (repo == null || n == null) { return null }
  403. rec = recordByNumber(repo.id, n)
  404. if (rec == null) { return null }
  405. msg = gitRaw(slug, ['log', '-1', '--format=%B', rec.sha])
  406. lines = msg != null && msg.exit == 0 ? msg.lines : []
  407. pr = lines.length > 0 ? parsePull(lines[0]) : null
  408. title = pr != null && pr.title != '' ? pr.title : (rec.source != '' ? rec.source : rec.sha.slice(0, 8))
  409. body = bodyOfLines(lines)
  410. baseTip = firstLine(slug, ['rev-parse', '--verify', '-q', 'refs/heads/' + rec.target])
  411. mergeBase = baseTip != '' ? firstLine(slug, ['merge-base', baseTip, rec.head]) : ''
  412. project = repo.tktProject != null ? repo.tktProject : ''
  413. statuses = []
  414. for (r of statusesOf(repo.id, rec.head)) { statuses.push(statusJson(r)) }
  415. return {
  416. number = rec.number
  417. title = title
  418. body = body
  419. draft = false
  420. state = rec.state
  421. author = { id = rec.authorId name = rec.authorName }
  422. source = rec.source
  423. target = rec.target
  424. head = rec.head
  425. ref = 'refs/pull/' + rec.number + '/head'
  426. baseRef = 'refs/heads/' + rec.target
  427. base = baseTip != '' ? baseTip : null
  428. mergeBase = mergeBase != '' ? mergeBase : null
  429. tickets = ticketNames(title + NL + body, project)
  430. url = repoOrigin(slug) + '/pulls/' + rec.number
  431. created = timestamp(rec.createdMs)
  432. updated = timestamp(rec.updatedMs)
  433. statuses = statuses
  434. required = requiredOf(repo.id)
  435. approvers = approversOf(repo.id)
  436. approvals = approvalsJson(approvalRows == null ? approvalsOf(repo.id, rec.number) : approvalRows, rec.head)
  437. }
  438. }
  439. // the rows of /pulls with their number: `number` (0 = not stored) and `numberText` ("#3")
  440. static withNumbers = (list, slug) => {
  441. out = []
  442. repo = repoBySlug(slug)
  443. for (p of list) {
  444. q = p
  445. rec = repo != null ? recordBySha(repo.id, p.sha) : null
  446. q.number = rec != null ? rec.number : 0
  447. q.numberText = rec != null ? '#' + rec.number : ''
  448. q.pageHref = rec != null ? px(slug) + '/pulls/' + rec.number : p.href
  449. out.push(q)
  450. }
  451. return out
  452. }

Branches

Latest commits

  • 6e03be0apull state: keep the resync marker until the sync ran (#56)mre
  • 93bdd26cpull state: wait for a claimed row, resync when it stays busy (#56)mre
  • e53d284bpull state: stop on a failed branch scan, claim the row on writes (#56)mre
  • d8608224close and reopen: keep a manual close against sync (#56)mre
  • ffb60746|||PR close and reopen pull requests (#56)mre
  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria