gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb5435de8b5435de8|||PR person approvals: second Kunibert round (#52)mreb5435de8/components/pulls.hl

8.5 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 gitoriaRequiredChanged(String changedSlug) {
  83. if (changedSlug == slug) { refreshPulls() }
  84. }
  85. refreshPulls = () => {
  86. r = emit server gitoriaPullsRead(slug)
  87. if (r == null) { return null }
  88. pullsList = r.list
  89. pullsNone = r.result.noPulls
  90. }
  91. on server gitoriaPullsRead(String slugOf, Hybrid session) {
  92. record = repoAt(slugOf, session)
  93. if (record == null) { return null }
  94. u = userOfSession(session)
  95. canMerge = u != null && mayPush(u.id, repoBySlug(slugOf))
  96. v = pullsView(slugOf, record.branch, canMerge, record.ticketsProject)
  97. return { result = v.result list = withNumbers(v.list, slugOf) }
  98. }
  99. // "Merge" (the owner, only when clicked): the face merges and answers with the list read again
  100. on mergePull(sha) {
  101. mergeError = ''
  102. r = emit server gitoriaMergePull(slug, sha)
  103. if (r == null || r.error != null) {
  104. mergeError = r != null ? r.error : 'could not merge'
  105. return null
  106. }
  107. got = r.result
  108. pullsList = r.list
  109. pullsNone = got.noPulls
  110. }
  111. on server gitoriaMergePull(slugOf, sha, session) {
  112. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not merge' } }
  113. u = userOfSession(session)
  114. if (u == null || !mayPush(u.id, repoBySlug(slugOf))) { return { error = 'only the owner and the members of this repository can merge a pull request' } }
  115. // the merge, the pull request records (merged, mergeCommit) and the connected apps' event: lib/pullmerge.hl, the same as the API's
  116. r = mergeAndAnnounce(repoBySlug(slugOf), sha, u, '')
  117. if (r.error != null) { return { error = r.error } }
  118. // the list again, with its ticket links made here: tickets-helpers.hl reads the environment, which the browser has not
  119. v = pullsView(slugOf, repoAt(slugOf, session).branch, true, repoAt(slugOf, session).ticketsProject)
  120. return { result = v.result list = withNumbers(v.list, slugOf) }
  121. }
  122. Style {
  123. repoPulls {
  124. display = 'grid'
  125. gap = '1rem'
  126. minWidth = '0'
  127. // Direct-child and sibling combinators have no bare language form.
  128. '> *' {
  129. margin = '0'
  130. }
  131. }
  132. #pulllist {
  133. display = 'grid'
  134. gap = '.4rem'
  135. margin = '0'
  136. padding = '0'
  137. listStyle = 'none'
  138. li {
  139. display = 'flex'
  140. flexWrap = 'wrap'
  141. alignItems = 'center'
  142. gap = '0 .8rem'
  143. margin = '0'
  144. padding = '.1rem 1rem .3rem'
  145. background = 'var(--color-surface)'
  146. borderRadius = 'var(--radius-large)'
  147. overflowWrap = 'anywhere'
  148. }
  149. // Runtime and theme class predicates have no bare selector form.
  150. '.open' {
  151. fontSize = '.875rem'
  152. color = 'var(--color-accent)'
  153. }
  154. // Runtime and theme class predicates have no bare selector form.
  155. '.nomerge' {
  156. display = 'none'
  157. }
  158. // Runtime and theme class predicates have no bare selector form.
  159. '.merged' {
  160. fontSize = '.875rem'
  161. color = 'var(--color-text-muted)'
  162. }
  163. // Runtime and theme class predicates have no bare selector form.
  164. 'button.mergepr' {
  165. marginLeft = 'auto'
  166. color = 'var(--color-accent-text)'
  167. background = 'var(--color-accent)'
  168. }
  169. }
  170. spanNumber {
  171. marginRight = '.5rem'
  172. color = 'var(--color-text-muted)'
  173. fontWeight = '400'
  174. }
  175. spanPullStatusState {
  176. fontWeight = '600'
  177. }
  178. spanSubject {
  179. flex = '1 1 100%'
  180. minWidth = '0'
  181. fontWeight = '600'
  182. a {
  183. display = 'inline-block'
  184. paddingBlock = '.65rem'
  185. }
  186. // Runtime and theme class predicates have no bare selector form.
  187. 'a.ticketref' {
  188. minWidth = '2.75rem'
  189. textAlign = 'center'
  190. }
  191. }
  192. spanBranches {
  193. display = 'inline-flex'
  194. flexWrap = 'wrap'
  195. alignItems = 'center'
  196. gap = '0 .5rem'
  197. a {
  198. display = 'inline-flex'
  199. alignItems = 'center'
  200. justifyContent = 'center'
  201. minWidth = '2.75rem'
  202. minHeight = '2.75rem'
  203. }
  204. }
  205. spanStatuses {
  206. display = 'flex'
  207. flex = '1 1 100%'
  208. flexWrap = 'wrap'
  209. gap = '.25rem .5rem'
  210. // Runtime and theme class predicates have no bare selector form.
  211. '.badge' {
  212. display = 'inline-flex'
  213. flexWrap = 'wrap'
  214. alignItems = 'center'
  215. gap = '0 .4rem'
  216. padding = '.1rem .6rem'
  217. fontSize = '.8125rem'
  218. background = 'var(--color-background-sunken)'
  219. borderRadius = 'var(--radius-large)'
  220. }
  221. // Runtime and theme class predicates have no bare selector form.
  222. '.success' {
  223. color = 'var(--color-success)'
  224. }
  225. // Runtime and theme class predicates have no bare selector form.
  226. '.failure' {
  227. color = 'var(--color-danger)'
  228. }
  229. // Runtime and theme class predicates have no bare selector form.
  230. '.error' {
  231. color = 'var(--color-text-strong)'
  232. fontStyle = 'italic'
  233. }
  234. }
  235. spanBlocked {
  236. fontSize = '.875rem'
  237. color = 'var(--color-text-muted)'
  238. }
  239. #mergeerror {
  240. margin = '0'
  241. color = 'var(--color-danger)'
  242. empty { display = 'none' }
  243. }
  244. }

Branches

Latest commits

  • 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
  • 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
  • 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
  • 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria
  • 698458e2|||PR No session for cookieless login errors: READMEmre
  • cce7b785|||PR No session for cookieless login errorsmre
  • 678d6303Merge branch 'v59' into mainGitoria