gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite7af3ecee7af3eceMerge branch 'w52b-approval-followup' into mainGitoriae7af3ece/components/pulls.hl

8.6 KB

  1. // components/pulls.hl — THE PULL REQUESTS of a repo (gitoria#11, gitoria#16): `/pulls` on <slug>.<domain>, its
  2. // own route. The repo head is rendered on the server from the request's host. The list comes from git (the
  3. // commits whose message starts with |||PR) on the SERVER too
  4. // (lib/pulls.hl pullsNow — hl:proc run() waits, hybriel#80): it is in the first HTML and in every hl:web navigation.
  5. parent './repo.hl'
  6. import { siteName } from '../project.hl'
  7. import { slugOfRequest } from '../lib/orgs.hl'
  8. import { userOfSession } from '../lib/users.hl'
  9. import { titleSlug, repoAt, repoBySlug, mayPush } from '../lib/repos.hl'
  10. import { pageTitle } from '../lib/repos-helpers.hl'
  11. import { pullsNow, withMerge, pullsView } from '../lib/pulls.hl'
  12. import { mergeAndAnnounce } from '../lib/pullmerge.hl'
  13. import { withPullParts } from '../lib/tickets-helpers.hl'
  14. import { ensurePulls, withNumbers } from '../lib/pullsync.hl'
  15. import { withStatuses } from '../lib/statuses.hl'
  16. host = null
  17. orepo = ''
  18. session = null
  19. slug = slugOfRequest(host, orepo)
  20. repo = repoAt(slug, session)
  21. hasRepo = repo != null
  22. mayMerge = repo != null && userOfSession(session) != null && mayPush(userOfSession(session).id, repoBySlug(slug))
  23. mergeError = ''
  24. numbered = repo != null ? ensurePulls(slug) : null
  25. got = repo != null ? pullsNow(slug, repo.branch) : null
  26. pullsShown = got != null && !got.isMessage
  27. pullsMessage = got != null && got.isMessage
  28. pullsText = got != null && got.isMessage ? got.message : ''
  29. pullsNone = got != null && !got.isMessage && got.noPulls
  30. pullsList = got != null && !got.isMessage ? withNumbers(withStatuses(withPullParts(withMerge(got.pulls, mayMerge), repo.ticketsProject), slug), slug) : []
  31. pullsDefault = got != null && !got.isMessage ? got.defaultName : ''
  32. __title = pageTitle(siteName, titleSlug(host, orepo, session), 'Pull requests')
  33. View {
  34. repoPage {
  35. if (hasRepo) {
  36. repoPulls { id = "pulls"
  37. if (pullsMessage) { p { id = "pullsmessage" class = "empty" pullsText } }
  38. if (pullsShown) {
  39. p { id = "pullshelp" class = "muted" "A commit whose message starts with " code { "|||PR " } " opens a pull request; " code { "|||PR|branch] " } " sets the target (now: " strong { pullsDefault } " by default)." }
  40. if (pullsNone) { p { id = "nopulls" class = "empty" "No pull request yet." } }
  41. p { id = "mergeerror" mergeError }
  42. ol { id = "pulllist"
  43. for (pr of pullsList) {
  44. li {
  45. span { Style.spanSubject span { Style.spanNumber pr.numberText } for (pt of pr.parts) { if (pt.isText) { a { href = pr.pageHref pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } } }
  46. // Runtime class selection has no Style-rule expression form.
  47. span { class = pr.state pr.state }
  48. span { Style.spanBranches
  49. if (pr.hasSource) { a { class = "source" href = pr.sourceHref pr.source } }
  50. if (pr.noSource) { span { class = "source muted" "(branch gone)" } }
  51. span { class = "muted" "→" }
  52. if (pr.targetLinked) { a { class = "target" href = pr.targetHref pr.target } }
  53. if (pr.targetMissing) { span { class = "target muted" pr.target " (no such branch)" } }
  54. }
  55. span { Style.spanStatuses
  56. for (st of pr.statuses) {
  57. // Runtime class selection has no Style-rule expression form.
  58. span { class = st.cls
  59. span { Style.spanPullStatusState st.state }
  60. span { class = "label" st.label }
  61. span { class = "muted" st.title }
  62. }
  63. }
  64. }
  65. span { class = "muted" pr.author }
  66. time { pr.date }
  67. span { Style.spanBlocked pr.blockText }
  68. // Runtime class selection has no Style-rule expression form.
  69. button { class = pr.mergeClass type = "button" value = pr.sha "Merge" on click(e) { emit mergePull(e.target.value) } }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
  78. // Approval payloads and requirement invalidations share the repo visibility audience.
  79. on client gitoriaPullApprovalChanged(String changedSlug, Number number, Hybrid state) {
  80. if (changedSlug == slug) { refreshPulls() }
  81. }
  82. on client gitoriaStatusChanged(String changedSlug, String sha) {
  83. if (changedSlug == slug) { refreshPulls() }
  84. }
  85. on client gitoriaRequiredChanged(String changedSlug) {
  86. if (changedSlug == slug) { refreshPulls() }
  87. }
  88. refreshPulls = () => {
  89. r = emit server gitoriaPullsRead(slug)
  90. if (r == null) { return null }
  91. pullsList = r.list
  92. pullsNone = r.result.noPulls
  93. }
  94. on server gitoriaPullsRead(String slugOf, Hybrid session) {
  95. record = repoAt(slugOf, session)
  96. if (record == null) { return null }
  97. u = userOfSession(session)
  98. canMerge = u != null && mayPush(u.id, repoBySlug(slugOf))
  99. v = pullsView(slugOf, record.branch, canMerge, record.ticketsProject)
  100. return { result = v.result list = withNumbers(v.list, slugOf) }
  101. }
  102. // "Merge" (the owner, only when clicked): the face merges and answers with the list read again
  103. on mergePull(sha) {
  104. mergeError = ''
  105. r = emit server gitoriaMergePull(slug, sha)
  106. if (r == null || r.error != null) {
  107. mergeError = r != null ? r.error : 'could not merge'
  108. return null
  109. }
  110. got = r.result
  111. pullsList = r.list
  112. pullsNone = got.noPulls
  113. }
  114. on server gitoriaMergePull(slugOf, sha, session) {
  115. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not merge' } }
  116. u = userOfSession(session)
  117. if (u == null || !mayPush(u.id, repoBySlug(slugOf))) { return { error = 'only the owner and the members of this repository can merge a pull request' } }
  118. // the merge, the pull request records (merged, mergeCommit) and the connected apps' event: lib/pullmerge.hl, the same as the API's
  119. r = mergeAndAnnounce(repoBySlug(slugOf), sha, u, '')
  120. if (r.error != null) { return { error = r.error } }
  121. // the list again, with its ticket links made here: tickets-helpers.hl reads the environment, which the browser has not
  122. v = pullsView(slugOf, repoAt(slugOf, session).branch, true, repoAt(slugOf, session).ticketsProject)
  123. return { result = v.result list = withNumbers(v.list, slugOf) }
  124. }
  125. Style {
  126. repoPulls {
  127. display = 'grid'
  128. gap = '1rem'
  129. minWidth = '0'
  130. // Direct-child and sibling combinators have no bare language form.
  131. '> *' {
  132. margin = '0'
  133. }
  134. }
  135. #pulllist {
  136. display = 'grid'
  137. gap = '.4rem'
  138. margin = '0'
  139. padding = '0'
  140. listStyle = 'none'
  141. li {
  142. display = 'flex'
  143. flexWrap = 'wrap'
  144. alignItems = 'center'
  145. gap = '0 .8rem'
  146. margin = '0'
  147. padding = '.1rem 1rem .3rem'
  148. background = 'var(--color-surface)'
  149. borderRadius = 'var(--radius-large)'
  150. overflowWrap = 'anywhere'
  151. }
  152. // Runtime and theme class predicates have no bare selector form.
  153. '.open' {
  154. fontSize = '.875rem'
  155. color = 'var(--color-accent)'
  156. }
  157. // Runtime and theme class predicates have no bare selector form.
  158. '.nomerge' {
  159. display = 'none'
  160. }
  161. // Runtime and theme class predicates have no bare selector form.
  162. '.merged' {
  163. fontSize = '.875rem'
  164. color = 'var(--color-text-muted)'
  165. }
  166. // Runtime and theme class predicates have no bare selector form.
  167. 'button.mergepr' {
  168. marginLeft = 'auto'
  169. color = 'var(--color-accent-text)'
  170. background = 'var(--color-accent)'
  171. }
  172. }
  173. spanNumber {
  174. marginRight = '.5rem'
  175. color = 'var(--color-text-muted)'
  176. fontWeight = '400'
  177. }
  178. spanPullStatusState {
  179. fontWeight = '600'
  180. }
  181. spanSubject {
  182. flex = '1 1 100%'
  183. minWidth = '0'
  184. fontWeight = '600'
  185. a {
  186. display = 'inline-block'
  187. paddingBlock = '.65rem'
  188. }
  189. // Runtime and theme class predicates have no bare selector form.
  190. 'a.ticketref' {
  191. minWidth = '2.75rem'
  192. textAlign = 'center'
  193. }
  194. }
  195. spanBranches {
  196. display = 'inline-flex'
  197. flexWrap = 'wrap'
  198. alignItems = 'center'
  199. gap = '0 .5rem'
  200. a {
  201. display = 'inline-flex'
  202. alignItems = 'center'
  203. justifyContent = 'center'
  204. minWidth = '2.75rem'
  205. minHeight = '2.75rem'
  206. }
  207. }
  208. spanStatuses {
  209. display = 'flex'
  210. flex = '1 1 100%'
  211. flexWrap = 'wrap'
  212. gap = '.25rem .5rem'
  213. // Runtime and theme class predicates have no bare selector form.
  214. '.badge' {
  215. display = 'inline-flex'
  216. flexWrap = 'wrap'
  217. alignItems = 'center'
  218. gap = '0 .4rem'
  219. padding = '.1rem .6rem'
  220. fontSize = '.8125rem'
  221. background = 'var(--color-background-sunken)'
  222. borderRadius = 'var(--radius-large)'
  223. }
  224. // Runtime and theme class predicates have no bare selector form.
  225. '.success' {
  226. color = 'var(--color-success)'
  227. }
  228. // Runtime and theme class predicates have no bare selector form.
  229. '.failure' {
  230. color = 'var(--color-danger)'
  231. }
  232. // Runtime and theme class predicates have no bare selector form.
  233. '.error' {
  234. color = 'var(--color-text-strong)'
  235. fontStyle = 'italic'
  236. }
  237. }
  238. spanBlocked {
  239. fontSize = '.875rem'
  240. color = 'var(--color-text-muted)'
  241. }
  242. #mergeerror {
  243. margin = '0'
  244. color = 'var(--color-danger)'
  245. empty { display = 'none' }
  246. }
  247. }

Branches

Latest commits

  • 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
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre
  • 55c84779Merge branch 'gp-gate-ports' into mainGitoria
  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria