gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainfe209ffeMerge branch 'w56-owner-members' into mainGitoriamain/components/pull.hl

14.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 { userIdOfSession } from '../lib/users.hl'
  13. import { titleSlug, repoAt } from '../lib/repos.hl'
  14. import { pageTitle } from '../lib/repos-helpers.hl'
  15. import { px } from '../lib/util.hl'
  16. import { prOfRequest, prView, approvalStateFor, approveThePull, mergeThePull, commentOnPull, replyInThread, setThreadResolved, reviewAgain } from '../lib/prpage.hl'
  17. host = null
  18. orepo = ''
  19. n = null
  20. session = null
  21. viewerId = userIdOfSession(session)
  22. slug = slugOfRequest(host, orepo)
  23. repo = repoAt(slug, session)
  24. rec = repo != null ? prOfRequest(host, orepo, session, n) : null
  25. v = rec != null ? prView(slug, rec, session) : null
  26. hasPr = v != null
  27. pr = v != null ? v.pr : null
  28. statuses = v != null ? v.statuses : []
  29. hasStatuses = v != null && v.hasStatuses
  30. verdicts = v != null ? v.verdicts : []
  31. hasVerdicts = v != null && v.hasVerdicts
  32. noVerdicts = v != null && !v.hasVerdicts
  33. apps = v != null ? v.apps : []
  34. hasApps = v != null && v.hasApps
  35. reviews = v != null ? v.reviews : []
  36. hasReviews = v != null && v.hasReviews
  37. noReviews = v != null && !v.hasReviews
  38. threads = v != null ? v.threads : []
  39. hasThreads = v != null && v.hasThreads
  40. noThreads = v != null && !v.hasThreads
  41. conversation = v != null ? v.conversation : []
  42. hasConversation = v != null && v.hasConversation
  43. noConversation = v != null && !v.hasConversation
  44. canAct = v != null && v.canAct
  45. mergeClass = v != null ? v.mergeClass : 'nomerge'
  46. approvals = v != null ? v.approvals : []
  47. approvalHead = v != null ? v.approvalHead : ''
  48. approvalLabel = v != null ? v.approvalLabel : 'Approve'
  49. approved = v != null && v.approved
  50. canApprove = v != null && v.canApprove
  51. blockText = v != null ? v.blockText : ''
  52. readOnly = v != null && v.readOnly
  53. commentBody = ''
  54. actError = ''
  55. actNotice = ''
  56. listHref = px(slug) + '/pulls'
  57. titleRepo = repoAt(slugOfRequest(host, orepo), session)
  58. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Pull request ' + (n == null ? '' : '#' + n))
  59. View {
  60. repoPage {
  61. if (hasPr) {
  62. pullPage { id = "pullpage"
  63. p { a { id = "topulls" href = listHref "← Pull requests" } }
  64. h2 { id = "pulltitle"
  65. span { Style.spanNumber pr.numberText }
  66. for (pt of pr.parts) { if (pt.isText) { span { pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } }
  67. }
  68. p { id = "pullmeta"
  69. // Runtime row/state classes have no Style-rule selection form.
  70. span { id = "pullstate" class = pr.state pr.state }
  71. span { id = "pullbranches" strong { pr.source } " → " strong { pr.target } }
  72. span { class = "muted" "by " span { id = "pullauthor" pr.author } " · head " code { pr.head } }
  73. }
  74. if (hasStatuses) {
  75. ul { id = "pullstatuses"
  76. for (st of statuses) {
  77. // Runtime row/state classes have no Style-rule selection form.
  78. li { class = st.cls
  79. span { class = "state" st.state }
  80. span { class = "label" st.label }
  81. span { class = "muted" st.title }
  82. }
  83. }
  84. }
  85. }
  86. h3 { "Verdicts" }
  87. if (hasVerdicts) {
  88. ul { id = "pullverdicts"
  89. for (vd of verdicts) {
  90. // Runtime row/state classes have no Style-rule selection form.
  91. li { class = vd.cls
  92. strong { vd.app }
  93. span { vd.text }
  94. }
  95. }
  96. }
  97. }
  98. if (noVerdicts) { p { id = "noapps" class = "empty" "No app is connected to this repository." } }
  99. if (canAct) {
  100. div { id = "reviewagain"
  101. for (ap of apps) {
  102. button { class = "quiet" type = "button" value = ap.id "Review again: " ap.name on click(e) { emit askAgain(e.target.value) } }
  103. }
  104. }
  105. }
  106. // Runtime row/state classes have no Style-rule selection form.
  107. button { id = "mergepull" class = mergeClass type = "button" "Merge" on click(e) { emit mergeIt() } }
  108. p { id = "pullnotice" actNotice }
  109. p { id = "pullerror" actError }
  110. h3 { "People’s approvals" }
  111. ul { id = "personApprovals"
  112. for (a of approvals) {
  113. li { strong { a.name } span { a.words } code { a.head } time { a.created } }
  114. }
  115. }
  116. if (canApprove) { button { id = "approvePull" type = "button" approvalLabel on click(Hybrid e) { emit approveIt() } } }
  117. p { id = "mergeWait" blockText }
  118. h3 { "Reviews" }
  119. if (noReviews) { p { id = "noreviews" class = "empty" "No review yet." } }
  120. ol { id = "reviewlist"
  121. for (rv of reviews) {
  122. // Runtime row/state classes have no Style-rule selection form.
  123. li { class = rv.verdict
  124. p { Style.pHead
  125. strong { rv.app }
  126. span { Style.spanTag "app" }
  127. span { class = "verdict" rv.words }
  128. span { class = "muted" rv.head + " · " + rv.earlier + " · " + rv.created }
  129. }
  130. Markdown { blocks = rv.blocks }
  131. }
  132. }
  133. }
  134. h3 { "Threads" }
  135. if (noThreads) { p { id = "nothreads" class = "empty" "No inline comments yet." } }
  136. ol { id = "threadlist"
  137. for (th of threads) {
  138. // Runtime row/state classes have no Style-rule selection form.
  139. li { class = th.cls
  140. p { Style.pHead
  141. code { Style.codeWhere th.where }
  142. span { Style.spanMark th.mark }
  143. span { class = "muted" th.app }
  144. }
  145. ol { Style.olComments
  146. for (c of th.comments) {
  147. // Runtime row/state classes have no Style-rule selection form.
  148. li { class = c.kind
  149. p { Style.pHead
  150. strong { c.author }
  151. span { class = "muted" c.created }
  152. }
  153. Markdown { blocks = c.blocks }
  154. }
  155. }
  156. }
  157. if (canAct) {
  158. PullReply { threadId = th.id toggleLabel = th.toggleLabel nextState = th.nextState sendReply = replyIt resolveThread = toggleThread }
  159. }
  160. }
  161. }
  162. }
  163. h3 { "Conversation" }
  164. if (noConversation) { p { id = "noconversation" class = "empty" "Nobody has written here yet." } }
  165. ol { id = "conversation"
  166. for (c of conversation) {
  167. // Runtime row/state classes have no Style-rule selection form.
  168. li { class = c.kind
  169. p { Style.pHead
  170. strong { c.author }
  171. if (c.isApp) { span { Style.spanTag "app" } }
  172. span { class = "muted" c.created }
  173. }
  174. Markdown { blocks = c.blocks }
  175. }
  176. }
  177. }
  178. if (canAct) {
  179. form { id = "commentform"
  180. on submit(e) {
  181. e.preventDefault()
  182. emit commentIt(e)
  183. }
  184. label { "Write a comment (Markdown)"
  185. textarea { id = "commentbody" name = "body" rows = "4" maxlength = "65536" required = "required" value = commentBody on input(e) { commentBody = e.target.value } }
  186. }
  187. button { id = "commentsave" type = "submit" "Comment" }
  188. }
  189. }
  190. if (readOnly) { p { id = "readonlyhint" class = "muted" "Only the owner and the members of this repository can comment here." } }
  191. }
  192. }
  193. }
  194. }
  195. // what a face answers is the page read again: every list is set from it
  196. apply = (r) => {
  197. if (r == null || r.error != null) {
  198. actError = r != null ? r.error : 'that did not work'
  199. return false
  200. }
  201. w = r.view
  202. pr = w.pr
  203. statuses = w.statuses
  204. hasStatuses = w.hasStatuses
  205. verdicts = w.verdicts
  206. hasVerdicts = w.hasVerdicts
  207. noVerdicts = !w.hasVerdicts
  208. reviews = w.reviews
  209. hasReviews = w.hasReviews
  210. noReviews = !w.hasReviews
  211. threads = w.threads
  212. hasThreads = w.hasThreads
  213. noThreads = !w.hasThreads
  214. conversation = w.conversation
  215. hasConversation = w.hasConversation
  216. noConversation = !w.hasConversation
  217. mergeClass = w.mergeClass
  218. approvals = w.approvals
  219. approvalHead = w.approvalHead
  220. approvalLabel = w.approvalLabel
  221. approved = w.approved
  222. canApprove = w.canApprove
  223. blockText = w.blockText
  224. actError = ''
  225. actNotice = r.notice != null ? r.notice : ''
  226. return true
  227. }
  228. on commentIt(e) {
  229. r = emit server gitoriaPrComment(slug, n, commentBody)
  230. if (apply(r)) { commentBody = '' }
  231. }
  232. replyIt = (threadId, body) => {
  233. r = emit server gitoriaPrReply(slug, n, threadId, body)
  234. return apply(r)
  235. }
  236. toggleThread = (threadId, resolved) => {
  237. r = emit server gitoriaPrResolve(slug, n, threadId, resolved)
  238. apply(r)
  239. }
  240. on client gitoriaPullApprovalChanged(String changedSlug, Number number, Hybrid state) {
  241. if (changedSlug != slug || pr == null || pr.number != number) { return null }
  242. applyApprovalState(state)
  243. }
  244. on client gitoriaStatusChanged(String changedSlug, String sha) {
  245. if (changedSlug != slug || pr == null || sha != approvalHead) { return null }
  246. state = emit server gitoriaPrApprovalState(slug, n)
  247. if (state != null) { applyApprovalState(state) }
  248. }
  249. on client gitoriaRequiredChanged(String changedSlug) {
  250. if (changedSlug != slug || pr == null) { return null }
  251. state = emit server gitoriaPrApprovalState(slug, n)
  252. if (state != null) { applyApprovalState(state) }
  253. }
  254. on server gitoriaPrApprovalState(String slugOf, String nText, Hybrid session) {
  255. return approvalStateFor(slugOf, nText, session)
  256. }
  257. applyApprovalState = (Hybrid state) => {
  258. if (state.head != approvalHead) {
  259. canApprove = false
  260. mergeClass = 'nomerge'
  261. blockText = 'The head changed; read the pull request again before approving.'
  262. return null
  263. }
  264. if (state.statuses != null) {
  265. statuses = state.statuses
  266. hasStatuses = state.hasStatuses
  267. }
  268. approvals = state.approvals
  269. approvalHead = state.head
  270. blockText = state.blockText
  271. approved = false
  272. for (a of state.approvals) { if (a.userId == viewerId && a.sha == state.head) { approved = true } }
  273. approvalLabel = approved ? 'Withdraw approval' : 'Approve'
  274. mergeClass = canAct && pr.state == 'open' && blockText == '' ? 'mergepr' : 'nomerge'
  275. }
  276. on approveIt() {
  277. r = emit server gitoriaPrApprove(slug, n, approvalHead, !approved)
  278. apply(r)
  279. }
  280. on server gitoriaPrApprove(String slugOf, String nText, String head, Boolean wanted, session) { return approveThePull(slugOf, nText, session, head, wanted) }
  281. on mergeIt() {
  282. r = emit server gitoriaPrMerge(slug, n)
  283. apply(r)
  284. }
  285. on askAgain(appId) {
  286. r = emit server gitoriaPrAskAgain(slug, n, appId)
  287. apply(r)
  288. }
  289. on server gitoriaPrComment(slugOf, nText, body, session) { return commentOnPull(slugOf, nText, session, body) }
  290. on server gitoriaPrReply(slugOf, nText, threadId, body, session) { return replyInThread(slugOf, nText, session, threadId, body) }
  291. on server gitoriaPrResolve(slugOf, nText, threadId, resolved, session) { return setThreadResolved(slugOf, nText, session, threadId, resolved) }
  292. on server gitoriaPrMerge(slugOf, nText, session) { return mergeThePull(slugOf, nText, session) }
  293. on server gitoriaPrAskAgain(slugOf, nText, appId, session) { return reviewAgain(slugOf, nText, session, appId) }
  294. Style {
  295. #personApprovals {
  296. listStyle = 'none'
  297. margin = '0'
  298. padding = '0'
  299. li {
  300. display = 'flex'
  301. flexWrap = 'wrap'
  302. gap = '.25rem .6rem'
  303. }
  304. }
  305. pullPage {
  306. display = 'grid'
  307. gap = '1rem'
  308. minWidth = '0'
  309. overflowWrap = 'anywhere'
  310. // Direct-child and sibling combinators have no bare language form.
  311. '> *' {
  312. margin = '0'
  313. }
  314. // Runtime and theme class predicates have no bare selector form.
  315. '.nomerge' {
  316. display = 'none'
  317. }
  318. // Runtime and theme class predicates have no bare selector form.
  319. '.muted' {
  320. fontSize = '.875rem'
  321. }
  322. }
  323. #pullmeta {
  324. display = 'flex'
  325. flexWrap = 'wrap'
  326. alignItems = 'center'
  327. gap = '.25rem .8rem'
  328. }
  329. #pullstatuses {
  330. display = 'flex'
  331. flexWrap = 'wrap'
  332. gap = '.25rem .5rem'
  333. margin = '0'
  334. padding = '0'
  335. listStyle = 'none'
  336. li {
  337. display = 'inline-flex'
  338. flexWrap = 'wrap'
  339. gap = '0 .4rem'
  340. padding = '.1rem .6rem'
  341. fontSize = '.8125rem'
  342. background = 'var(--color-background-sunken)'
  343. borderRadius = 'var(--radius-large)'
  344. }
  345. // Runtime and theme class predicates have no bare selector form.
  346. '.success' {
  347. color = 'var(--color-success)'
  348. }
  349. // Runtime and theme class predicates have no bare selector form.
  350. '.failure' {
  351. color = 'var(--color-danger)'
  352. }
  353. }
  354. #pullverdicts {
  355. display = 'grid'
  356. gap = '.25rem'
  357. margin = '0'
  358. padding = '0'
  359. listStyle = 'none'
  360. li {
  361. display = 'flex'
  362. flexWrap = 'wrap'
  363. gap = '0 .6rem'
  364. }
  365. // Runtime and theme class predicates have no bare selector form.
  366. '.approve' {
  367. color = 'var(--color-success)'
  368. }
  369. // Runtime and theme class predicates have no bare selector form.
  370. '.request_changes' {
  371. color = 'var(--color-danger)'
  372. }
  373. }
  374. #reviewagain {
  375. display = 'flex'
  376. flexWrap = 'wrap'
  377. gap = '.5rem'
  378. }
  379. #reviewlist {
  380. display = 'grid'
  381. gap = '.5rem'
  382. margin = '0'
  383. padding = '0'
  384. listStyle = 'none'
  385. li {
  386. padding = '.5rem 1rem'
  387. background = 'var(--color-surface)'
  388. borderRadius = 'var(--radius-large)'
  389. }
  390. }
  391. #threadlist {
  392. display = 'grid'
  393. gap = '.5rem'
  394. margin = '0'
  395. padding = '0'
  396. listStyle = 'none'
  397. // Direct-child and sibling combinators have no bare language form.
  398. '> li' {
  399. padding = '.5rem 1rem'
  400. background = 'var(--color-surface)'
  401. borderRadius = 'var(--radius-large)'
  402. }
  403. // Runtime and theme class predicates have no bare selector form.
  404. '.resolved' {
  405. opacity = '.75'
  406. }
  407. }
  408. #conversation {
  409. display = 'grid'
  410. gap = '.5rem'
  411. margin = '0'
  412. padding = '0'
  413. listStyle = 'none'
  414. li {
  415. padding = '.5rem 1rem'
  416. background = 'var(--color-surface)'
  417. borderRadius = 'var(--radius-large)'
  418. }
  419. }
  420. #commentform {
  421. display = 'grid'
  422. gap = '.75rem'
  423. }
  424. spanNumber {
  425. marginRight = '.5rem'
  426. color = 'var(--color-text-muted)'
  427. fontWeight = '400'
  428. }
  429. spanTag {
  430. padding = '0 .4rem'
  431. fontSize = '.75rem'
  432. background = 'var(--color-background-sunken)'
  433. borderRadius = 'var(--radius-large)'
  434. }
  435. pHead {
  436. display = 'flex'
  437. flexWrap = 'wrap'
  438. alignItems = 'center'
  439. gap = '.25rem .6rem'
  440. }
  441. spanMark {
  442. fontSize = '.875rem'
  443. color = 'var(--color-text-muted)'
  444. }
  445. olComments {
  446. display = 'grid'
  447. gap = '.5rem'
  448. margin = '0'
  449. padding = '0'
  450. listStyle = 'none'
  451. }
  452. codeWhere {
  453. fontWeight = '600'
  454. }
  455. #pullnotice {
  456. margin = '0'
  457. color = 'var(--color-success)'
  458. }
  459. #pullerror {
  460. margin = '0'
  461. color = 'var(--color-danger)'
  462. empty { display = 'none' }
  463. }
  464. }
  465. on client repoChanged(Hybrid row) {
  466. if (titleRepo != null && row.id == titleRepo.id) { __title = pageTitle(siteName, row.heading, 'Pull request ' + (n == null ? '' : '#' + n)) }
  467. }

Branches

Latest commits

  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre