gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitcd442066cd442066gitoria#43: app-auth unit test reads the apps table from its new filemrecd442066/components/pulls.hl

5.7 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, ownsRepo } from '../lib/repos.hl'
  10. import { pageTitle } from '../lib/repos-helpers.hl'
  11. import { pullsNow, mergePullNow, withMerge, pullsView } from '../lib/pulls.hl'
  12. import { withPullParts } from '../lib/tickets-helpers.hl'
  13. import { notifyPush } from '../lib/tickets.hl'
  14. import { ensurePulls, withNumbers } from '../lib/pullsync.hl'
  15. import { syncAndRaise } from '../lib/events.hl'
  16. host = null
  17. orepo = ''
  18. session = null
  19. slug = slugOfRequest(host, orepo)
  20. repo = repoAt(slug, session)
  21. hasRepo = repo != null
  22. isOwner = repo != null && ownsRepo(slug, session)
  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(withPullParts(withMerge(got.pulls, isOwner), repo.ticketsProject), 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" class = "message" mergeError }
  42. ol { id = "pulllist"
  43. for (pr of pullsList) {
  44. li {
  45. span { class = "subject" span { class = "number" pr.numberText } for (pt of pr.parts) { if (pt.isText) { a { href = pr.href pt.text } } if (pt.isLink) { a { class = "ticketref" href = pt.href pt.text } } } }
  46. span { class = pr.state pr.state }
  47. span { class = "branches"
  48. if (pr.hasSource) { a { class = "source" href = pr.sourceHref pr.source } }
  49. if (pr.noSource) { span { class = "source muted" "(branch gone)" } }
  50. span { class = "muted" "→" }
  51. if (pr.targetLinked) { a { class = "target" href = pr.targetHref pr.target } }
  52. if (pr.targetMissing) { span { class = "target muted" pr.target " (no such branch)" } }
  53. }
  54. span { class = "muted" pr.author }
  55. time { pr.date }
  56. button { class = pr.mergeClass type = "button" value = pr.sha "Merge" on click(e) { emit mergePull(e.target.value) } }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. // "Merge" (the owner, only when clicked): the face merges and answers with the list read again
  66. on mergePull(sha) {
  67. mergeError = ''
  68. r = emit server gitoriaMergePull(slug, sha)
  69. if (r == null || r.error != null) {
  70. mergeError = r != null ? r.error : 'could not merge'
  71. return null
  72. }
  73. got = r.result
  74. pullsList = r.list
  75. pullsNone = got.noPulls
  76. }
  77. on server gitoriaMergePull(slugOf, sha, session) {
  78. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not merge' } }
  79. u = userOfSession(session)
  80. if (u == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can merge a pull request' } }
  81. r = mergePullNow(slugOf, repoAt(slugOf, session).branch, sha, u.name)
  82. if (r.error != null) { return { error = r.error } }
  83. notifyPush(slugOf, false)
  84. // the pull request records follow (merged, mergeCommit) and the connected apps hear of it (lib/events.hl)
  85. syncAndRaise(slugOf, u.id)
  86. // the list again, with its ticket links made here: tickets-helpers.hl reads the environment, which the browser has not
  87. v = pullsView(slugOf, repoAt(slugOf, session).branch, true, repoAt(slugOf, session).ticketsProject)
  88. return { result = v.result list = withNumbers(v.list, slugOf) }
  89. }
  90. Style {
  91. repoPulls {
  92. display = 'grid'
  93. gap = '1rem'
  94. minWidth = '0'
  95. '> *' {
  96. margin = '0'
  97. }
  98. }
  99. #pulllist {
  100. display = 'grid'
  101. gap = '.4rem'
  102. margin = '0'
  103. padding = '0'
  104. listStyle = 'none'
  105. li {
  106. display = 'flex'
  107. flexWrap = 'wrap'
  108. alignItems = 'center'
  109. gap = '0 .8rem'
  110. margin = '0'
  111. padding = '.1rem 1rem .3rem'
  112. background = 'var(--color-surface)'
  113. borderRadius = 'var(--radius-large)'
  114. overflowWrap = 'anywhere'
  115. }
  116. '.subject' {
  117. flex = '1 1 100%'
  118. '.number' {
  119. marginRight = '.5rem'
  120. color = 'var(--color-text-muted)'
  121. fontWeight = '400'
  122. }
  123. minWidth = '0'
  124. fontWeight = '600'
  125. a {
  126. display = 'inline-block'
  127. paddingBlock = '.65rem'
  128. }
  129. 'a.ticketref' {
  130. minWidth = '2.75rem'
  131. textAlign = 'center'
  132. }
  133. }
  134. '.open' {
  135. fontSize = '.875rem'
  136. color = 'var(--color-accent)'
  137. }
  138. '.nomerge' {
  139. display = 'none'
  140. }
  141. '.merged' {
  142. fontSize = '.875rem'
  143. color = 'var(--color-text-muted)'
  144. }
  145. '.branches' {
  146. display = 'inline-flex'
  147. flexWrap = 'wrap'
  148. alignItems = 'center'
  149. gap = '0 .5rem'
  150. a {
  151. display = 'inline-flex'
  152. alignItems = 'center'
  153. justifyContent = 'center'
  154. minWidth = '2.75rem'
  155. minHeight = '2.75rem'
  156. }
  157. }
  158. 'button.mergepr' {
  159. marginLeft = 'auto'
  160. color = 'var(--color-accent-text)'
  161. background = 'var(--color-accent)'
  162. }
  163. }
  164. }

Branches

Latest commits

  • cd442066gitoria#43: app-auth unit test reads the apps table from its new filemre
  • 5dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre
  • 8c8805f3merge main (gitoria#42), delivery log and redelivery routes, sweep fixmre
  • 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
  • afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
  • 15e01e94gitoria#43: tests/events.mjs and its probemre
  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • b5d696fegitoria#42: app tokens (gat_, one hour), appOfRequest, app token as the git read passwordmre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
  • 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre
  • fdb9ed28gitoria#41: repo owners can connect an app (merge w41-apps-connect)mre
  • 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
  • 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
  • b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
  • 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
  • 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
  • c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
  • c50d17efKeep function-route not-found style in shared stylesheetmre
  • e42d78d3Preserve ticket state CSS and document function-route style gapmre
  • c6b7154eWIP gitoria#26: move styles into nested component blocksmre