gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitd8608224d8608224close and reopen: keep a manual close against sync (#56)mred8608224/components/pulls.hl

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

Branches

Latest commits

  • 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
  • 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