gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite7af3ecee7af3eceMerge branch 'w52b-approval-followup' into mainGitoriae7af3ece/components/pull.hl

14.4 KB

  1. // components/pull.hl — ONE PULL REQUEST (gitoria#45, part of the push API #38): `/pulls/N` on <slug>.<domain> and `/<repo>/pulls/N` in an organization.
  2. // A function route (lib/api.hl pullPage) renders it only for a PR the viewer may see, so an unknown number is a real 404. Everything comes from lib/prpage.hl
  3. // on the SERVER (first HTML and every navigation): the PR, its statuses on the current head, every app's current verdict, the reviews, the threads
  4. // (path:line, outdated / resolved marks) and the conversation. Bodies are Markdown as text nodes (components/markdown.hl). A viewer who may write (lib/prpage.hl
  5. // mayWritePull) gets the forms and the "Review again" buttons; the faces check it again, so a forged call is refused. Rows are keyed by the PR number and the
  6. // thread / comment ids the server gave, never by a position.
  7. parent './repo.hl'
  8. import Markdown from './markdown.hl'
  9. import PullReply from './pull-reply.hl'
  10. import { siteName } from '../project.hl'
  11. import { slugOfRequest } from '../lib/orgs.hl'
  12. import { userIdOfSession } from '../lib/users.hl'
  13. import { titleSlug, repoAt } from '../lib/repos.hl'
  14. import { pageTitle } from '../lib/repos-helpers.hl'
  15. import { px } from '../lib/util.hl'
  16. import { prOfRequest, prView, approvalStateFor, approveThePull, mergeThePull, commentOnPull, replyInThread, setThreadResolved, reviewAgain } from '../lib/prpage.hl'
  17. host = null
  18. orepo = ''
  19. n = null
  20. session = null
  21. viewerId = userIdOfSession(session)
  22. slug = slugOfRequest(host, orepo)
  23. repo = repoAt(slug, session)
  24. rec = repo != null ? prOfRequest(host, orepo, session, n) : null
  25. v = rec != null ? prView(slug, rec, session) : null
  26. hasPr = v != null
  27. pr = v != null ? v.pr : null
  28. statuses = v != null ? v.statuses : []
  29. hasStatuses = v != null && v.hasStatuses
  30. verdicts = v != null ? v.verdicts : []
  31. hasVerdicts = v != null && v.hasVerdicts
  32. noVerdicts = v != null && !v.hasVerdicts
  33. apps = v != null ? v.apps : []
  34. hasApps = v != null && v.hasApps
  35. reviews = v != null ? v.reviews : []
  36. hasReviews = v != null && v.hasReviews
  37. noReviews = v != null && !v.hasReviews
  38. threads = v != null ? v.threads : []
  39. hasThreads = v != null && v.hasThreads
  40. noThreads = v != null && !v.hasThreads
  41. conversation = v != null ? v.conversation : []
  42. hasConversation = v != null && v.hasConversation
  43. noConversation = v != null && !v.hasConversation
  44. canAct = v != null && v.canAct
  45. mergeClass = v != null ? v.mergeClass : 'nomerge'
  46. approvals = v != null ? v.approvals : []
  47. approvalHead = v != null ? v.approvalHead : ''
  48. approvalLabel = v != null ? v.approvalLabel : 'Approve'
  49. approved = v != null && v.approved
  50. canApprove = v != null && v.canApprove
  51. blockText = v != null ? v.blockText : ''
  52. readOnly = v != null && v.readOnly
  53. commentBody = ''
  54. actError = ''
  55. actNotice = ''
  56. listHref = px(slug) + '/pulls'
  57. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Pull request ' + (n == null ? '' : '#' + n))
  58. View {
  59. repoPage {
  60. if (hasPr) {
  61. pullPage { id = "pullpage"
  62. p { a { id = "topulls" href = listHref "← Pull requests" } }
  63. h2 { id = "pulltitle"
  64. span { Style.spanNumber pr.numberText }
  65. for (pt of pr.parts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } }
  66. }
  67. p { id = "pullmeta"
  68. // Runtime row/state classes have no Style-rule selection form.
  69. span { id = "pullstate" class = pr.state pr.state }
  70. span { id = "pullbranches" strong { pr.source } " → " strong { pr.target } }
  71. span { class = "muted" "by " span { id = "pullauthor" pr.author } " · head " code { pr.head } }
  72. }
  73. if (hasStatuses) {
  74. ul { id = "pullstatuses"
  75. for (st of statuses) {
  76. // Runtime row/state classes have no Style-rule selection form.
  77. li { class = st.cls
  78. span { class = "state" st.state }
  79. span { class = "label" st.label }
  80. span { class = "muted" st.title }
  81. }
  82. }
  83. }
  84. }
  85. h3 { "Verdicts" }
  86. if (hasVerdicts) {
  87. ul { id = "pullverdicts"
  88. for (vd of verdicts) {
  89. // Runtime row/state classes have no Style-rule selection form.
  90. li { class = vd.cls
  91. strong { vd.app }
  92. span { vd.text }
  93. }
  94. }
  95. }
  96. }
  97. if (noVerdicts) { p { id = "noapps" class = "empty" "No app is connected to this repository." } }
  98. if (canAct) {
  99. div { id = "reviewagain"
  100. for (ap of apps) {
  101. button { class = "quiet" type = "button" value = ap.id "Review again: " ap.name on click(e) { emit askAgain(e.target.value) } }
  102. }
  103. }
  104. }
  105. // Runtime row/state classes have no Style-rule selection form.
  106. button { id = "mergepull" class = mergeClass type = "button" "Merge" on click(e) { emit mergeIt() } }
  107. p { id = "pullnotice" actNotice }
  108. p { id = "pullerror" actError }
  109. h3 { "People’s approvals" }
  110. ul { id = "personApprovals"
  111. for (a of approvals) {
  112. li { strong { a.name } span { a.words } code { a.head } time { a.created } }
  113. }
  114. }
  115. if (canApprove) { button { id = "approvePull" type = "button" approvalLabel on click(Hybrid e) { emit approveIt() } } }
  116. p { id = "mergeWait" blockText }
  117. h3 { "Reviews" }
  118. if (noReviews) { p { id = "noreviews" class = "empty" "No review yet." } }
  119. ol { id = "reviewlist"
  120. for (rv of reviews) {
  121. // Runtime row/state classes have no Style-rule selection form.
  122. li { class = rv.verdict
  123. p { Style.pHead
  124. strong { rv.app }
  125. span { Style.spanTag "app" }
  126. span { class = "verdict" rv.words }
  127. span { class = "muted" rv.head + " · " + rv.earlier + " · " + rv.created }
  128. }
  129. Markdown { blocks = rv.blocks }
  130. }
  131. }
  132. }
  133. h3 { "Threads" }
  134. if (noThreads) { p { id = "nothreads" class = "empty" "No inline comments yet." } }
  135. ol { id = "threadlist"
  136. for (th of threads) {
  137. // Runtime row/state classes have no Style-rule selection form.
  138. li { class = th.cls
  139. p { Style.pHead
  140. code { Style.codeWhere th.where }
  141. span { Style.spanMark th.mark }
  142. span { class = "muted" th.app }
  143. }
  144. ol { Style.olComments
  145. for (c of th.comments) {
  146. // Runtime row/state classes have no Style-rule selection form.
  147. li { class = c.kind
  148. p { Style.pHead
  149. strong { c.author }
  150. span { class = "muted" c.created }
  151. }
  152. Markdown { blocks = c.blocks }
  153. }
  154. }
  155. }
  156. if (canAct) {
  157. PullReply { threadId = th.id toggleLabel = th.toggleLabel nextState = th.nextState sendReply = replyIt resolveThread = toggleThread }
  158. }
  159. }
  160. }
  161. }
  162. h3 { "Conversation" }
  163. if (noConversation) { p { id = "noconversation" class = "empty" "Nobody has written here yet." } }
  164. ol { id = "conversation"
  165. for (c of conversation) {
  166. // Runtime row/state classes have no Style-rule selection form.
  167. li { class = c.kind
  168. p { Style.pHead
  169. strong { c.author }
  170. if (c.isApp) { span { Style.spanTag "app" } }
  171. span { class = "muted" c.created }
  172. }
  173. Markdown { blocks = c.blocks }
  174. }
  175. }
  176. }
  177. if (canAct) {
  178. form { id = "commentform"
  179. on submit(e) {
  180. e.preventDefault()
  181. emit commentIt(e)
  182. }
  183. label { "Write a comment (Markdown)"
  184. textarea { id = "commentbody" name = "body" rows = "4" maxlength = "65536" required = "required" value = commentBody on input(e) { commentBody = e.target.value } }
  185. }
  186. button { id = "commentsave" type = "submit" "Comment" }
  187. }
  188. }
  189. if (readOnly) { p { id = "readonlyhint" class = "muted" "Only the owner and the members of this repository can comment here." } }
  190. }
  191. }
  192. }
  193. }
  194. // what a face answers is the page read again: every list is set from it
  195. apply = (r) => {
  196. if (r == null || r.error != null) {
  197. actError = r != null ? r.error : 'that did not work'
  198. return false
  199. }
  200. w = r.view
  201. pr = w.pr
  202. statuses = w.statuses
  203. hasStatuses = w.hasStatuses
  204. verdicts = w.verdicts
  205. hasVerdicts = w.hasVerdicts
  206. noVerdicts = !w.hasVerdicts
  207. reviews = w.reviews
  208. hasReviews = w.hasReviews
  209. noReviews = !w.hasReviews
  210. threads = w.threads
  211. hasThreads = w.hasThreads
  212. noThreads = !w.hasThreads
  213. conversation = w.conversation
  214. hasConversation = w.hasConversation
  215. noConversation = !w.hasConversation
  216. mergeClass = w.mergeClass
  217. approvals = w.approvals
  218. approvalHead = w.approvalHead
  219. approvalLabel = w.approvalLabel
  220. approved = w.approved
  221. canApprove = w.canApprove
  222. blockText = w.blockText
  223. actError = ''
  224. actNotice = r.notice != null ? r.notice : ''
  225. return true
  226. }
  227. on commentIt(e) {
  228. r = emit server gitoriaPrComment(slug, n, commentBody)
  229. if (apply(r)) { commentBody = '' }
  230. }
  231. replyIt = (threadId, body) => {
  232. r = emit server gitoriaPrReply(slug, n, threadId, body)
  233. return apply(r)
  234. }
  235. toggleThread = (threadId, resolved) => {
  236. r = emit server gitoriaPrResolve(slug, n, threadId, resolved)
  237. apply(r)
  238. }
  239. on client gitoriaPullApprovalChanged(String changedSlug, Number number, Hybrid state) {
  240. if (changedSlug != slug || pr == null || pr.number != number) { return null }
  241. applyApprovalState(state)
  242. }
  243. on client gitoriaStatusChanged(String changedSlug, String sha) {
  244. if (changedSlug != slug || pr == null || sha != approvalHead) { return null }
  245. state = emit server gitoriaPrApprovalState(slug, n)
  246. if (state != null) { applyApprovalState(state) }
  247. }
  248. on client gitoriaRequiredChanged(String changedSlug) {
  249. if (changedSlug != slug || pr == null) { return null }
  250. state = emit server gitoriaPrApprovalState(slug, n)
  251. if (state != null) { applyApprovalState(state) }
  252. }
  253. on server gitoriaPrApprovalState(String slugOf, String nText, Hybrid session) {
  254. return approvalStateFor(slugOf, nText, session)
  255. }
  256. applyApprovalState = (Hybrid state) => {
  257. if (state.head != approvalHead) {
  258. canApprove = false
  259. mergeClass = 'nomerge'
  260. blockText = 'The head changed; read the pull request again before approving.'
  261. return null
  262. }
  263. approvals = state.approvals
  264. approvalHead = state.head
  265. blockText = state.blockText
  266. approved = false
  267. for (a of state.approvals) { if (a.userId == viewerId && a.sha == state.head) { approved = true } }
  268. approvalLabel = approved ? 'Withdraw approval' : 'Approve'
  269. mergeClass = canAct && pr.state == 'open' && blockText == '' ? 'mergepr' : 'nomerge'
  270. }
  271. on approveIt() {
  272. r = emit server gitoriaPrApprove(slug, n, approvalHead, !approved)
  273. apply(r)
  274. }
  275. on server gitoriaPrApprove(String slugOf, String nText, String head, Boolean wanted, session) { return approveThePull(slugOf, nText, session, head, wanted) }
  276. on mergeIt() {
  277. r = emit server gitoriaPrMerge(slug, n)
  278. apply(r)
  279. }
  280. on askAgain(appId) {
  281. r = emit server gitoriaPrAskAgain(slug, n, appId)
  282. apply(r)
  283. }
  284. on server gitoriaPrComment(slugOf, nText, body, session) { return commentOnPull(slugOf, nText, session, body) }
  285. on server gitoriaPrReply(slugOf, nText, threadId, body, session) { return replyInThread(slugOf, nText, session, threadId, body) }
  286. on server gitoriaPrResolve(slugOf, nText, threadId, resolved, session) { return setThreadResolved(slugOf, nText, session, threadId, resolved) }
  287. on server gitoriaPrMerge(slugOf, nText, session) { return mergeThePull(slugOf, nText, session) }
  288. on server gitoriaPrAskAgain(slugOf, nText, appId, session) { return reviewAgain(slugOf, nText, session, appId) }
  289. Style {
  290. #personApprovals {
  291. listStyle = 'none'
  292. margin = '0'
  293. padding = '0'
  294. li {
  295. display = 'flex'
  296. flexWrap = 'wrap'
  297. gap = '.25rem .6rem'
  298. }
  299. }
  300. pullPage {
  301. display = 'grid'
  302. gap = '1rem'
  303. minWidth = '0'
  304. overflowWrap = 'anywhere'
  305. // Direct-child and sibling combinators have no bare language form.
  306. '> *' {
  307. margin = '0'
  308. }
  309. // Runtime and theme class predicates have no bare selector form.
  310. '.nomerge' {
  311. display = 'none'
  312. }
  313. // Runtime and theme class predicates have no bare selector form.
  314. '.muted' {
  315. fontSize = '.875rem'
  316. }
  317. }
  318. #pullmeta {
  319. display = 'flex'
  320. flexWrap = 'wrap'
  321. alignItems = 'center'
  322. gap = '.25rem .8rem'
  323. }
  324. #pullstatuses {
  325. display = 'flex'
  326. flexWrap = 'wrap'
  327. gap = '.25rem .5rem'
  328. margin = '0'
  329. padding = '0'
  330. listStyle = 'none'
  331. li {
  332. display = 'inline-flex'
  333. flexWrap = 'wrap'
  334. gap = '0 .4rem'
  335. padding = '.1rem .6rem'
  336. fontSize = '.8125rem'
  337. background = 'var(--color-background-sunken)'
  338. borderRadius = 'var(--radius-large)'
  339. }
  340. // Runtime and theme class predicates have no bare selector form.
  341. '.success' {
  342. color = 'var(--color-success)'
  343. }
  344. // Runtime and theme class predicates have no bare selector form.
  345. '.failure' {
  346. color = 'var(--color-danger)'
  347. }
  348. }
  349. #pullverdicts {
  350. display = 'grid'
  351. gap = '.25rem'
  352. margin = '0'
  353. padding = '0'
  354. listStyle = 'none'
  355. li {
  356. display = 'flex'
  357. flexWrap = 'wrap'
  358. gap = '0 .6rem'
  359. }
  360. // Runtime and theme class predicates have no bare selector form.
  361. '.approve' {
  362. color = 'var(--color-success)'
  363. }
  364. // Runtime and theme class predicates have no bare selector form.
  365. '.request_changes' {
  366. color = 'var(--color-danger)'
  367. }
  368. }
  369. #reviewagain {
  370. display = 'flex'
  371. flexWrap = 'wrap'
  372. gap = '.5rem'
  373. }
  374. #reviewlist {
  375. display = 'grid'
  376. gap = '.5rem'
  377. margin = '0'
  378. padding = '0'
  379. listStyle = 'none'
  380. li {
  381. padding = '.5rem 1rem'
  382. background = 'var(--color-surface)'
  383. borderRadius = 'var(--radius-large)'
  384. }
  385. }
  386. #threadlist {
  387. display = 'grid'
  388. gap = '.5rem'
  389. margin = '0'
  390. padding = '0'
  391. listStyle = 'none'
  392. // Direct-child and sibling combinators have no bare language form.
  393. '> li' {
  394. padding = '.5rem 1rem'
  395. background = 'var(--color-surface)'
  396. borderRadius = 'var(--radius-large)'
  397. }
  398. // Runtime and theme class predicates have no bare selector form.
  399. '.resolved' {
  400. opacity = '.75'
  401. }
  402. }
  403. #conversation {
  404. display = 'grid'
  405. gap = '.5rem'
  406. margin = '0'
  407. padding = '0'
  408. listStyle = 'none'
  409. li {
  410. padding = '.5rem 1rem'
  411. background = 'var(--color-surface)'
  412. borderRadius = 'var(--radius-large)'
  413. }
  414. }
  415. #commentform {
  416. display = 'grid'
  417. gap = '.75rem'
  418. }
  419. spanNumber {
  420. marginRight = '.5rem'
  421. color = 'var(--color-text-muted)'
  422. fontWeight = '400'
  423. }
  424. spanTag {
  425. padding = '0 .4rem'
  426. fontSize = '.75rem'
  427. background = 'var(--color-background-sunken)'
  428. borderRadius = 'var(--radius-large)'
  429. }
  430. pHead {
  431. display = 'flex'
  432. flexWrap = 'wrap'
  433. alignItems = 'center'
  434. gap = '.25rem .6rem'
  435. }
  436. spanMark {
  437. fontSize = '.875rem'
  438. color = 'var(--color-text-muted)'
  439. }
  440. olComments {
  441. display = 'grid'
  442. gap = '.5rem'
  443. margin = '0'
  444. padding = '0'
  445. listStyle = 'none'
  446. }
  447. codeWhere {
  448. fontWeight = '600'
  449. }
  450. #pullnotice {
  451. margin = '0'
  452. color = 'var(--color-success)'
  453. }
  454. #pullerror {
  455. margin = '0'
  456. color = 'var(--color-danger)'
  457. empty { display = 'none' }
  458. }
  459. }

Branches

Latest commits

  • 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
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 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