ref0-git 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/app/apps/github/.dev.vars.example +6 -0
  2. package/app/apps/github/README.md +70 -0
  3. package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
  4. package/app/apps/github/components.json +25 -0
  5. package/app/apps/github/generated/git-rest.ts +10444 -0
  6. package/app/apps/github/generated/routeTree.gen.ts +1242 -0
  7. package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
  8. package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
  9. package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
  10. package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
  11. package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
  12. package/app/apps/github/package.json +80 -0
  13. package/app/apps/github/src/branches/branch-list.tsx +385 -0
  14. package/app/apps/github/src/branches/branches.ts +55 -0
  15. package/app/apps/github/src/clients/allowed.ts +213 -0
  16. package/app/apps/github/src/clients/at-most.ts +17 -0
  17. package/app/apps/github/src/clients/avatars.ts +410 -0
  18. package/app/apps/github/src/clients/cached.ts +65 -0
  19. package/app/apps/github/src/clients/calls.ts +160 -0
  20. package/app/apps/github/src/clients/clients.ts +82 -0
  21. package/app/apps/github/src/clients/graphql.ts +50 -0
  22. package/app/apps/github/src/clients/host-answer.ts +28 -0
  23. package/app/apps/github/src/clients/host-calls.ts +382 -0
  24. package/app/apps/github/src/clients/icon-bytes.ts +203 -0
  25. package/app/apps/github/src/clients/proxy.ts +59 -0
  26. package/app/apps/github/src/clients/session-ended.ts +18 -0
  27. package/app/apps/github/src/clients/transfers.ts +212 -0
  28. package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
  29. package/app/apps/github/src/code/code-page.tsx +147 -0
  30. package/app/apps/github/src/code/code-tree.tsx +338 -0
  31. package/app/apps/github/src/code/controls.tsx +230 -0
  32. package/app/apps/github/src/code/file-view.tsx +450 -0
  33. package/app/apps/github/src/code/files.ts +332 -0
  34. package/app/apps/github/src/code/folder-list.tsx +122 -0
  35. package/app/apps/github/src/code/go-to-file.tsx +131 -0
  36. package/app/apps/github/src/code/highlighted.tsx +58 -0
  37. package/app/apps/github/src/code/lines.ts +46 -0
  38. package/app/apps/github/src/code/load.ts +147 -0
  39. package/app/apps/github/src/code/markdown-files.ts +58 -0
  40. package/app/apps/github/src/code/places.ts +88 -0
  41. package/app/apps/github/src/code/ref-pages.ts +179 -0
  42. package/app/apps/github/src/code/ref-switcher.tsx +203 -0
  43. package/app/apps/github/src/code/refs.ts +142 -0
  44. package/app/apps/github/src/code/repo-home.tsx +240 -0
  45. package/app/apps/github/src/code/repo.ts +105 -0
  46. package/app/apps/github/src/code/saved-reads.ts +199 -0
  47. package/app/apps/github/src/code/saved.ts +110 -0
  48. package/app/apps/github/src/code/tree-fold.ts +186 -0
  49. package/app/apps/github/src/code/trees.ts +136 -0
  50. package/app/apps/github/src/components/avatar-picture.ts +53 -0
  51. package/app/apps/github/src/components/avatar-url.ts +16 -0
  52. package/app/apps/github/src/components/confirm-action.tsx +100 -0
  53. package/app/apps/github/src/components/count.tsx +24 -0
  54. package/app/apps/github/src/components/create-button.tsx +38 -0
  55. package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
  56. package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
  57. package/app/apps/github/src/components/filter.tsx +35 -0
  58. package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
  59. package/app/apps/github/src/components/item-list.tsx +65 -0
  60. package/app/apps/github/src/components/language-dot.tsx +29 -0
  61. package/app/apps/github/src/components/list-toolbar.tsx +82 -0
  62. package/app/apps/github/src/components/markdown/editor.tsx +57 -0
  63. package/app/apps/github/src/components/markdown/markdown.css +177 -0
  64. package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
  65. package/app/apps/github/src/components/owner-card.tsx +196 -0
  66. package/app/apps/github/src/components/pull-status.tsx +34 -0
  67. package/app/apps/github/src/components/recent.ts +41 -0
  68. package/app/apps/github/src/components/relative-time.tsx +78 -0
  69. package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
  70. package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
  71. package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
  72. package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
  73. package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
  74. package/app/apps/github/src/components/review-state.tsx +75 -0
  75. package/app/apps/github/src/components/route-dialog.tsx +137 -0
  76. package/app/apps/github/src/components/save-button.tsx +58 -0
  77. package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
  78. package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
  79. package/app/apps/github/src/components/shell/create-row.tsx +49 -0
  80. package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
  81. package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
  82. package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
  83. package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
  84. package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
  85. package/app/apps/github/src/components/shell/sections.ts +31 -0
  86. package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
  87. package/app/apps/github/src/components/signin/device-card.tsx +139 -0
  88. package/app/apps/github/src/components/signin/login-form.tsx +88 -0
  89. package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
  90. package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
  91. package/app/apps/github/src/components/states/live-status.tsx +42 -0
  92. package/app/apps/github/src/components/states/states.tsx +126 -0
  93. package/app/apps/github/src/components/tab-indicator.tsx +143 -0
  94. package/app/apps/github/src/components/theme-choice.tsx +108 -0
  95. package/app/apps/github/src/components/theme-provider.tsx +126 -0
  96. package/app/apps/github/src/components/tones.ts +23 -0
  97. package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
  98. package/app/apps/github/src/components/ui/alert.tsx +78 -0
  99. package/app/apps/github/src/components/ui/avatar.tsx +106 -0
  100. package/app/apps/github/src/components/ui/badge.tsx +51 -0
  101. package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
  102. package/app/apps/github/src/components/ui/button-group.tsx +87 -0
  103. package/app/apps/github/src/components/ui/button.tsx +61 -0
  104. package/app/apps/github/src/components/ui/calendar.tsx +221 -0
  105. package/app/apps/github/src/components/ui/card.tsx +102 -0
  106. package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
  107. package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
  108. package/app/apps/github/src/components/ui/combobox.tsx +304 -0
  109. package/app/apps/github/src/components/ui/command.tsx +208 -0
  110. package/app/apps/github/src/components/ui/dialog.tsx +156 -0
  111. package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
  112. package/app/apps/github/src/components/ui/empty.tsx +100 -0
  113. package/app/apps/github/src/components/ui/field.tsx +236 -0
  114. package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
  115. package/app/apps/github/src/components/ui/input-group.tsx +163 -0
  116. package/app/apps/github/src/components/ui/input.tsx +19 -0
  117. package/app/apps/github/src/components/ui/item.tsx +201 -0
  118. package/app/apps/github/src/components/ui/kbd.tsx +27 -0
  119. package/app/apps/github/src/components/ui/label.tsx +33 -0
  120. package/app/apps/github/src/components/ui/popover.tsx +87 -0
  121. package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
  122. package/app/apps/github/src/components/ui/select.tsx +198 -0
  123. package/app/apps/github/src/components/ui/separator.tsx +22 -0
  124. package/app/apps/github/src/components/ui/sheet.tsx +138 -0
  125. package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
  126. package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
  127. package/app/apps/github/src/components/ui/sonner.tsx +47 -0
  128. package/app/apps/github/src/components/ui/styles.css +242 -0
  129. package/app/apps/github/src/components/ui/table.tsx +113 -0
  130. package/app/apps/github/src/components/ui/tabs.tsx +79 -0
  131. package/app/apps/github/src/components/ui/textarea.tsx +17 -0
  132. package/app/apps/github/src/components/ui/title.ts +6 -0
  133. package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
  134. package/app/apps/github/src/components/ui/toggle.tsx +42 -0
  135. package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
  136. package/app/apps/github/src/components/user-avatar.tsx +145 -0
  137. package/app/apps/github/src/components/view-tabs.tsx +42 -0
  138. package/app/apps/github/src/context/context.ts +133 -0
  139. package/app/apps/github/src/diffs/blobs.ts +94 -0
  140. package/app/apps/github/src/diffs/diff-view.tsx +155 -0
  141. package/app/apps/github/src/diffs/files.ts +121 -0
  142. package/app/apps/github/src/diffs/hunks.tsx +454 -0
  143. package/app/apps/github/src/diffs/patch.ts +131 -0
  144. package/app/apps/github/src/diffs/rows.ts +137 -0
  145. package/app/apps/github/src/history/commit-diff.ts +54 -0
  146. package/app/apps/github/src/history/commit-list.tsx +207 -0
  147. package/app/apps/github/src/history/commit-page.tsx +147 -0
  148. package/app/apps/github/src/history/history.ts +129 -0
  149. package/app/apps/github/src/hooks/allowed.ts +31 -0
  150. package/app/apps/github/src/hooks/answers.ts +65 -0
  151. package/app/apps/github/src/hooks/avatars.ts +54 -0
  152. package/app/apps/github/src/hooks/draft.ts +38 -0
  153. package/app/apps/github/src/hooks/open-counts.ts +127 -0
  154. package/app/apps/github/src/hooks/profiles.ts +120 -0
  155. package/app/apps/github/src/hooks/repos.ts +440 -0
  156. package/app/apps/github/src/hooks/use-mobile.ts +19 -0
  157. package/app/apps/github/src/hooks/viewer.ts +39 -0
  158. package/app/apps/github/src/inbox/count.ts +70 -0
  159. package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
  160. package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
  161. package/app/apps/github/src/inbox/marks.ts +130 -0
  162. package/app/apps/github/src/inbox/release-tags.ts +65 -0
  163. package/app/apps/github/src/inbox/search.ts +97 -0
  164. package/app/apps/github/src/inbox/subjects.ts +184 -0
  165. package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
  166. package/app/apps/github/src/inbox/subscriptions.ts +189 -0
  167. package/app/apps/github/src/inbox/threads.ts +198 -0
  168. package/app/apps/github/src/issues/changes.ts +332 -0
  169. package/app/apps/github/src/issues/counts.ts +62 -0
  170. package/app/apps/github/src/issues/issue-list.tsx +682 -0
  171. package/app/apps/github/src/issues/issue-page.tsx +533 -0
  172. package/app/apps/github/src/issues/issues.ts +566 -0
  173. package/app/apps/github/src/issues/label-dialog.tsx +310 -0
  174. package/app/apps/github/src/issues/labels-page.tsx +119 -0
  175. package/app/apps/github/src/issues/new-issue.tsx +79 -0
  176. package/app/apps/github/src/issues/parts.tsx +71 -0
  177. package/app/apps/github/src/issues/picker.tsx +298 -0
  178. package/app/apps/github/src/issues/search.ts +238 -0
  179. package/app/apps/github/src/issues/sidebar.tsx +236 -0
  180. package/app/apps/github/src/lib/cn.ts +8 -0
  181. package/app/apps/github/src/lib/highlighting.ts +13 -0
  182. package/app/apps/github/src/live/follow.ts +129 -0
  183. package/app/apps/github/src/live/sse.ts +74 -0
  184. package/app/apps/github/src/live/use-follow.ts +37 -0
  185. package/app/apps/github/src/markdown/README.md +53 -0
  186. package/app/apps/github/src/markdown/allowed-html.ts +69 -0
  187. package/app/apps/github/src/markdown/context.ts +206 -0
  188. package/app/apps/github/src/markdown/images.ts +81 -0
  189. package/app/apps/github/src/markdown/lookup.ts +122 -0
  190. package/app/apps/github/src/markdown/patches.ts +299 -0
  191. package/app/apps/github/src/markdown/query.ts +25 -0
  192. package/app/apps/github/src/markdown/references.ts +158 -0
  193. package/app/apps/github/src/markdown/render.ts +103 -0
  194. package/app/apps/github/src/names/owners.ts +51 -0
  195. package/app/apps/github/src/names/repos.ts +24 -0
  196. package/app/apps/github/src/palette/palette.tsx +547 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +455 -0
  199. package/app/apps/github/src/palette/server.ts +104 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +600 -0
  202. package/app/apps/github/src/private-repos.ts +47 -0
  203. package/app/apps/github/src/pulls/compare-page.tsx +342 -0
  204. package/app/apps/github/src/pulls/files-tab.tsx +776 -0
  205. package/app/apps/github/src/pulls/live.ts +124 -0
  206. package/app/apps/github/src/pulls/merge-box.tsx +367 -0
  207. package/app/apps/github/src/pulls/merge-button.ts +86 -0
  208. package/app/apps/github/src/pulls/pull-list.tsx +235 -0
  209. package/app/apps/github/src/pulls/pull-page.tsx +474 -0
  210. package/app/apps/github/src/pulls/pull.ts +468 -0
  211. package/app/apps/github/src/pulls/pulls.ts +318 -0
  212. package/app/apps/github/src/pulls/review.ts +350 -0
  213. package/app/apps/github/src/pulls/search.ts +130 -0
  214. package/app/apps/github/src/queue/queue-page.tsx +405 -0
  215. package/app/apps/github/src/queue/queue.ts +231 -0
  216. package/app/apps/github/src/releases/latest-release.tsx +55 -0
  217. package/app/apps/github/src/releases/overview.tsx +30 -0
  218. package/app/apps/github/src/releases/release-form.tsx +353 -0
  219. package/app/apps/github/src/releases/release-list.tsx +173 -0
  220. package/app/apps/github/src/releases/release-view.tsx +183 -0
  221. package/app/apps/github/src/releases/releases.ts +308 -0
  222. package/app/apps/github/src/releases/tag-list.tsx +134 -0
  223. package/app/apps/github/src/router.tsx +46 -0
  224. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
  225. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
  226. package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
  227. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
  228. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
  229. package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
  230. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
  231. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
  232. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
  233. package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
  234. package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
  235. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
  236. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
  237. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
  238. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
  239. package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
  240. package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
  241. package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
  242. package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
  243. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
  244. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
  245. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
  246. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
  247. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
  248. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
  249. package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
  250. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
  251. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
  252. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
  253. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
  254. package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
  255. package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
  256. package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
  257. package/app/apps/github/src/routes/$owner/index.tsx +45 -0
  258. package/app/apps/github/src/routes/-nav.tsx +293 -0
  259. package/app/apps/github/src/routes/-root-testing.ts +107 -0
  260. package/app/apps/github/src/routes/__root.tsx +225 -0
  261. package/app/apps/github/src/routes/api.auth.$.ts +18 -0
  262. package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
  263. package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
  264. package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
  265. package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
  266. package/app/apps/github/src/routes/icons/index.tsx +12 -0
  267. package/app/apps/github/src/routes/index.tsx +48 -0
  268. package/app/apps/github/src/routes/login.tsx +24 -0
  269. package/app/apps/github/src/routes/login_.code.tsx +31 -0
  270. package/app/apps/github/src/routes/new.tsx +91 -0
  271. package/app/apps/github/src/routes/notifications.tsx +20 -0
  272. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
  273. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
  274. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
  275. package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
  276. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
  277. package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
  278. package/app/apps/github/src/routes/settings.tsx +54 -0
  279. package/app/apps/github/src/routes/signup.tsx +24 -0
  280. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
  281. package/app/apps/github/src/seed/acme.ts +498 -0
  282. package/app/apps/github/src/seed/licenses.ts +114 -0
  283. package/app/apps/github/src/seed/seed.ts +538 -0
  284. package/app/apps/github/src/server.ts +97 -0
  285. package/app/apps/github/src/settings/account-avatar.tsx +43 -0
  286. package/app/apps/github/src/settings/avatar-section.tsx +140 -0
  287. package/app/apps/github/src/settings/avatar.ts +58 -0
  288. package/app/apps/github/src/settings/general-settings.tsx +439 -0
  289. package/app/apps/github/src/settings/general.ts +73 -0
  290. package/app/apps/github/src/settings/hook-form.tsx +195 -0
  291. package/app/apps/github/src/settings/hook-list.tsx +166 -0
  292. package/app/apps/github/src/settings/hooks.ts +87 -0
  293. package/app/apps/github/src/settings/org-settings.tsx +228 -0
  294. package/app/apps/github/src/settings/orgs.ts +116 -0
  295. package/app/apps/github/src/settings/rule-list.tsx +72 -0
  296. package/app/apps/github/src/settings/rules.ts +27 -0
  297. package/app/apps/github/src/settings/settings-layout.tsx +114 -0
  298. package/app/apps/github/src/signin/approval.ts +186 -0
  299. package/app/apps/github/src/signin/auth-client.ts +127 -0
  300. package/app/apps/github/src/signin/auth.ts +753 -0
  301. package/app/apps/github/src/signin/avatars.ts +126 -0
  302. package/app/apps/github/src/signin/client-ip.ts +39 -0
  303. package/app/apps/github/src/signin/credentials.ts +26 -0
  304. package/app/apps/github/src/signin/device-code.ts +95 -0
  305. package/app/apps/github/src/signin/device-prompt.ts +125 -0
  306. package/app/apps/github/src/signin/errors.ts +135 -0
  307. package/app/apps/github/src/signin/host-session.ts +68 -0
  308. package/app/apps/github/src/signin/orgs.ts +283 -0
  309. package/app/apps/github/src/signin/owner-names.ts +183 -0
  310. package/app/apps/github/src/signin/person-lock.ts +104 -0
  311. package/app/apps/github/src/signin/seal.ts +88 -0
  312. package/app/apps/github/src/signin/seed-people.ts +92 -0
  313. package/app/apps/github/src/signin/session.ts +48 -0
  314. package/app/apps/github/src/signin/unborn.ts +110 -0
  315. package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
  316. package/app/apps/github/src/signin/viewer.ts +74 -0
  317. package/app/apps/github/src/signin/with-headers.ts +14 -0
  318. package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
  319. package/app/apps/github/src/tokens/tokens.ts +54 -0
  320. package/app/apps/github/tsconfig.json +25 -0
  321. package/app/apps/github/tsconfig.worker.json +24 -0
  322. package/app/apps/github/vite.config.ts +21 -0
  323. package/app/pnpm-workspace.yaml +216 -0
  324. package/app/tsconfig.base.json +127 -0
  325. package/dist/LICENSE +202 -0
  326. package/dist/cli/child.mjs +42 -0
  327. package/dist/cli/commands.mjs +23 -0
  328. package/dist/cli/credentials.mjs +84 -0
  329. package/dist/cli/documents.mjs +214 -0
  330. package/dist/cli/events.mjs +55 -0
  331. package/dist/cli/failure.mjs +105 -0
  332. package/dist/cli/folders.mjs +32 -0
  333. package/dist/cli/git-remote-ref0.d.mts +1 -0
  334. package/dist/cli/git-remote-ref0.mjs +29 -0
  335. package/dist/cli/git.mjs +48 -0
  336. package/dist/cli/helpers.mjs +51 -0
  337. package/dist/cli/hosts.mjs +127 -0
  338. package/dist/cli/node.mjs +15 -0
  339. package/dist/cli/output.mjs +135 -0
  340. package/dist/cli/prompt.mjs +35 -0
  341. package/dist/cli/queue.mjs +215 -0
  342. package/dist/cli/ref0-git.d.mts +1 -0
  343. package/dist/cli/ref0-git.mjs +144 -0
  344. package/dist/cli/repos.mjs +162 -0
  345. package/dist/cli/resources.mjs +131 -0
  346. package/dist/cli/run-end.mjs +57 -0
  347. package/dist/cli/runtime.mjs +50 -0
  348. package/dist/cli/setup.mjs +1410 -0
  349. package/dist/cli/sign-in.mjs +162 -0
  350. package/dist/cli/sign-ins.mjs +79 -0
  351. package/dist/cli/sqlite.mjs +28 -0
  352. package/dist/cli/tokens.mjs +141 -0
  353. package/dist/cli/vendor.mjs +123 -0
  354. package/dist/init/app.mjs +231 -0
  355. package/dist/init/astro.mjs +49 -0
  356. package/dist/init/choices.mjs +497 -0
  357. package/dist/init/cloudflare.mjs +324 -0
  358. package/dist/init/create.mjs +151 -0
  359. package/dist/init/detect.mjs +297 -0
  360. package/dist/init/files.mjs +75 -0
  361. package/dist/init/frameworks.mjs +248 -0
  362. package/dist/init/git-module.mjs +49 -0
  363. package/dist/init/github-routes.mjs +66 -0
  364. package/dist/init/jsonc.mjs +143 -0
  365. package/dist/init/metadata.mjs +48 -0
  366. package/dist/init/mounts.mjs +109 -0
  367. package/dist/init/next.mjs +205 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +458 -0
  370. package/dist/init/nuxt.mjs +115 -0
  371. package/dist/init/output.mjs +21 -0
  372. package/dist/init/plan.mjs +82 -0
  373. package/dist/init/range-major.mjs +257 -0
  374. package/dist/init/react-router.mjs +59 -0
  375. package/dist/init/routes.mjs +148 -0
  376. package/dist/init/shell.mjs +4 -0
  377. package/dist/init/stores.mjs +51 -0
  378. package/dist/init/sveltekit.mjs +139 -0
  379. package/dist/init/template.mjs +142 -0
  380. package/dist/init/templates.mjs +343 -0
  381. package/dist/init/vercel.mjs +383 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +48 -6
  385. package/README.md +0 -5
@@ -0,0 +1,124 @@
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import * as Option from 'effect/Option';
3
+ import * as Schema from 'effect/Schema';
4
+
5
+ import { callAt } from '../clients/clients.ts';
6
+ import type { RepoPlace } from '../code/places.ts';
7
+ import type { Ending, Followed } from '../live/follow.ts';
8
+ import type { StreamMessage } from '../live/sse.ts';
9
+ import { refreshPull } from './pull.ts';
10
+ import { refreshReviews } from './review.ts';
11
+
12
+ /** The five kinds of change a pull request's Event Stream sends, as GitHub names them. */
13
+ const pullEvents = {
14
+ review: 'com.github.pull_request.review.submitted.v1',
15
+ state: 'com.github.pull_request.state.changed.v1',
16
+ head: 'com.github.pull_request.head.changed.v1',
17
+ conflict: 'com.github.pull_request.merge_conflict.v1',
18
+ checks: 'com.github.pull_request.check_suite.status.changed.v1',
19
+ } as const;
20
+
21
+ /**
22
+ * A cursor past any event, as `Last-Event-ID` sends it: a stream starts after the lower of it and
23
+ * the log's position now, so it sends only what happens from now on, to this tab alone. A stream
24
+ * without one would start at its subscription's cursor, which the viewer's other tabs share.
25
+ */
26
+ const fromNow = '999999999999999';
27
+
28
+ /** What `POST /event-subscriptions` answers, in the field the page reads. */
29
+ const decodeSubscription = Schema.decodeUnknownOption(Schema.Struct({ events_url: Schema.String }));
30
+
31
+ /** Why `github.stream.end` ended a stream, from its data: none when it doesn't say. */
32
+ const decodeEnd = Schema.decodeUnknownOption(
33
+ Schema.fromJsonString(Schema.Struct({ reason: Schema.optional(Schema.String) })),
34
+ );
35
+
36
+ /** An absolute URL the drop-in names, as a path under its REST's base: `/event-subscriptions/…`. */
37
+ const apiPathOf = (url: string) => {
38
+ const { pathname } = new URL(url);
39
+
40
+ return pathname.startsWith('/api/v3/') ? pathname.slice('/api/v3'.length) : undefined;
41
+ };
42
+
43
+ /**
44
+ * Subscribes the viewer to pull request `number`'s changes, or finds the subscription they hold,
45
+ * and opens its stream after `cursor`. A subscription lasts a day, so each opening asks again.
46
+ */
47
+ const openPullStream = async (
48
+ origin: () => string,
49
+ place: RepoPlace,
50
+ number: number,
51
+ cursor: string | undefined,
52
+ signal: AbortSignal,
53
+ ) => {
54
+ const resource = `${origin()}/${place.owner}/${place.repo}/pull/${number}`;
55
+ const subscribed = await callAt('github', '/event-subscriptions', {
56
+ method: 'POST',
57
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
58
+ body: JSON.stringify({ resource_url: resource, event_types: Object.values(pullEvents) }),
59
+ signal,
60
+ });
61
+ if (!subscribed.ok) return subscribed;
62
+
63
+ const subscription = decodeSubscription(await subscribed.json());
64
+ const path = Option.isSome(subscription) ? apiPathOf(subscription.value.events_url) : undefined;
65
+ if (path === undefined) return new Response(null, { status: 502 });
66
+
67
+ const headers = new Headers({ accept: 'text/event-stream' });
68
+ if (cursor !== undefined) headers.set('last-event-id', cursor);
69
+
70
+ return callAt('github', path, { headers, signal });
71
+ };
72
+
73
+ /** How `github.stream.end` ends a stream: it says why in its data. */
74
+ const endingOf = (data: string): Ending => {
75
+ const reason = Option.getOrUndefined(decodeEnd(data))?.reason;
76
+ if (reason === 'access_revoked') return 'signed-out';
77
+
78
+ // Past a gap, the cursor is behind what the drop-in keeps: the page reads everything again.
79
+ return reason === 'history_expired' ? 'restart' : 'reconnect';
80
+ };
81
+
82
+ /** Reads again what `message` says changed on pull request `number`. */
83
+ const refreshFor = (client: QueryClient, place: RepoPlace, number: number, type: string) => {
84
+ switch (type) {
85
+ case pullEvents.review:
86
+ return refreshReviews(client, place, number);
87
+ case pullEvents.checks:
88
+ return client.invalidateQueries({ queryKey: ['checks', place.owner, place.repo] });
89
+ default:
90
+ return Promise.all([
91
+ refreshPull(client, place, number),
92
+ client.invalidateQueries({ queryKey: ['pull-commits', place.owner, place.repo, number] }),
93
+ client.invalidateQueries({ queryKey: ['queued', place.owner, place.repo] }),
94
+ ]);
95
+ }
96
+ };
97
+
98
+ /**
99
+ * Pull request `number`'s Event Stream, as the page served at `origin` follows it, read as each
100
+ * opening subscribes: each event reads again what its `api_url` names, and an opening from now
101
+ * reads the whole page again, since the stream gives nothing from before it.
102
+ */
103
+ export const pullStream = (
104
+ origin: () => string,
105
+ client: QueryClient,
106
+ place: RepoPlace,
107
+ number: number,
108
+ ): Omit<Followed, 'state'> => ({
109
+ start: fromNow,
110
+ open: (cursor, signal) => openPullStream(origin, place, number, cursor, signal),
111
+ opened: (fresh) => {
112
+ if (!fresh) return;
113
+
114
+ for (const type of [pullEvents.review, pullEvents.head, pullEvents.checks])
115
+ void refreshFor(client, place, number, type);
116
+ },
117
+ receive: (message: StreamMessage) => {
118
+ if (message.event === 'github.stream.end') return endingOf(message.data);
119
+
120
+ void refreshFor(client, place, number, message.event);
121
+
122
+ return undefined;
123
+ },
124
+ });
@@ -0,0 +1,367 @@
1
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
2
+ import {
3
+ ChevronDownIcon,
4
+ CircleAlertIcon,
5
+ CircleCheckIcon,
6
+ CircleDotIcon,
7
+ GitMergeIcon,
8
+ ListOrderedIcon,
9
+ LoaderCircleIcon,
10
+ } from 'lucide-react';
11
+ import { useEffect, useState, type ReactNode } from 'react';
12
+ import { toast } from 'sonner';
13
+
14
+ import type { PageOperation } from '../clients/allowed.ts';
15
+ import { Go } from '../code/controls.tsx';
16
+ import type { RepoPlace } from '../code/places.ts';
17
+ import type { MergeMethod, Repo } from '../code/repo.ts';
18
+ import { ConfirmAction } from '../components/confirm-action.tsx';
19
+ import { Button } from '../components/ui/button.tsx';
20
+ import { ButtonGroup, ButtonGroupSeparator } from '../components/ui/button-group.tsx';
21
+ import { Card, CardContent, CardHeader } from '../components/ui/card.tsx';
22
+ import {
23
+ DropdownMenu,
24
+ DropdownMenuContent,
25
+ DropdownMenuGroup,
26
+ DropdownMenuRadioGroup,
27
+ DropdownMenuRadioItem,
28
+ DropdownMenuTrigger,
29
+ } from '../components/ui/dropdown-menu.tsx';
30
+ import { Skeleton } from '../components/ui/skeleton.tsx';
31
+ import { Failed } from '../issues/issue-page.tsx';
32
+ import { baseRuleOf, mergeOffer, type Unmergeable } from './merge-button.ts';
33
+ import {
34
+ checksOf,
35
+ dequeuePull,
36
+ enqueuePull,
37
+ entryStateOf,
38
+ lastEntryOf,
39
+ mergePull,
40
+ protectionOf,
41
+ pullAt,
42
+ queuedOf,
43
+ refreshPull,
44
+ type Check,
45
+ type PullDetail,
46
+ } from './pull.ts';
47
+
48
+ /** Each method's button, as GitHub's merge box names it. */
49
+ const methodNames: Readonly<Record<MergeMethod, string>> = {
50
+ merge: 'Create a merge commit',
51
+ squash: 'Squash and merge',
52
+ rebase: 'Rebase and merge',
53
+ };
54
+
55
+ const mergeButtons: Readonly<Record<MergeMethod, string>> = {
56
+ merge: 'Merge pull request',
57
+ squash: 'Squash and merge',
58
+ rebase: 'Rebase and merge',
59
+ };
60
+
61
+ /** Why the box offers nothing, as it says so. */
62
+ const reasons: Readonly<Record<Exclude<Unmergeable, 'merged' | 'queued'>, string>> = {
63
+ closed: 'This pull request is closed.',
64
+ 'not-allowed': 'Only those with write access to this repository can merge pull requests.',
65
+ draft: 'This pull request is still a work in progress. Draft pull requests cannot be merged.',
66
+ checking: 'Checking whether this branch can merge…',
67
+ conflicts: 'This branch has conflicts that must be resolved before it can merge.',
68
+ protected: `The base branch takes changes only from pushes, so a pull request can't merge into it here.`,
69
+ 'no-method': 'This repository allows no way to merge a pull request.',
70
+ };
71
+
72
+ /** Whether an entry's state is one it ends in: merged, failed or removed. */
73
+ const endedOf = (state: string | undefined) =>
74
+ state === 'merged' || state === 'failed' || state === 'removed';
75
+
76
+ /** How often the box asks again while the queue holds the pull request, until live updates. */
77
+ const queuePoll = 5_000;
78
+
79
+ /** The head's checks in one line: how many failed, wait or passed. */
80
+ function ChecksLine({ checks }: { readonly checks: readonly Check[] }) {
81
+ const count = (state: Check['state']) => checks.filter((check) => check.state === state).length;
82
+ const failed = count('failure');
83
+ const pending = count('pending');
84
+ if (checks.length === 0) return null;
85
+
86
+ const [Icon, tone, text] =
87
+ failed > 0
88
+ ? [CircleAlertIcon, 'text-destructive', `${failed} of ${checks.length} checks failed`]
89
+ : pending > 0
90
+ ? [CircleDotIcon, 'text-warning', `${pending} of ${checks.length} checks haven't finished`]
91
+ : [CircleCheckIcon, 'text-success', 'All checks have passed'];
92
+
93
+ return (
94
+ <CardHeader className="border-b">
95
+ <p className="flex items-center gap-2">
96
+ <Icon aria-hidden className={`size-4 ${tone}`} />
97
+ {text}
98
+ </p>
99
+ </CardHeader>
100
+ );
101
+ }
102
+
103
+ /**
104
+ * A pull request's merge box: what merging it takes, offered as its base allows: a method to merge
105
+ * by, adding it to the merge queue, or nothing, and why. Its place in the queue while it waits,
106
+ * with Remove, and its head's checks. Add and Remove go through the drop-in's
107
+ * `enqueuePullRequest` and `dequeuePullRequest`, as `gh` does (Q527).
108
+ */
109
+ export function MergeBox({
110
+ place,
111
+ repo,
112
+ pull,
113
+ allowed,
114
+ }: {
115
+ readonly place: RepoPlace;
116
+ readonly repo: Repo;
117
+ readonly pull: PullDetail;
118
+ readonly allowed: ReadonlySet<PageOperation>;
119
+ }) {
120
+ const client = useQueryClient();
121
+ const open = pull.state === 'open' && pull.merged === null;
122
+ const protection = useQuery({ ...protectionOf(place, pull.base.ref), enabled: open });
123
+ // While the queue holds it, the box reads its entry and the pull request again, so its place in
124
+ // the queue, its leaving it and its merge all show.
125
+ const queued = useQuery({
126
+ ...queuedOf(place, pull.base.ref, pull.number),
127
+ enabled: open,
128
+ refetchInterval: ({ state }) => (state.data === null ? false : queuePoll),
129
+ });
130
+ const waiting = queued.data !== null && queued.data !== undefined;
131
+ // The entry the box last found it waiting as, kept with the page's reads, so once the queue lets
132
+ // it go, the box reads how, after a tab away too.
133
+ const { owner, repo: name } = place;
134
+ const last = useQuery(lastEntryOf(place, pull.number)).data;
135
+ const entry = queued.data?.entry;
136
+ useEffect(() => {
137
+ const { queryKey } = lastEntryOf({ owner, repo: name }, pull.number);
138
+ if (entry !== undefined) client.setQueryData(queryKey, entry);
139
+ }, [client, owner, name, pull.number, entry]);
140
+ const ended = useQuery({
141
+ ...entryStateOf(last ?? ''),
142
+ enabled: open && last !== undefined && queued.data === null,
143
+ refetchInterval: ({ state }) => (endedOf(state.data) ? false : queuePoll),
144
+ });
145
+ // The queue merged it before the drop-in recorded the merge: the box reads on until it has.
146
+ const landing = queued.data === null && ended.data === 'merged';
147
+ // The queue let it go, and how isn't known yet: the box offers nothing until it is.
148
+ const leaving = open && queued.data === null && last !== undefined && !endedOf(ended.data);
149
+ useQuery({
150
+ ...pullAt(place, pull.number),
151
+ refetchInterval: waiting || landing || leaving ? queuePoll : false,
152
+ });
153
+ const checks = useQuery(checksOf(place, pull.head.sha)).data ?? [];
154
+ const [method, setMethod] = useState<MergeMethod | undefined>();
155
+
156
+ const refresh = () =>
157
+ Promise.all([
158
+ refreshPull(client, place, pull.number),
159
+ client.invalidateQueries({ queryKey: queuedOf(place, pull.base.ref, pull.number).queryKey }),
160
+ ]);
161
+ // A failed act reads again too: a refusal can mean the queue moved on, as an entry gone does.
162
+ const acted = useMutation({
163
+ mutationFn: (act: () => Promise<void>) => act(),
164
+ onSettled: refresh,
165
+ });
166
+ // Adding answers the drop-in's entry, not Git's, so the box reads the queue at once and keeps the
167
+ // entry it finds there, as it keeps one it saw waiting: a merge before the page reads again shows.
168
+ const add = async () => {
169
+ await enqueuePull(pull);
170
+ const found = await client.fetchQuery({
171
+ ...queuedOf(place, pull.base.ref, pull.number),
172
+ staleTime: 0,
173
+ });
174
+ if (found !== null) client.setQueryData(lastEntryOf(place, pull.number).queryKey, found.entry);
175
+ };
176
+
177
+ if (pull.merged !== null) {
178
+ return (
179
+ <Box icon={<GitMergeIcon aria-hidden className="size-4 text-state-merged" />}>
180
+ <CardContent>
181
+ <p className="font-medium">Pull request successfully merged and closed</p>
182
+ {/* An Add pressed on a page that hadn't read the merge yet says why it was refused. */}
183
+ <Failed error={acted.error} />
184
+ </CardContent>
185
+ </Box>
186
+ );
187
+ }
188
+
189
+ if (landing) {
190
+ return (
191
+ <Box icon={<GitMergeIcon aria-hidden className="size-4 text-state-merged" />}>
192
+ <CardContent>
193
+ <p>
194
+ <span className="font-medium">Merged by the merge queue.</span> The pull request shows
195
+ it once the merge is recorded.
196
+ </p>
197
+ </CardContent>
198
+ </Box>
199
+ );
200
+ }
201
+
202
+ if (leaving) {
203
+ return (
204
+ <Box icon={<LoaderCircleIcon aria-hidden className="size-4 text-muted-foreground" />}>
205
+ <CardContent>
206
+ {ended.error === null ? (
207
+ <p>Checking whether the merge queue merged it…</p>
208
+ ) : (
209
+ <Failed error={ended.error} />
210
+ )}
211
+ </CardContent>
212
+ </Box>
213
+ );
214
+ }
215
+
216
+ if (open && (protection.data === undefined || queued.data === undefined)) {
217
+ const error = protection.error ?? queued.error;
218
+
219
+ return (
220
+ <Box icon={<LoaderCircleIcon aria-hidden className="size-4 text-muted-foreground" />}>
221
+ <CardContent>
222
+ {error === null ? <Skeleton className="h-5 w-64" /> : <Failed error={error} />}
223
+ </CardContent>
224
+ </Box>
225
+ );
226
+ }
227
+
228
+ const offer = mergeOffer(
229
+ { rule: baseRuleOf(protection.data ?? null), methods: repo.mergeMethods },
230
+ { ...pull, merged: false, queued: waiting },
231
+ allowed.has('pull.merge'),
232
+ );
233
+ const chosen =
234
+ offer.kind === 'merge' && method !== undefined && offer.methods.includes(method)
235
+ ? method
236
+ : offer.kind === 'merge'
237
+ ? offer.methods[0]
238
+ : undefined;
239
+
240
+ return (
241
+ <Box
242
+ icon={
243
+ waiting ? (
244
+ <ListOrderedIcon aria-hidden className="size-4 text-warning" />
245
+ ) : (
246
+ <GitMergeIcon
247
+ aria-hidden
248
+ className={`size-4 ${offer.kind === 'none' ? 'text-muted-foreground' : 'text-success'}`}
249
+ />
250
+ )
251
+ }
252
+ >
253
+ <ChecksLine checks={checks} />
254
+ <CardContent className="flex flex-col gap-2">
255
+ {queued.data !== null && queued.data !== undefined ? (
256
+ <div className="flex flex-wrap items-center justify-between gap-2">
257
+ <p>
258
+ <span className="font-medium">Queued to merge.</span>{' '}
259
+ {queued.data.ahead === 0
260
+ ? 'It merges next.'
261
+ : `${queued.data.ahead} ${queued.data.ahead === 1 ? 'pull request is' : 'pull requests are'} ahead of it.`}{' '}
262
+ <Go
263
+ href={`/${place.owner}/${place.repo}/queue`}
264
+ className="text-link hover:underline"
265
+ >
266
+ View the queue
267
+ </Go>
268
+ </p>
269
+ {allowed.has('pull.merge') && (
270
+ <ConfirmAction
271
+ label="Remove from queue"
272
+ title={`Remove pull request #${pull.number} from the queue?`}
273
+ description="It leaves the queue, and isn't merged by it. You can add it again."
274
+ disabled={acted.isPending}
275
+ onConfirm={() =>
276
+ acted.mutate(() => dequeuePull(pull), {
277
+ onSuccess: () => toast.success(`Removed #${pull.number} from the merge queue`),
278
+ })
279
+ }
280
+ />
281
+ )}
282
+ </div>
283
+ ) : offer.kind === 'queue' ? (
284
+ <div className="flex flex-wrap items-center justify-between gap-2">
285
+ <p>This branch takes changes only from the merge queue.</p>
286
+ <Button
287
+ disabled={acted.isPending}
288
+ onClick={() =>
289
+ acted.mutate(add, {
290
+ onSuccess: () => toast.success(`Added #${pull.number} to the merge queue`),
291
+ })
292
+ }
293
+ >
294
+ Add to merge queue
295
+ </Button>
296
+ </div>
297
+ ) : offer.kind === 'merge' && chosen !== undefined ? (
298
+ <div className="flex flex-wrap items-center justify-between gap-2">
299
+ <p>This branch has no conflicts with the base branch.</p>
300
+ <ButtonGroup>
301
+ <Button
302
+ disabled={acted.isPending}
303
+ onClick={() =>
304
+ acted.mutate(
305
+ () => mergePull(place, pull.number, { method: chosen, sha: pull.head.sha }),
306
+ { onSuccess: () => toast.success(`Merged #${pull.number}`) },
307
+ )
308
+ }
309
+ >
310
+ {mergeButtons[chosen]}
311
+ </Button>
312
+ {offer.methods.length > 1 && <ButtonGroupSeparator />}
313
+ {offer.methods.length > 1 && (
314
+ <DropdownMenu>
315
+ <DropdownMenuTrigger
316
+ render={
317
+ <Button
318
+ size="icon"
319
+ aria-label="Choose how to merge"
320
+ disabled={acted.isPending}
321
+ />
322
+ }
323
+ >
324
+ <ChevronDownIcon aria-hidden />
325
+ </DropdownMenuTrigger>
326
+ <DropdownMenuContent align="end" className="w-56">
327
+ <DropdownMenuGroup>
328
+ <DropdownMenuRadioGroup
329
+ value={chosen}
330
+ onValueChange={(value) =>
331
+ setMethod(offer.methods.find((each) => each === value))
332
+ }
333
+ >
334
+ {offer.methods.map((each) => (
335
+ <DropdownMenuRadioItem key={each} value={each}>
336
+ {methodNames[each]}
337
+ </DropdownMenuRadioItem>
338
+ ))}
339
+ </DropdownMenuRadioGroup>
340
+ </DropdownMenuGroup>
341
+ </DropdownMenuContent>
342
+ </DropdownMenu>
343
+ )}
344
+ </ButtonGroup>
345
+ </div>
346
+ ) : (
347
+ offer.kind === 'none' &&
348
+ offer.why !== 'merged' &&
349
+ offer.why !== 'queued' && <p className="text-muted-foreground">{reasons[offer.why]}</p>
350
+ )}
351
+ <Failed error={acted.error} />
352
+ </CardContent>
353
+ </Box>
354
+ );
355
+ }
356
+
357
+ /** The box's frame: a Card, its icon beside it, as GitHub's timeline ends. */
358
+ function Box({ icon, children }: { readonly icon: ReactNode; readonly children: ReactNode }) {
359
+ return (
360
+ <section aria-label="Merge" className="flex gap-3">
361
+ <div className="pt-3">{icon}</div>
362
+ <Card size="sm" className="min-w-0 grow text-sm">
363
+ {children}
364
+ </Card>
365
+ </section>
366
+ );
367
+ }
@@ -0,0 +1,86 @@
1
+ import type { MergeMethod } from '../code/repo.ts';
2
+
3
+ /** Where a ref's moves may come from, as Git's protection on it names them. */
4
+ export type RefSource = 'git' | 'api' | 'queue' | 'import';
5
+
6
+ /** Git's protection on a ref, or `null` for none: `sources` names who may move it. */
7
+ export type Protection = { readonly sources?: readonly RefSource[] } | null;
8
+
9
+ /**
10
+ * How a pull request's base takes it: merged directly, as the drop-in's REST merge moves the base
11
+ * as `api`; only through the queue; or neither, when it takes only pushes or imports.
12
+ */
13
+ export type BaseRule = 'direct' | 'queue' | 'protected';
14
+
15
+ /** The rule `protection` sets on a base: any move when it names no sources. */
16
+ export const baseRuleOf = (protection: Protection): BaseRule => {
17
+ const sources = protection?.sources;
18
+ if (sources === undefined || sources.includes('api')) return 'direct';
19
+
20
+ return sources.includes('queue') ? 'queue' : 'protected';
21
+ };
22
+
23
+ /** What a pull request merges into: its base's rule, and the methods the repo allows. */
24
+ export interface MergeTarget {
25
+ readonly rule: BaseRule;
26
+ readonly methods: readonly MergeMethod[];
27
+ }
28
+
29
+ /** What of a pull request decides whether it can merge now. */
30
+ export interface MergeState {
31
+ readonly state: 'open' | 'closed';
32
+ readonly merged: boolean;
33
+ readonly draft: boolean;
34
+ /** Whether it merges cleanly, or `null` while the drop-in hasn't worked it out yet. */
35
+ readonly mergeable: boolean | null;
36
+ /** Whether the queue holds it already. */
37
+ readonly queued: boolean;
38
+ }
39
+
40
+ /** Why the merge box offers nothing. */
41
+ export type Unmergeable =
42
+ | 'merged'
43
+ | 'closed'
44
+ | 'not-allowed'
45
+ | 'draft'
46
+ | 'queued'
47
+ | 'checking'
48
+ | 'conflicts'
49
+ | 'protected'
50
+ | 'no-method';
51
+
52
+ /** What the merge box offers: the methods to merge by, adding to the queue, or nothing and why. */
53
+ export type MergeOffer =
54
+ | { readonly kind: 'merge'; readonly methods: readonly MergeMethod[] }
55
+ | { readonly kind: 'queue' }
56
+ | { readonly kind: 'none'; readonly why: Unmergeable };
57
+
58
+ /**
59
+ * What the merge box offers for `pull` into `target`, to a viewer who `may` merge it: exactly
60
+ * what the target allows. A merge method where the base takes direct merges, adding to the queue
61
+ * where it takes changes only from the queue, and nothing while mergeability is unknown or false.
62
+ */
63
+ export const mergeOffer = (target: MergeTarget, pull: MergeState, may: boolean): MergeOffer => {
64
+ const none = (why: Unmergeable): MergeOffer => ({ kind: 'none', why });
65
+ if (pull.merged) return none('merged');
66
+
67
+ if (pull.state === 'closed') return none('closed');
68
+
69
+ if (!may) return none('not-allowed');
70
+
71
+ if (pull.draft) return none('draft');
72
+
73
+ if (pull.queued) return none('queued');
74
+
75
+ if (pull.mergeable === null) return none('checking');
76
+
77
+ if (!pull.mergeable) return none('conflicts');
78
+
79
+ if (target.rule === 'protected') return none('protected');
80
+
81
+ if (target.rule === 'queue') return { kind: 'queue' };
82
+
83
+ return target.methods.length === 0
84
+ ? none('no-method')
85
+ : { kind: 'merge', methods: target.methods };
86
+ };