gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit483141d0483141d0gitoria#45: Settings shows the Apps heading only to the ownermre483141d0/components/pulls.hl

6.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, 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. import { withStatuses } from '../lib/statuses.hl'
  17. host = null
  18. orepo = ''
  19. session = null
  20. slug = slugOfRequest(host, orepo)
  21. repo = repoAt(slug, session)
  22. hasRepo = repo != null
  23. isOwner = repo != null && ownsRepo(slug, session)
  24. mergeError = ''
  25. numbered = repo != null ? ensurePulls(slug) : null
  26. got = repo != null ? pullsNow(slug, repo.branch) : null
  27. pullsShown = got != null && !got.isMessage
  28. pullsMessage = got != null && got.isMessage
  29. pullsText = got != null && got.isMessage ? got.message : ''
  30. pullsNone = got != null && !got.isMessage && got.noPulls
  31. pullsList = got != null && !got.isMessage ? withNumbers(withStatuses(withPullParts(withMerge(got.pulls, isOwner), repo.ticketsProject), slug), slug) : []
  32. pullsDefault = got != null && !got.isMessage ? got.defaultName : ''
  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" class = "message" mergeError }
  43. ol { id = "pulllist"
  44. for (pr of pullsList) {
  45. li {
  46. span { class = "subject" span { class = "number" 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. span { class = pr.state pr.state }
  48. span { class = "branches"
  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 { class = "statuses"
  56. for (st of pr.statuses) {
  57. span { class = st.cls
  58. span { class = "state" st.state }
  59. span { class = "label" st.label }
  60. span { class = "muted" st.title }
  61. }
  62. }
  63. }
  64. span { class = "muted" pr.author }
  65. time { pr.date }
  66. span { class = "blocked" pr.blockText }
  67. button { class = pr.mergeClass type = "button" value = pr.sha "Merge" on click(e) { emit mergePull(e.target.value) } }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. // "Merge" (the owner, only when clicked): the face merges and answers with the list read again
  77. on mergePull(sha) {
  78. mergeError = ''
  79. r = emit server gitoriaMergePull(slug, sha)
  80. if (r == null || r.error != null) {
  81. mergeError = r != null ? r.error : 'could not merge'
  82. return null
  83. }
  84. got = r.result
  85. pullsList = r.list
  86. pullsNone = got.noPulls
  87. }
  88. on server gitoriaMergePull(slugOf, sha, session) {
  89. if (session == null || repoAt(slugOf, session) == null) { return { error = 'could not merge' } }
  90. u = userOfSession(session)
  91. if (u == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can merge a pull request' } }
  92. r = mergePullNow(slugOf, repoAt(slugOf, session).branch, sha, u.name)
  93. if (r.error != null) { return { error = r.error } }
  94. notifyPush(slugOf, false)
  95. // the pull request records follow (merged, mergeCommit) and the connected apps hear of it (lib/events.hl)
  96. syncAndRaise(slugOf, u.id)
  97. // the list again, with its ticket links made here: tickets-helpers.hl reads the environment, which the browser has not
  98. v = pullsView(slugOf, repoAt(slugOf, session).branch, true, repoAt(slugOf, session).ticketsProject)
  99. return { result = v.result list = withNumbers(v.list, slugOf) }
  100. }
  101. Style {
  102. repoPulls {
  103. display = 'grid'
  104. gap = '1rem'
  105. minWidth = '0'
  106. '> *' {
  107. margin = '0'
  108. }
  109. }
  110. #pulllist {
  111. display = 'grid'
  112. gap = '.4rem'
  113. margin = '0'
  114. padding = '0'
  115. listStyle = 'none'
  116. li {
  117. display = 'flex'
  118. flexWrap = 'wrap'
  119. alignItems = 'center'
  120. gap = '0 .8rem'
  121. margin = '0'
  122. padding = '.1rem 1rem .3rem'
  123. background = 'var(--color-surface)'
  124. borderRadius = 'var(--radius-large)'
  125. overflowWrap = 'anywhere'
  126. }
  127. '.subject' {
  128. flex = '1 1 100%'
  129. '.number' {
  130. marginRight = '.5rem'
  131. color = 'var(--color-text-muted)'
  132. fontWeight = '400'
  133. }
  134. minWidth = '0'
  135. fontWeight = '600'
  136. a {
  137. display = 'inline-block'
  138. paddingBlock = '.65rem'
  139. }
  140. 'a.ticketref' {
  141. minWidth = '2.75rem'
  142. textAlign = 'center'
  143. }
  144. }
  145. '.open' {
  146. fontSize = '.875rem'
  147. color = 'var(--color-accent)'
  148. }
  149. '.nomerge' {
  150. display = 'none'
  151. }
  152. '.blocked' {
  153. fontSize = '.875rem'
  154. color = 'var(--color-text-muted)'
  155. }
  156. '.statuses' {
  157. display = 'flex'
  158. flex = '1 1 100%'
  159. flexWrap = 'wrap'
  160. gap = '.25rem .5rem'
  161. '.badge' {
  162. display = 'inline-flex'
  163. flexWrap = 'wrap'
  164. alignItems = 'center'
  165. gap = '0 .4rem'
  166. padding = '.1rem .6rem'
  167. fontSize = '.8125rem'
  168. background = 'var(--color-background-sunken)'
  169. borderRadius = 'var(--radius-large)'
  170. '.state' {
  171. fontWeight = '600'
  172. }
  173. }
  174. '.success' {
  175. color = 'var(--color-success)'
  176. }
  177. '.failure' {
  178. color = 'var(--color-danger)'
  179. }
  180. '.error' {
  181. color = 'var(--color-text-strong)'
  182. fontStyle = 'italic'
  183. }
  184. }
  185. '.merged' {
  186. fontSize = '.875rem'
  187. color = 'var(--color-text-muted)'
  188. }
  189. '.branches' {
  190. display = 'inline-flex'
  191. flexWrap = 'wrap'
  192. alignItems = 'center'
  193. gap = '0 .5rem'
  194. a {
  195. display = 'inline-flex'
  196. alignItems = 'center'
  197. justifyContent = 'center'
  198. minWidth = '2.75rem'
  199. minHeight = '2.75rem'
  200. }
  201. }
  202. 'button.mergepr' {
  203. marginLeft = 'auto'
  204. color = 'var(--color-accent-text)'
  205. background = 'var(--color-accent)'
  206. }
  207. }
  208. }

Branches

Latest commits

  • 483141d0gitoria#45: Settings shows the Apps heading only to the ownermre
  • e2eff8f6gitoria#45: the PR page /pulls/N with reviews, threads, verdicts, conversation, comment, reply, resolve and Review againmre
  • 7a602839gitoria#45: raiseEvent can send to one app only; people's comments, replies and resolving in reviews.hlmre
  • 0a46bf7dgitoria#47: apps API contract v1.3 (status read route, statuses + required on the pull)mre
  • 3373f7c3gitoria#38: push API contract v1.2.1, reviews, worker briefs and logmre
  • 34143d2cgitoria#46: closing brace of appComments lost in the mergemre
  • 54927c9cgitoria#46: PR statuses and required checks before merge (merge w46-status)mre
  • 187e1871gitoria#46: badges without decorative bordersmre
  • 6b022798gitoria#46: tests/status.mjs in GATESmre
  • c6162f00gitoria#46: status badges on /pulls, Required before merge in Settingsmre
  • e5a0b64egitoria#46: PUT statuses/<sha>, required contexts block the merge on the servermre
  • 26a140e3gitoria#44: reviews, inline threads, replies, conversation for apps (merge w44-reviews)mre
  • 888dbf87gitoria#44: unknown API paths answer the contract's JSON 404 and sit above the page routesmre
  • ea587d90gitoria#44: reviews with inline threads, replies, resolve and the PR conversation for apps (lib/reviews.hl, tests/reviews.mjs)mre
  • 49533a50gitoria#43: signed events to connected apps (merge w43-events)mre
  • 1a1e87d5gitoria#43: the sender never writes the apps row; Settings shows the newest deliverymre
  • 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