gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5d0834e75d0834e7log: Apollo model rulemre5d0834e7/components/pull.hl

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

Branches

Latest commits

  • 5d0834e7log: Apollo model rulemre
  • fe8e5bd5log: #25 sample, V48 missionmre
  • 8580c5d9log: theme fix from Atlasmre
  • 46823d93log: Apollo budget correctionmre
  • f6d32341log: Apollo on budget and #25 nextmre
  • d7184f53log: batch live, #25 evidencemre
  • 5e25e816log: W61 mergedmre
  • aafe330dTidy: drop evidence JSON (kept in scratch), collapse blank linesmre
  • aca1fda1Merge W61: theme from layouts 17e0f03, Views refer to Style rules (gitoria#37 #27)mre
  • 03cb650blog: W61 theme decisionmre
  • 248bce85Report final style gates, CSS mappings and 136 whole-image comparisonsmre
  • 153c344bRestore organization metadata exposed by the whole-image comparisonmre
  • 917a1465Update status gate assertions for the referenced state rulemre
  • 3cdb02c6Own settings feedback styles and explain connection-state classesmre
  • 00d5d6c4Reference code-entry styles and nest code-browser media and pseudosmre
  • 3c425eddReference PR content styles and explain dynamic state classesmre
  • e46fa222Own shell feedback styles and retain documented selector formsmre
  • c26084c4Reference repository list styles and nest its breakpointmre
  • f3e196b5Document Markdown direct-child selector remaindersmre
  • 70597528Reference pull list rules and explain runtime class predicatesmre