gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita2ae8302a2ae8302logmrea2ae8302/components/pull.hl

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

Branches

Latest commits

  • a2ae8302logmre
  • 6947cd58logmre
  • 2175e48clogmre
  • 40eb3ca1gitoria#38: review package, logmre
  • 06a5a50egitoria#38: deploy b8252ca, logmre
  • b8252ca0gitoria#46: W46b report, logmre
  • 50093aafgitoria#46: statuses keyed by app + context (merge w46b-keyed)mre
  • dd0267edgitoria#46: fix a label in the keyed gatemre
  • b1dcb580gitoria#46: statuses keyed by app + context, required = app + context, old rows still readmre
  • 2287363egitoria#47: W47 report, logmre
  • 9f502db1gitoria#46: W46b briefmre
  • 9678a8f3gitoria#46: contract v1.4, statuses keyed by app + contextmre
  • bdcbbaa9gitoria#47: rate limits, status read route, statuses + required on the pull (merge w47-limits)mre
  • 772c401fgitoria#45: W45 report, logmre
  • b6b793afgitoria#45: PR page with reviews, threads, conversation, Review again (merge w45-pr-page)mre
  • fb9e7554gitoria#45: browser gate: a /pulls title links to the PR pagemre
  • f7198131gitoria#45: tests/pr-page.mjs gatemre
  • 483141d0gitoria#45: Settings shows the Apps heading only to the ownermre
  • e2eff8f6gitoria#45: the PR page /pulls/N with reviews, threads, verdicts, conversation, comment, reply, resolve and Review againmre
  • 7a602839gitoria#45: raiseEvent can send to one app only; people's comments, replies and resolving in reviews.hlmre