gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitfa0754c8fa0754c8|||PR repository owner transfer and members API (#55)mrefa0754c8/components/pulls.hl

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

Branches

Latest commits

  • 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
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre