gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit54eec68754eec687Gate person approvals and merge alternativesmre54eec687/components/pull.hl

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

Branches

Latest commits

  • 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
  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre