gitoriaLog in with ident

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit4a2d71254a2d7125initial commitmre4a2d7125/components/pulls.hl

3.4 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. // (git.hl pullsNow — hl:proc run() waits, hybriel#80): it is in the first HTML and in every hl:web navigation.
  5. parent './main.hl'
  6. import { siteName } from '../project.hl'
  7. import RepoHead from './repohead.hl'
  8. import { repoAt, pageTitle, ownsRepo } from '../repos.hl'
  9. import { pullsNow, mergePullNow, withMerge } from '../git.hl'
  10. import { slugOfHost, userOfSession } from '../users.hl'
  11. host = null
  12. session = null
  13. slug = slugOfHost(host)
  14. repo = repoAt(slug)
  15. hasRepo = repo != null
  16. isOwner = repo != null && ownsRepo(slug, session)
  17. mergeError = ''
  18. got = repo != null ? pullsNow(slug, repo.branch) : null
  19. pullsShown = got != null && !got.isMessage
  20. pullsMessage = got != null && got.isMessage
  21. pullsText = got != null && got.isMessage ? got.message : ''
  22. pullsNone = got != null && !got.isMessage && got.noPulls
  23. pullsList = got != null && !got.isMessage ? withMerge(got.pulls, isOwner) : []
  24. pullsDefault = got != null && !got.isMessage ? got.defaultName : ''
  25. __title = pageTitle(siteName, slug, 'Pull requests')
  26. View {
  27. repoPage {
  28. RepoHead { }
  29. if (hasRepo) {
  30. repoPulls { id = "pulls"
  31. if (pullsMessage) { p { id = "pullsmessage" class = "empty" pullsText } }
  32. if (pullsShown) {
  33. 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)." }
  34. if (pullsNone) { p { id = "nopulls" class = "empty" "No pull request yet." } }
  35. p { id = "mergeerror" class = "message" mergeError }
  36. ol { id = "pulllist"
  37. for (pr of pullsList) {
  38. li {
  39. a { class = "subject" href = pr.href pr.title }
  40. span { class = pr.state pr.state }
  41. span { class = "branches"
  42. if (pr.hasSource) { a { class = "source" href = pr.sourceHref pr.source } }
  43. if (pr.noSource) { span { class = "source muted" "(branch gone)" } }
  44. span { class = "muted" "→" }
  45. if (pr.targetLinked) { a { class = "target" href = pr.targetHref pr.target } }
  46. if (pr.targetMissing) { span { class = "target muted" pr.target " (no such branch)" } }
  47. }
  48. span { class = "muted" pr.author }
  49. time { pr.date }
  50. if (pr.canMerge) { button { class = "quiet mergepr" type = "button" value = pr.sha "Merge" on click(e) { emit mergePull(e.target.value) } } }
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. // "Merge" (the owner, only when clicked): the face merges and answers with the list read again
  60. on mergePull(sha) {
  61. mergeError = ''
  62. let r = emit server gitoriaMergePull(slug, sha)
  63. if (r == null || r.error != null) {
  64. mergeError = r != null ? r.error : 'could not merge'
  65. return null
  66. }
  67. got = r.result
  68. pullsList = withMerge(got.pulls, isOwner)
  69. pullsNone = got.noPulls
  70. }
  71. on server gitoriaMergePull(slugOf, sha, session) {
  72. if (session == null || repoAt(slugOf) == null) { return { error = 'could not merge' } }
  73. let u = userOfSession(session)
  74. if (u == null || !ownsRepo(slugOf, session)) { return { error = 'only the owner can merge a pull request' } }
  75. let r = mergePullNow(slugOf, repoAt(slugOf).branch, sha, u.name)
  76. if (r.error != null) { return { error = r.error } }
  77. return { result = pullsNow(slugOf, repoAt(slugOf).branch) }
  78. }

Branches

Latest commits

  • 4a2d7125initial commitmre