gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb05f6d92b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmreb05f6d92/lib/prpage.hl

9.0 KB

  1. // lib/prpage.hl — THE PULL REQUEST PAGE (gitoria#45, part of the push API #38): what /pulls/N shows and what a person can do there.
  2. // Reads (all keyed by the repo's id and the PR number, never a list position): the PR, its statuses on the current head, every app's current verdict,
  3. // the reviews, the threads and the conversation (tables: lib/reviews.hl). Writes (a person's comment, reply, resolve / reopen, "Review again") store through
  4. // lib/reviews.hl and raise the contract's events (§4) through lib/events.hl: pull_comment → every app, review_comment / review_thread / review_requested → THAT app only.
  5. // WHO MAY WRITE is ONE helper, mayWritePull: signed in AND owner or member of the repo (the people who may push). Everybody else reads.
  6. // Bodies are Markdown shown as TEXT NODES (lib/markdown.hl blocks, components/markdown.hl): no raw HTML anywhere.
  7. import { slugOfRequest } from './orgs.hl'
  8. import { repoBySlug, repoAt, mayPush } from './repos.hl'
  9. import { userOfSession } from './users.hl'
  10. import { ensurePulls, pullObject, recordByNumber } from './pullsync.hl'
  11. import { appsTable, appsOfRepo } from './apps-table.hl'
  12. import { statusesOf, badgeOf } from './statuses.hl'
  13. import { refParts } from './tickets-helpers.hl'
  14. import { markdownBlocks } from './markdown.hl'
  15. import { currentVerdict, pullTalk, personComment, personReply, personResolve, anyThreadOf, threadShape } from './reviews.hl'
  16. import { numberOf, isoMs } from './reviews-helpers.hl'
  17. import { raiseEvent } from './events.hl'
  18. import { mergeAndAnnounce } from './pullmerge.hl'
  19. // ---- who may write -----------------------------------------------------------------------------------------------
  20. // the one place that decides it (Atlas's reading, not the creator's words: "who may push"); `record` = the repos table record
  21. static mayWritePull = (user, record) => {
  22. return user != null && record != null && mayPush(user.id, record)
  23. }
  24. // ---- the PR of a request: the record, or null (no such repo for this viewer, unknown number) ------------------------
  25. static prOfRequest = (host, orepo, session, nText) => {
  26. slug = slugOfRequest(host, orepo)
  27. if (repoAt(slug, session) == null) { return null }
  28. n = numberOf(nText)
  29. record = repoBySlug(slug)
  30. if (n == null || record == null) { return null }
  31. ensurePulls(slug)
  32. return recordByNumber(record.id, n)
  33. }
  34. // ---- the view ------------------------------------------------------------------------------------------------------
  35. static verdictWords = (v) => { return v == 'approve' ? 'approved' : (v == 'request_changes' ? 'requested changes' : 'commented') }
  36. static appNameOf = (appId) => {
  37. a = appId == null ? null : appsTable.fetch(appId)
  38. return a == null ? '(removed app)' : a.name
  39. }
  40. // a comment's ISO time as "2026-11-02 06:00:00" (UTC, as the contract gives it)
  41. static shownTime = (iso) => { return iso.slice(0, 10) + ' ' + iso.slice(11, 19) + ' UTC' }
  42. static commentRow = (c) => {
  43. isApp = c.author.type == 'app'
  44. return { id = c.id author = c.author.name kind = isApp ? 'app' : 'user' isApp = isApp blocks = markdownBlocks(c.body) created = shownTime(c.created) }
  45. }
  46. // everything the page shows → the members of components/pull.hl. `viewer` = the session's user (or null)
  47. static prView = (slug, rec, session) => {
  48. repo = repoBySlug(slug)
  49. user = userOfSession(session)
  50. pull = pullObject(slug, rec.number)
  51. apps = appsOfRepo(repo.id)
  52. talk = pullTalk(repo, rec)
  53. badges = []
  54. for (s of statusesOf(repo.id, rec.head)) { badges.push(badgeOf(s)) }
  55. verdicts = []
  56. appList = []
  57. for (a of apps) {
  58. cv = currentVerdict(repo.id, rec.number, a.id)
  59. text = cv == null ? 'no review yet' : verdictWords(cv.verdict) + (cv.head == rec.head ? '' : ' on an earlier head ' + cv.head.slice(0, 8))
  60. verdicts.push({ id = a.id app = a.name text = text cls = cv == null ? 'none' : cv.verdict })
  61. appList.push({ id = a.id name = a.name })
  62. }
  63. reviews = []
  64. for (r of talk.reviews) {
  65. reviews.push({ id = r.id app = appNameOf(r.app) verdict = r.verdict words = verdictWords(r.verdict) head = r.head.slice(0, 8) earlier = r.head != rec.head ? 'earlier head' : 'current head' blocks = markdownBlocks(r.body) created = shownTime(isoMs(r.created)) })
  66. }
  67. threads = []
  68. for (t of talk.threads) { threads.push(threadRow(t)) }
  69. conversation = []
  70. for (c of talk.talk) { conversation.push(commentRow(c)) }
  71. pr = { number = rec.number numberText = '#' + rec.number title = pull.title parts = refParts(pull.title, repo.tktProject != null ? repo.tktProject : '') state = rec.state source = rec.source target = rec.target author = pull.author.name head = rec.head.slice(0, 8) }
  72. canAct = mayWritePull(user, repo)
  73. // the Merge button: always in the page, `.nomerge` hides it (an attribute is re-read when the view is reassigned, an `if` is not); the face checks again
  74. showMerge = canAct && rec.state == 'open'
  75. return { pr = pr statuses = badges hasStatuses = badges.length > 0 verdicts = verdicts hasVerdicts = verdicts.length > 0 apps = appList hasApps = appList.length > 0 reviews = reviews hasReviews = reviews.length > 0 threads = threads hasThreads = threads.length > 0 conversation = conversation hasConversation = conversation.length > 0 canAct = canAct readOnly = !canAct mergeClass = showMerge ? 'mergepr' : 'nomerge' }
  76. }
  77. static threadRow = (t) => {
  78. cs = []
  79. for (c of t.shape.comments) { cs.push(commentRow(c)) }
  80. marks = []
  81. if (t.shape.outdated) { marks.push('outdated') }
  82. if (t.shape.resolved) { marks.push('resolved') }
  83. return { id = t.shape.id app = appNameOf(t.row.app) path = t.shape.path line = t.shape.line where = t.shape.path + ':' + t.shape.line mark = marks.join(' · ') resolved = t.shape.resolved cls = t.shape.resolved ? 'thread resolved' : 'thread' toggleLabel = t.shape.resolved ? 'Reopen' : 'Resolve' nextState = !t.shape.resolved comments = cs }
  84. }
  85. // ---- the writes (the faces in components/pull.hl are thin wrappers around these) ----------------------------------
  86. // who + which PR → { repo, rec, user } | { error }; a viewer who may not write gets the same answer as a forged call would
  87. static actorFor = (slug, nText, session) => {
  88. if (repoAt(slug, session) == null) { return { error = 'no such pull request' } }
  89. user = userOfSession(session)
  90. if (user == null) { return { error = 'sign in to do that' } }
  91. repo = repoBySlug(slug)
  92. if (!mayWritePull(user, repo)) { return { error = 'only the owner and the members of this repository can do that' } }
  93. if (user.name == '') { return { error = 'choose a display name first (top of the page)' } }
  94. n = numberOf(nText)
  95. rec = n == null ? null : recordByNumber(repo.id, n)
  96. if (rec == null) { return { error = 'no such pull request' } }
  97. return { repo = repo rec = rec user = user }
  98. }
  99. // the PR page's Merge button: the same merge as the API's and the list's (lib/pullmerge.hl); the page is read again
  100. static mergeThePull = (slug, nText, session) => {
  101. a = actorFor(slug, nText, session)
  102. if (a.error != null) { return { error = a.error } }
  103. r = mergeAndAnnounce(a.repo, a.rec.sha, a.user, '')
  104. if (r.error != null) { return { error = r.error } }
  105. b = recordByNumber(a.repo.id, a.rec.number)
  106. return { view = prView(slug, b, session) notice = 'Merged.' }
  107. }
  108. static done = (slug, a, session) => { return { view = prView(slug, a.rec, session) } }
  109. static commentOnPull = (slug, nText, session, body) => {
  110. a = actorFor(slug, nText, session)
  111. if (a.error != null) { return { error = a.error } }
  112. r = personComment(a.repo, a.rec, a.user, body)
  113. if (r.error != null) { return { error = r.error } }
  114. raiseEvent(a.repo, 'pull_comment', 'created', { pull = pullObject(slug, a.rec.number) comment = r.comment }, a.user.id)
  115. return done(slug, a, session)
  116. }
  117. static replyInThread = (slug, nText, session, threadId, body) => {
  118. a = actorFor(slug, nText, session)
  119. if (a.error != null) { return { error = a.error } }
  120. r = personReply(a.repo, a.rec, a.user, threadId, body)
  121. if (r.error != null) { return { error = r.error } }
  122. t = anyThreadOf(a.repo, a.rec, threadId)
  123. shape = threadShape(t, a.rec.head)
  124. raiseEvent(a.repo, 'review_comment', 'created', { pull = pullObject(slug, a.rec.number) thread = shape comment = r.comment onlyApp = t.app }, a.user.id)
  125. return done(slug, a, session)
  126. }
  127. static setThreadResolved = (slug, nText, session, threadId, resolved) => {
  128. a = actorFor(slug, nText, session)
  129. if (a.error != null) { return { error = a.error } }
  130. r = personResolve(a.repo, a.rec, threadId, resolved)
  131. if (r.error != null) { return { error = r.error } }
  132. if (r.changed) {
  133. raiseEvent(a.repo, 'review_thread', resolved ? 'resolved' : 'unresolved', { pull = pullObject(slug, a.rec.number) thread = r.shape onlyApp = r.thread.app }, a.user.id)
  134. }
  135. return done(slug, a, session)
  136. }
  137. static reviewAgain = (slug, nText, session, appId) => {
  138. a = actorFor(slug, nText, session)
  139. if (a.error != null) { return { error = a.error } }
  140. let found = null
  141. for (x of appsOfRepo(a.repo.id)) { if (x.id == appId) { found = x } }
  142. if (found == null) { return { error = 'no such app on this repository' } }
  143. raiseEvent(a.repo, 'review_requested', 'requested', { pull = pullObject(slug, a.rec.number) onlyApp = found.id }, a.user.id)
  144. return { view = prView(slug, a.rec, session) notice = 'Asked ' + found.name + ' to review again.' }
  145. }

Branches

Latest commits

  • b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmre
  • 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
  • f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre
  • dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
  • 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
  • 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
  • 71b2fa4blog: hybriel#335mre
  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre
  • bf568e14log: V48 mergedmre
  • 09955dedMerge v48: Hybriel set-day48, theme layouts ce4a0bamre
  • f2a2b0cevendor: Hybriel set-day48, theme layouts ce4a0bamre
  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre