gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit1ce7ac241ce7ac24Reference ticket row and feedback styles from its Viewmre1ce7ac24/components/pull.hl

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

Branches

Latest commits

  • 1ce7ac24Reference ticket row and feedback styles from its Viewmre
  • 10cdf54bGive organization repository rows their own Style referencesmre
  • 0d019521Document shared class selectors in the styles-only filemre
  • c67404a7Scope token labels and feedback through the token Viewmre
  • 944e3dabScope key names, fingerprints and errors to the keys Viewmre
  • 7bcf7bc2Nest repo navigation media rules and document selector gapsmre
  • 46a76272Reference release row styles from the Viewmre
  • a383f428Tie README definition and path styles to its own Viewmre
  • a90812ffConsolidate add-code styles under its existing View idmre
  • 89107a3eDocument the index direct-child selector remaindermre
  • 07403362Scope reply form layout through the component form rulemre
  • 097c52baStyle the login error through its View idmre
  • c6d9c86aOwn the not-found code rule in its componentmre
  • 055424c2Record W61 replacement theme gates, sidebar repro and baselinemre
  • 2ed09441Use layouts theme 17e0f03 for W61 compatibilitymre
  • b8609a91Merge branch 'main' into w61-stylemre
  • 4639caf7Report W61 theme startup blocker and day39 Style probemre
  • 81f0a0bbREADME: two caches were restored by 90b4f72; log W62mre
  • 4a3f557eImport layouts theme ebd00b6 for W61 (startup blocked)mre
  • ab12a257Merge W62: #25 commit page measurements and proc repromre