gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5e11184c5e11184cW60: record partial validation, framework gaps and cleanupmre5e11184c/components/pull.hl

11.0 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, mergeThePull, 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. mergeClass = v != null ? v.mergeClass : 'nomerge'
  43. readOnly = v != null && v.readOnly
  44. commentBody = ''
  45. replyDrafts = {}
  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. form { class = "replyform"
  135. on submit(e) {
  136. e.preventDefault()
  137. emit replyIt(e, th.id)
  138. }
  139. label { "Reply"
  140. textarea { name = "body" rows = "3" maxlength = "65536" required = "required" value = replyDrafts[th.id] on input(e) { replyDrafts[th.id] = e.target.value } }
  141. }
  142. button { type = "submit" "Reply" }
  143. button { class = "quiet" type = "button" th.toggleLabel on click(e) { emit toggleThread(th.id, th.nextState) } }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. h3 { "Conversation" }
  150. if (noConversation) { p { id = "noconversation" class = "empty" "Nobody has written here yet." } }
  151. ol { id = "conversation"
  152. for (c of conversation) {
  153. li { class = c.kind
  154. p { class = "head"
  155. strong { c.author }
  156. if (c.isApp) { span { class = "tag" "app" } }
  157. span { class = "muted" c.created }
  158. }
  159. Markdown { blocks = c.blocks }
  160. }
  161. }
  162. }
  163. if (canAct) {
  164. form { id = "commentform"
  165. on submit(e) {
  166. e.preventDefault()
  167. emit commentIt(e)
  168. }
  169. label { "Write a comment (Markdown)"
  170. textarea { id = "commentbody" name = "body" rows = "4" maxlength = "65536" required = "required" value = commentBody on input(e) { commentBody = e.target.value } }
  171. }
  172. button { id = "commentsave" type = "submit" "Comment" }
  173. }
  174. }
  175. if (readOnly) { p { id = "readonlyhint" class = "muted" "Only the owner and the members of this repository can comment here." } }
  176. }
  177. }
  178. }
  179. }
  180. // what a face answers is the page read again: every list is set from it
  181. apply = (r) => {
  182. if (r == null || r.error != null) {
  183. actError = r != null ? r.error : 'that did not work'
  184. return false
  185. }
  186. w = r.view
  187. pr = w.pr
  188. statuses = w.statuses
  189. hasStatuses = w.hasStatuses
  190. verdicts = w.verdicts
  191. hasVerdicts = w.hasVerdicts
  192. noVerdicts = !w.hasVerdicts
  193. reviews = w.reviews
  194. hasReviews = w.hasReviews
  195. noReviews = !w.hasReviews
  196. threads = w.threads
  197. hasThreads = w.hasThreads
  198. noThreads = !w.hasThreads
  199. conversation = w.conversation
  200. hasConversation = w.hasConversation
  201. noConversation = !w.hasConversation
  202. mergeClass = w.mergeClass
  203. actError = ''
  204. actNotice = r.notice != null ? r.notice : ''
  205. return true
  206. }
  207. on commentIt(e) {
  208. r = emit server gitoriaPrComment(slug, n, commentBody)
  209. if (apply(r)) { commentBody = '' }
  210. }
  211. on replyIt(e, threadId) {
  212. r = emit server gitoriaPrReply(slug, n, threadId, replyDrafts[threadId])
  213. if (apply(r)) { replyDrafts[threadId] = '' }
  214. }
  215. on toggleThread(threadId, resolved) {
  216. r = emit server gitoriaPrResolve(slug, n, threadId, resolved)
  217. apply(r)
  218. }
  219. on mergeIt() {
  220. r = emit server gitoriaPrMerge(slug, n)
  221. apply(r)
  222. }
  223. on askAgain(appId) {
  224. r = emit server gitoriaPrAskAgain(slug, n, appId)
  225. apply(r)
  226. }
  227. on server gitoriaPrComment(slugOf, nText, body, session) { return commentOnPull(slugOf, nText, session, body) }
  228. on server gitoriaPrReply(slugOf, nText, threadId, body, session) { return replyInThread(slugOf, nText, session, threadId, body) }
  229. on server gitoriaPrResolve(slugOf, nText, threadId, resolved, session) { return setThreadResolved(slugOf, nText, session, threadId, resolved) }
  230. on server gitoriaPrMerge(slugOf, nText, session) { return mergeThePull(slugOf, nText, session) }
  231. on server gitoriaPrAskAgain(slugOf, nText, appId, session) { return reviewAgain(slugOf, nText, session, appId) }
  232. Style {
  233. pullPage {
  234. display = 'grid'
  235. gap = '1rem'
  236. minWidth = '0'
  237. overflowWrap = 'anywhere'
  238. '> *' {
  239. margin = '0'
  240. }
  241. '.nomerge' {
  242. display = 'none'
  243. }
  244. '.number' {
  245. marginRight = '.5rem'
  246. color = 'var(--color-text-muted)'
  247. fontWeight = '400'
  248. }
  249. '.muted' {
  250. fontSize = '.875rem'
  251. }
  252. '.tag' {
  253. padding = '0 .4rem'
  254. fontSize = '.75rem'
  255. background = 'var(--color-background-sunken)'
  256. borderRadius = 'var(--radius-large)'
  257. }
  258. '.head' {
  259. display = 'flex'
  260. flexWrap = 'wrap'
  261. alignItems = 'center'
  262. gap = '.25rem .6rem'
  263. }
  264. '.mark' {
  265. fontSize = '.875rem'
  266. color = 'var(--color-text-muted)'
  267. }
  268. }
  269. #pullmeta {
  270. display = 'flex'
  271. flexWrap = 'wrap'
  272. alignItems = 'center'
  273. gap = '.25rem .8rem'
  274. }
  275. #pullstatuses {
  276. display = 'flex'
  277. flexWrap = 'wrap'
  278. gap = '.25rem .5rem'
  279. margin = '0'
  280. padding = '0'
  281. listStyle = 'none'
  282. li {
  283. display = 'inline-flex'
  284. flexWrap = 'wrap'
  285. gap = '0 .4rem'
  286. padding = '.1rem .6rem'
  287. fontSize = '.8125rem'
  288. background = 'var(--color-background-sunken)'
  289. borderRadius = 'var(--radius-large)'
  290. }
  291. '.success' {
  292. color = 'var(--color-success)'
  293. }
  294. '.failure' {
  295. color = 'var(--color-danger)'
  296. }
  297. }
  298. #pullverdicts {
  299. display = 'grid'
  300. gap = '.25rem'
  301. margin = '0'
  302. padding = '0'
  303. listStyle = 'none'
  304. li {
  305. display = 'flex'
  306. flexWrap = 'wrap'
  307. gap = '0 .6rem'
  308. }
  309. '.approve' {
  310. color = 'var(--color-success)'
  311. }
  312. '.request_changes' {
  313. color = 'var(--color-danger)'
  314. }
  315. }
  316. #reviewagain {
  317. display = 'flex'
  318. flexWrap = 'wrap'
  319. gap = '.5rem'
  320. }
  321. #reviewlist {
  322. display = 'grid'
  323. gap = '.5rem'
  324. margin = '0'
  325. padding = '0'
  326. listStyle = 'none'
  327. li {
  328. padding = '.5rem 1rem'
  329. background = 'var(--color-surface)'
  330. borderRadius = 'var(--radius-large)'
  331. }
  332. }
  333. #threadlist {
  334. display = 'grid'
  335. gap = '.5rem'
  336. margin = '0'
  337. padding = '0'
  338. listStyle = 'none'
  339. '> li' {
  340. padding = '.5rem 1rem'
  341. background = 'var(--color-surface)'
  342. borderRadius = 'var(--radius-large)'
  343. }
  344. '.resolved' {
  345. opacity = '.75'
  346. }
  347. '.comments' {
  348. display = 'grid'
  349. gap = '.5rem'
  350. margin = '0'
  351. padding = '0'
  352. listStyle = 'none'
  353. }
  354. '.where' {
  355. fontWeight = '600'
  356. }
  357. }
  358. #conversation {
  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. #commentform {
  371. display = 'grid'
  372. gap = '.75rem'
  373. }
  374. '.replyform' {
  375. display = 'grid'
  376. gap = '.5rem'
  377. justifyItems = 'start'
  378. }
  379. }

Branches

Latest commits

  • 5e11184cW60: record partial validation, framework gaps and cleanupmre
  • 20fe13fagitoria#33: centralize login and tickets connection statemre
  • 859754c0gitoria#29: retain the offline note and record the framework gapmre
  • d140bc04gitoria#30: reproduce the upsert ordering constraintmre
  • 6960e8f8gitoria#28: keep form values in bound component membersmre
  • 0db27200gitoria#32: share character checks and environment lookupmre
  • 452f6a1amission W60: logic clean-upsmre
  • 1448c899log: cleanup, #49 GPTBot, tracker mentions on #36mre
  • fcf95936log: v1.5.1 provenmre
  • 22105420log: W51b livemre
  • 7e8aabeareport: W51b pull source verificationmre
  • 6c18de76fix: preserve pull sources across containing branchesmre
  • fc36fa2elog: W51b pull source bugmre
  • 56bc1220log: v1.5.1 livemre
  • 845fc0aareport: W51mre
  • 83127391fix: return v1.5.1 app and merge error detailsmre
  • b07d0e97log: W51 v1.5.1 startedmre
  • 0b417d06docs: apps-api v1.5 user tokens (#48, W49)mre
  • d046940alog: vinzenz contract note sentmre
  • db443456log: vinzenz note retry 2mre