gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita4a33081a4a33081Merge branch 'w63-force-push' into mainGitoriaa4a33081/components/pull.hl

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

Branches

Latest commits

  • a4a33081Merge branch 'w63-force-push' into mainGitoria
  • 52576cb0force push: defer on a failed scan, one-to-one pairs, docs (#56)mre
  • 5a7b3e68|||PR a force push keeps the same pull request (#56)mre
  • cc1be2d6Merge branch 'w62-pr-close' into mainGitoria
  • 6e03be0apull state: keep the resync marker until the sync ran (#56)mre
  • 93bdd26cpull state: wait for a claimed row, resync when it stays busy (#56)mre
  • e53d284bpull state: stop on a failed branch scan, claim the row on writes (#56)mre
  • d8608224close and reopen: keep a manual close against sync (#56)mre
  • ffb60746|||PR close and reopen pull requests (#56)mre
  • 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