gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfcf95936fcf95936log: v1.5.1 provenmrefcf95936/components/pull.hl

10.8 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. actError = ''
  45. actNotice = ''
  46. listHref = px(slug) + '/pulls'
  47. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Pull request ' + (n == null ? '' : '#' + n))
  48. View {
  49. repoPage {
  50. if (hasPr) {
  51. pullPage { id = "pullpage"
  52. p { a { id = "topulls" href = listHref "← Pull requests" } }
  53. h2 { id = "pulltitle"
  54. span { class = "number" pr.numberText }
  55. for (pt of pr.parts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } }
  56. }
  57. p { id = "pullmeta"
  58. span { id = "pullstate" class = pr.state pr.state }
  59. span { id = "pullbranches" strong { pr.source } " → " strong { pr.target } }
  60. span { class = "muted" "by " span { id = "pullauthor" pr.author } " · head " code { pr.head } }
  61. }
  62. if (hasStatuses) {
  63. ul { id = "pullstatuses"
  64. for (st of statuses) {
  65. li { class = st.cls
  66. span { class = "state" st.state }
  67. span { class = "label" st.label }
  68. span { class = "muted" st.title }
  69. }
  70. }
  71. }
  72. }
  73. h3 { "Verdicts" }
  74. if (hasVerdicts) {
  75. ul { id = "pullverdicts"
  76. for (vd of verdicts) {
  77. li { class = vd.cls
  78. strong { vd.app }
  79. span { vd.text }
  80. }
  81. }
  82. }
  83. }
  84. if (noVerdicts) { p { id = "noapps" class = "empty" "No app is connected to this repository." } }
  85. if (canAct) {
  86. div { id = "reviewagain"
  87. for (ap of apps) {
  88. button { class = "quiet" type = "button" value = ap.id "Review again: " ap.name on click(e) { emit askAgain(e.target.value) } }
  89. }
  90. }
  91. }
  92. button { id = "mergepull" class = mergeClass type = "button" "Merge" on click(e) { emit mergeIt() } }
  93. p { id = "pullnotice" class = "notice" actNotice }
  94. p { id = "pullerror" class = "message" actError }
  95. h3 { "Reviews" }
  96. if (noReviews) { p { id = "noreviews" class = "empty" "No review yet." } }
  97. ol { id = "reviewlist"
  98. for (rv of reviews) {
  99. li { class = rv.verdict
  100. p { class = "head"
  101. strong { rv.app }
  102. span { class = "tag" "app" }
  103. span { class = "verdict" rv.words }
  104. span { class = "muted" rv.head + " · " + rv.earlier + " · " + rv.created }
  105. }
  106. Markdown { blocks = rv.blocks }
  107. }
  108. }
  109. }
  110. h3 { "Threads" }
  111. if (noThreads) { p { id = "nothreads" class = "empty" "No inline comments yet." } }
  112. ol { id = "threadlist"
  113. for (th of threads) {
  114. li { class = th.cls
  115. p { class = "head"
  116. code { class = "where" th.where }
  117. span { class = "mark" th.mark }
  118. span { class = "muted" th.app }
  119. }
  120. ol { class = "comments"
  121. for (c of th.comments) {
  122. li { class = c.kind
  123. p { class = "head"
  124. strong { c.author }
  125. span { class = "muted" c.created }
  126. }
  127. Markdown { blocks = c.blocks }
  128. }
  129. }
  130. }
  131. if (canAct) {
  132. form { class = "replyform"
  133. on submit(e) {
  134. e.preventDefault()
  135. emit replyIt(e, th.id)
  136. }
  137. label { "Reply"
  138. textarea { name = "body" rows = "3" maxlength = "65536" required = "required" }
  139. }
  140. button { type = "submit" "Reply" }
  141. button { class = "quiet" type = "button" th.toggleLabel on click(e) { emit toggleThread(th.id, th.nextState) } }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. h3 { "Conversation" }
  148. if (noConversation) { p { id = "noconversation" class = "empty" "Nobody has written here yet." } }
  149. ol { id = "conversation"
  150. for (c of conversation) {
  151. li { class = c.kind
  152. p { class = "head"
  153. strong { c.author }
  154. if (c.isApp) { span { class = "tag" "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" }
  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. f = e.target.elements
  207. r = emit server gitoriaPrComment(slug, n, f.body.value)
  208. if (apply(r)) { f.body.value = '' }
  209. }
  210. on replyIt(e, threadId) {
  211. f = e.target.elements
  212. r = emit server gitoriaPrReply(slug, n, threadId, f.body.value)
  213. if (apply(r)) { f.body.value = '' }
  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

  • 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
  • 802f229alog: kunibert repo ping provenmre
  • 2d2eaa92log: Kunibert connected to kunibert repomre
  • 65d5f80alogmre
  • dab74b0dW49 report, logmre
  • fd4fc028Exercise member status reads with a populated check statemre
  • 536ca6f9Allow repository members to read pull workflow APIs with user tokensmre
  • 705dd834W49 missionmre
  • b554cd5flogmre