gitoria

gitoria

All repositories: gitoria

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

13.7 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, 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. if (state.head != approvalHead) {
  242. canApprove = false
  243. mergeClass = 'nomerge'
  244. blockText = 'The head changed; read the pull request again before approving.'
  245. return null
  246. }
  247. approvals = state.approvals
  248. approvalHead = state.head
  249. blockText = state.blockText
  250. approved = false
  251. for (a of state.approvals) { if (a.userId == viewerId && a.sha == state.head) { approved = true } }
  252. approvalLabel = approved ? 'Withdraw approval' : 'Approve'
  253. mergeClass = canAct && pr.state == 'open' && blockText == '' ? 'mergepr' : 'nomerge'
  254. }
  255. on approveIt() {
  256. r = emit server gitoriaPrApprove(slug, n, approvalHead, !approved)
  257. apply(r)
  258. }
  259. on server gitoriaPrApprove(String slugOf, String nText, String head, Boolean wanted, session) { return approveThePull(slugOf, nText, session, head, wanted) }
  260. on mergeIt() {
  261. r = emit server gitoriaPrMerge(slug, n)
  262. apply(r)
  263. }
  264. on askAgain(appId) {
  265. r = emit server gitoriaPrAskAgain(slug, n, appId)
  266. apply(r)
  267. }
  268. on server gitoriaPrComment(slugOf, nText, body, session) { return commentOnPull(slugOf, nText, session, body) }
  269. on server gitoriaPrReply(slugOf, nText, threadId, body, session) { return replyInThread(slugOf, nText, session, threadId, body) }
  270. on server gitoriaPrResolve(slugOf, nText, threadId, resolved, session) { return setThreadResolved(slugOf, nText, session, threadId, resolved) }
  271. on server gitoriaPrMerge(slugOf, nText, session) { return mergeThePull(slugOf, nText, session) }
  272. on server gitoriaPrAskAgain(slugOf, nText, appId, session) { return reviewAgain(slugOf, nText, session, appId) }
  273. Style {
  274. #personApprovals {
  275. listStyle = 'none'
  276. margin = '0'
  277. padding = '0'
  278. li {
  279. display = 'flex'
  280. flexWrap = 'wrap'
  281. gap = '.25rem .6rem'
  282. }
  283. }
  284. pullPage {
  285. display = 'grid'
  286. gap = '1rem'
  287. minWidth = '0'
  288. overflowWrap = 'anywhere'
  289. // Direct-child and sibling combinators have no bare language form.
  290. '> *' {
  291. margin = '0'
  292. }
  293. // Runtime and theme class predicates have no bare selector form.
  294. '.nomerge' {
  295. display = 'none'
  296. }
  297. // Runtime and theme class predicates have no bare selector form.
  298. '.muted' {
  299. fontSize = '.875rem'
  300. }
  301. }
  302. #pullmeta {
  303. display = 'flex'
  304. flexWrap = 'wrap'
  305. alignItems = 'center'
  306. gap = '.25rem .8rem'
  307. }
  308. #pullstatuses {
  309. display = 'flex'
  310. flexWrap = 'wrap'
  311. gap = '.25rem .5rem'
  312. margin = '0'
  313. padding = '0'
  314. listStyle = 'none'
  315. li {
  316. display = 'inline-flex'
  317. flexWrap = 'wrap'
  318. gap = '0 .4rem'
  319. padding = '.1rem .6rem'
  320. fontSize = '.8125rem'
  321. background = 'var(--color-background-sunken)'
  322. borderRadius = 'var(--radius-large)'
  323. }
  324. // Runtime and theme class predicates have no bare selector form.
  325. '.success' {
  326. color = 'var(--color-success)'
  327. }
  328. // Runtime and theme class predicates have no bare selector form.
  329. '.failure' {
  330. color = 'var(--color-danger)'
  331. }
  332. }
  333. #pullverdicts {
  334. display = 'grid'
  335. gap = '.25rem'
  336. margin = '0'
  337. padding = '0'
  338. listStyle = 'none'
  339. li {
  340. display = 'flex'
  341. flexWrap = 'wrap'
  342. gap = '0 .6rem'
  343. }
  344. // Runtime and theme class predicates have no bare selector form.
  345. '.approve' {
  346. color = 'var(--color-success)'
  347. }
  348. // Runtime and theme class predicates have no bare selector form.
  349. '.request_changes' {
  350. color = 'var(--color-danger)'
  351. }
  352. }
  353. #reviewagain {
  354. display = 'flex'
  355. flexWrap = 'wrap'
  356. gap = '.5rem'
  357. }
  358. #reviewlist {
  359. display = 'grid'
  360. gap = '.5rem'
  361. margin = '0'
  362. padding = '0'
  363. listStyle = 'none'
  364. li {
  365. padding = '.5rem 1rem'
  366. background = 'var(--color-surface)'
  367. borderRadius = 'var(--radius-large)'
  368. }
  369. }
  370. #threadlist {
  371. display = 'grid'
  372. gap = '.5rem'
  373. margin = '0'
  374. padding = '0'
  375. listStyle = 'none'
  376. // Direct-child and sibling combinators have no bare language form.
  377. '> li' {
  378. padding = '.5rem 1rem'
  379. background = 'var(--color-surface)'
  380. borderRadius = 'var(--radius-large)'
  381. }
  382. // Runtime and theme class predicates have no bare selector form.
  383. '.resolved' {
  384. opacity = '.75'
  385. }
  386. }
  387. #conversation {
  388. display = 'grid'
  389. gap = '.5rem'
  390. margin = '0'
  391. padding = '0'
  392. listStyle = 'none'
  393. li {
  394. padding = '.5rem 1rem'
  395. background = 'var(--color-surface)'
  396. borderRadius = 'var(--radius-large)'
  397. }
  398. }
  399. #commentform {
  400. display = 'grid'
  401. gap = '.75rem'
  402. }
  403. spanNumber {
  404. marginRight = '.5rem'
  405. color = 'var(--color-text-muted)'
  406. fontWeight = '400'
  407. }
  408. spanTag {
  409. padding = '0 .4rem'
  410. fontSize = '.75rem'
  411. background = 'var(--color-background-sunken)'
  412. borderRadius = 'var(--radius-large)'
  413. }
  414. pHead {
  415. display = 'flex'
  416. flexWrap = 'wrap'
  417. alignItems = 'center'
  418. gap = '.25rem .6rem'
  419. }
  420. spanMark {
  421. fontSize = '.875rem'
  422. color = 'var(--color-text-muted)'
  423. }
  424. olComments {
  425. display = 'grid'
  426. gap = '.5rem'
  427. margin = '0'
  428. padding = '0'
  429. listStyle = 'none'
  430. }
  431. codeWhere {
  432. fontWeight = '600'
  433. }
  434. #pullnotice {
  435. margin = '0'
  436. color = 'var(--color-success)'
  437. }
  438. #pullerror {
  439. margin = '0'
  440. color = 'var(--color-danger)'
  441. empty { display = 'none' }
  442. }
  443. }

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