gitoria

gitoria

All repositories: gitoria

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

Branches

Latest commits

  • fcf95936log: v1.5.1 provenmre
  • 22105420log: W51b livemre
  • 7e8aabeareport: W51b pull source verificationmre
  • 6c18de76fix: preserve pull sources across containing branchesmre
  • fc36fa2elog: W51b pull source bugmre
  • 56bc1220log: v1.5.1 livemre
  • 845fc0aareport: W51mre
  • 83127391fix: return v1.5.1 app and merge error detailsmre
  • b07d0e97log: W51 v1.5.1 startedmre
  • 0b417d06docs: apps-api v1.5 user tokens (#48, W49)mre
  • d046940alog: vinzenz contract note sentmre
  • db443456log: vinzenz note retry 2mre
  • 802f229alog: kunibert repo ping provenmre
  • 2d2eaa92log: Kunibert connected to kunibert repomre
  • 65d5f80alogmre
  • dab74b0dW49 report, logmre
  • fd4fc028Exercise member status reads with a populated check statemre
  • 536ca6f9Allow repository members to read pull workflow APIs with user tokensmre
  • 705dd834W49 missionmre
  • b554cd5flogmre