ref0-git 0.0.0-stage → 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 +52 -3
  385. package/README.md +0 -3
@@ -0,0 +1,318 @@
1
+ import { queryOptions } from '@tanstack/react-query';
2
+
3
+ import { github } from '../clients/clients.ts';
4
+ import type { RepoPlace } from '../code/places.ts';
5
+ import { rowOf, type CommitRow } from '../code/refs.ts';
6
+ import { isText, type ChangedFile } from '../diffs/files.ts';
7
+ import { everyPage, failure } from '../hooks/answers.ts';
8
+ import { type Pictures, picturesOf } from '../hooks/avatars.ts';
9
+ import {
10
+ issueOf,
11
+ listerOf,
12
+ listQuery,
13
+ readOn,
14
+ type Issue,
15
+ type Listed,
16
+ type Vocabulary,
17
+ } from '../issues/issues.ts';
18
+ import type { PullStatus } from '../components/pull-status.tsx';
19
+ import type { IssueState } from '../issues/search.ts';
20
+ import { pullSearchQueryOf, type PullFilter, type ReviewFilter } from './search.ts';
21
+
22
+ /** A pull request in the fields its row reads. */
23
+ export interface Pull extends Issue {
24
+ readonly draft: boolean;
25
+ /** When it merged, or `null` while it hasn't. */
26
+ readonly merged: string | null;
27
+ }
28
+
29
+ export const statusOf = (pull: Pick<Pull, 'state' | 'draft' | 'merged'>): PullStatus => {
30
+ if (pull.merged !== null) return 'merged';
31
+
32
+ if (pull.state === 'closed') return 'closed';
33
+
34
+ return pull.draft ? 'draft' : 'open';
35
+ };
36
+
37
+ const pullOf = (issue: Listed): Pull => ({
38
+ ...issueOf(issue),
39
+ draft: issue.draft ?? false,
40
+ merged: issue.pull_request?.merged_at ?? null,
41
+ });
42
+
43
+ /**
44
+ * The state the drop-in lists by for `filter`, or `undefined` when none can match: a merged
45
+ * pull request is closed, and whether one merged, the page tells apart.
46
+ */
47
+ const listedState = ({ state, merged }: PullFilter): IssueState | undefined => {
48
+ if (merged !== true) return state;
49
+
50
+ return state === 'open' ? undefined : 'closed';
51
+ };
52
+
53
+ /** Whether `pull` is one `filter` names, in what the drop-in can't filter by. */
54
+ const shown = (filter: PullFilter, pull: Pull) => {
55
+ if (filter.merged !== undefined && filter.merged !== (pull.merged !== null)) return false;
56
+
57
+ return filter.draft === undefined || filter.draft === pull.draft;
58
+ };
59
+
60
+ /** What a pull request's reviews decided, as `review:` filters by. */
61
+ export type Decision = ReviewFilter | 'commented';
62
+
63
+ /**
64
+ * What `reviews` decided, as GitHub decides it: each reviewer's latest approval or request for
65
+ * changes stands, until dismissed; any change asked for outweighs approvals.
66
+ */
67
+ export const decisionOf = (
68
+ reviews: readonly { readonly login: string; readonly state: string }[],
69
+ ): Decision => {
70
+ const standing = new Map<string, string>();
71
+ let submitted = false;
72
+
73
+ for (const { login, state } of reviews) {
74
+ if (state === 'PENDING') continue;
75
+
76
+ submitted = true;
77
+
78
+ if (state === 'APPROVED' || state === 'CHANGES_REQUESTED') standing.set(login, state);
79
+ else if (state === 'DISMISSED') standing.delete(login);
80
+ }
81
+
82
+ const stands = [...standing.values()];
83
+ if (stands.includes('CHANGES_REQUESTED')) return 'changes_requested';
84
+
85
+ if (stands.includes('APPROVED')) return 'approved';
86
+
87
+ return submitted ? 'commented' : 'none';
88
+ };
89
+
90
+ /** A review: who gave it, what it decided, and when. */
91
+ export interface Review {
92
+ readonly id: number;
93
+ readonly login: string;
94
+ readonly state: string;
95
+ readonly body: string;
96
+ /** When it was submitted, or `null` while it's pending. */
97
+ readonly submitted: string | null;
98
+ /** Its author's picture, as the answer named it. */
99
+ readonly pictures: Pictures;
100
+ }
101
+
102
+ /** `pull`'s reviews, oldest first, read from the drop-in a page of 100 at a time. */
103
+ export const reviewsRead = (place: RepoPlace, pull: number) =>
104
+ everyPage(async (after) => {
105
+ const answer = await github.GET('/repos/{owner}/{repo}/pulls/{pull_number}/reviews', {
106
+ // `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
107
+ params: { path: { ...place, pull_number: pull }, query: { ...{ per_page: 100, after } } },
108
+ });
109
+ if (answer.data === undefined) throw failure(`#${pull}'s reviews didn't load`, answer);
110
+
111
+ const rows = answer.data.map((review): Review => ({
112
+ id: Number(review.id),
113
+ login: review.user?.login ?? 'ghost',
114
+ state: review.state,
115
+ body: review.body,
116
+ submitted: review.submitted_at ?? null,
117
+ pictures: picturesOf([review.user]),
118
+ }));
119
+
120
+ return { rows, link: answer.response.headers.get('link') };
121
+ });
122
+
123
+ /** `pull`'s reviews' decision. */
124
+ const decided = async (place: RepoPlace, pull: number) =>
125
+ decisionOf((await reviewsRead(place, pull)).rows);
126
+
127
+ /** Whether `login`'s review of `pull` is asked for. */
128
+ const requestedOf = async (place: RepoPlace, pull: number, login: string) => {
129
+ const answer = await github.GET('/repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers', {
130
+ params: { path: { ...place, pull_number: pull } },
131
+ });
132
+ if (answer.data === undefined) throw failure(`#${pull}'s reviewers didn't load`, answer);
133
+
134
+ return answer.data.users.some((user) => user.login === login);
135
+ };
136
+
137
+ /** Whether `pull` passes `filter`'s review qualifiers, which only its reviews can say. */
138
+ const reviewedAs = async (place: RepoPlace, filter: PullFilter, pull: Pull) => {
139
+ const { review, reviewRequested } = filter;
140
+ const [decision, requested] = await Promise.all([
141
+ review === undefined ? undefined : decided(place, pull.number),
142
+ reviewRequested === undefined ? true : requestedOf(place, pull.number, reviewRequested),
143
+ ]);
144
+
145
+ return requested && (review === undefined || decision === review);
146
+ };
147
+
148
+ /**
149
+ * How many of the drop-in's pages a list page reads on through before it shows what it found:
150
+ * enough to pass a run of issues, and few enough that the reviews a review filter reads stay
151
+ * bounded.
152
+ */
153
+ const pullReads = 10;
154
+
155
+ /** A page of pull requests, and the cursor of the one after it. */
156
+ export interface PullPage {
157
+ readonly pulls: readonly Pull[];
158
+ readonly next: string | undefined;
159
+ }
160
+
161
+ /**
162
+ * A page of the repo's pull requests under `filter`, after `after`. The drop-in lists them
163
+ * among its issues, filtered as issues are, or its search finds them once the box holds words,
164
+ * and the page keeps those `filter` names: merged or not, draft or not, and by their reviews,
165
+ * read only when the box asks for them.
166
+ */
167
+ export const pullPage = async (
168
+ place: RepoPlace,
169
+ filter: PullFilter,
170
+ vocabulary: Vocabulary,
171
+ after: string | undefined,
172
+ ): Promise<PullPage> => {
173
+ const state = listedState(filter);
174
+ const query = state === undefined ? undefined : listQuery({ ...filter, state }, vocabulary);
175
+ const searched = pullSearchQueryOf(place, filter);
176
+ const lister = listerOf(place, filter, query, searched, 'The pull requests');
177
+ if (lister === undefined) return { pulls: [], next: undefined };
178
+
179
+ const keep = async (listed: readonly Listed[]) => {
180
+ const pulls = listed.flatMap((issue) => {
181
+ if (issue.pull_request === undefined) return [];
182
+
183
+ const pull = pullOf(issue);
184
+
185
+ return shown(filter, pull) ? [pull] : [];
186
+ });
187
+ if (filter.review === undefined && filter.reviewRequested === undefined) return pulls;
188
+
189
+ const passes = await Promise.all(pulls.map((pull) => reviewedAs(place, filter, pull)));
190
+
191
+ return pulls.filter((_, index) => passes[index]);
192
+ };
193
+
194
+ const { rows, next } = await readOn(lister, after, { keep, reads: pullReads });
195
+
196
+ return { pulls: rows, next };
197
+ };
198
+
199
+ const firstPage: string | undefined = undefined;
200
+
201
+ /**
202
+ * Where the repo's pull request lists are read, one under each filter: their pages and nothing
203
+ * else, so a change can write into their rows. The rest of the repo's pull request reads, such as
204
+ * the tabs' counts and a pair's open pull request, sit beside it under `['pulls', owner, repo]`.
205
+ */
206
+ export const pullLists = (place: RepoPlace) => ['pulls', place.owner, place.repo, 'list'] as const;
207
+
208
+ /** The repo's pull requests under `filter`, a page at a time as the reader asks for more. */
209
+ export const pullList = (place: RepoPlace, filter: PullFilter, vocabulary: Vocabulary) => ({
210
+ queryKey: [...pullLists(place), filter] as const,
211
+ queryFn: ({ pageParam }: { readonly pageParam: string | undefined }) =>
212
+ pullPage(place, filter, vocabulary, pageParam),
213
+ initialPageParam: firstPage,
214
+ getNextPageParam: (last: PullPage) => last.next,
215
+ staleTime: 10_000,
216
+ });
217
+
218
+ /** Two revisions a comparison is between: what a pull request would merge into, and from. */
219
+ export interface Basehead {
220
+ readonly base: string;
221
+ readonly head: string;
222
+ }
223
+
224
+ /** `base...head`, as GitHub's compare URL and REST name a comparison. */
225
+ export const baseheadOf = ({ base, head }: Basehead) => `${base}...${head}`;
226
+
227
+ /** How many of a comparison's commits the page lists, as GitHub's compare page does. */
228
+ export const comparedCommitsShown = 250;
229
+
230
+ /** What `head` has that `base` hasn't, and the other way round, read in one answer. */
231
+ export interface Comparison {
232
+ /** The commit `base` and `head` last share, which the diff is from. */
233
+ readonly mergeBase: string;
234
+ /** The commit `head` named when it was read, which the diff is to. */
235
+ readonly head: string;
236
+ readonly ahead: number;
237
+ readonly behind: number;
238
+ /** The first `comparedCommitsShown` of the commits `head` has, oldest first. */
239
+ readonly commits: readonly CommitRow[];
240
+ /** The files `head` changed since the merge base, up to GitHub's 300. */
241
+ readonly files: readonly ChangedFile[];
242
+ }
243
+
244
+ /** The head commit a comparison's `permalink_url` names, `owner:` dropped, as GitHub's has it. */
245
+ const permalinkHead = (permalink: string) => {
246
+ const head = permalink.slice(permalink.lastIndexOf('...') + 3);
247
+
248
+ return head.slice(head.indexOf(':') + 1);
249
+ };
250
+
251
+ /**
252
+ * The comparison of `basehead`, or `null` when there's none to make: a revision the repo hasn't
253
+ * got, or two that share no history.
254
+ */
255
+ export const comparisonOf = (place: RepoPlace, basehead: Basehead) =>
256
+ queryOptions({
257
+ queryKey: ['comparison', place.owner, place.repo, basehead.base, basehead.head],
258
+ queryFn: async (): Promise<Comparison | null> => {
259
+ const answer = await github.GET('/repos/{owner}/{repo}/compare/{basehead}', {
260
+ // No page asked for: the drop-in answers the first 250 commits and the files at once.
261
+ params: { path: { ...place, basehead: baseheadOf(basehead) } },
262
+ });
263
+ if (answer.response.status === 404) return null;
264
+
265
+ if (answer.data === undefined || isText(answer.data)) {
266
+ throw failure("The comparison didn't load", answer);
267
+ }
268
+
269
+ const { merge_base_commit, permalink_url, ahead_by, behind_by, commits, files } = answer.data;
270
+
271
+ return {
272
+ mergeBase: merge_base_commit.sha,
273
+ head: permalinkHead(permalink_url),
274
+ ahead: ahead_by,
275
+ behind: behind_by,
276
+ commits: commits.slice(0, comparedCommitsShown).map(rowOf),
277
+ files: files ?? [],
278
+ };
279
+ },
280
+ staleTime: 10_000,
281
+ });
282
+
283
+ /** The pull request `basehead` has open already, if it has one: GitHub opens one a pair. */
284
+ export const openPullOf = (place: RepoPlace, basehead: Basehead) =>
285
+ queryOptions({
286
+ // Under the list's key, so opening one, which invalidates the list, reads this again.
287
+ queryKey: ['pulls', place.owner, place.repo, 'open', basehead.base, basehead.head],
288
+ queryFn: async (): Promise<number | null> => {
289
+ const answer = await github.GET('/repos/{owner}/{repo}/pulls', {
290
+ params: {
291
+ path: place,
292
+ query: { state: 'open', base: basehead.base, head: `${place.owner}:${basehead.head}` },
293
+ },
294
+ });
295
+ if (answer.data === undefined) throw failure("The open pull requests didn't load", answer);
296
+
297
+ return answer.data[0]?.number ?? null;
298
+ },
299
+ staleTime: 10_000,
300
+ });
301
+
302
+ /** What a new pull request is opened with. */
303
+ export interface Opening extends Basehead {
304
+ readonly title: string;
305
+ readonly body: string;
306
+ readonly draft: boolean;
307
+ }
308
+
309
+ /** Opens a pull request, answering its number. */
310
+ export const openPull = async (place: RepoPlace, opening: Opening) => {
311
+ const answer = await github.POST('/repos/{owner}/{repo}/pulls', {
312
+ params: { path: place },
313
+ body: { ...opening },
314
+ });
315
+ if (answer.data === undefined) throw failure("The pull request wasn't opened", answer);
316
+
317
+ return answer.data.number;
318
+ };
@@ -0,0 +1,350 @@
1
+ import { queryOptions, type QueryClient } from '@tanstack/react-query';
2
+ import { useEffect } from 'react';
3
+
4
+ import { git, github } from '../clients/clients.ts';
5
+ import type { RepoPlace } from '../code/places.ts';
6
+ import { everyPage, failure } from '../hooks/answers.ts';
7
+ import { type Pictures, picturesOf } from '../hooks/avatars.ts';
8
+ import { refreshPull, reviewsOf, type PullDetail } from './pull.ts';
9
+
10
+ /**
11
+ * What a review comment's two shapes in GitHub's REST share: a pull request's comments, and a
12
+ * review's, which GitHub's types name apart.
13
+ */
14
+ interface RestComment {
15
+ readonly id: number | bigint;
16
+ readonly user: { readonly login: string; readonly avatar_url: string } | null;
17
+ readonly body: string;
18
+ readonly created_at: string;
19
+ readonly original_commit_id: string;
20
+ readonly in_reply_to_id?: number;
21
+ readonly path: string;
22
+ readonly line?: number | null;
23
+ readonly original_line?: number | null;
24
+ readonly side?: string;
25
+ readonly start_line?: number | null;
26
+ readonly original_start_line?: number | null;
27
+ readonly start_side?: string | null;
28
+ }
29
+
30
+ /** A diff's side, as GitHub's review comments name it: the old file's lines, or the new's. */
31
+ export type LineSide = 'LEFT' | 'RIGHT';
32
+
33
+ /** The lines a review comment is on: `line` on `side`, from `startLine` when it's a range. */
34
+ export interface LinePlace {
35
+ readonly path: string;
36
+ readonly side: LineSide;
37
+ readonly line: number;
38
+ readonly startLine?: number;
39
+ readonly startSide?: LineSide;
40
+ }
41
+
42
+ /** A review comment on a line of the diff, saved or a pending review's draft. */
43
+ export interface LineComment extends LinePlace {
44
+ readonly id: number;
45
+ readonly login: string;
46
+ readonly body: string;
47
+ readonly created: string;
48
+ /**
49
+ * The commit it was made on, whose lines it's on: the drop-in doesn't move them when the head
50
+ * moves (Q508), and GitHub's `original_commit_id` keeps it where GitHub's does.
51
+ */
52
+ readonly commit: string;
53
+ /** The comment whose thread it replies in, or none when it starts one. */
54
+ readonly replyTo: number | undefined;
55
+ /** Its author's picture, as the answer named it. */
56
+ readonly pictures: Pictures;
57
+ }
58
+
59
+ /** A comment the page holds for the review the viewer is writing, until they submit it. */
60
+ export interface Draft extends LinePlace {
61
+ readonly key: string;
62
+ readonly body: string;
63
+ /** The head it was written on, whose diff its lines are numbered in. */
64
+ readonly head: string;
65
+ }
66
+
67
+ /** What submitting a review says of the pull request, as GitHub's review box offers it. */
68
+ export type ReviewEvent = 'COMMENT' | 'APPROVE' | 'REQUEST_CHANGES';
69
+
70
+ const sideOf = (side: string | undefined): LineSide | undefined =>
71
+ side === 'LEFT' || side === 'RIGHT' ? side : undefined;
72
+
73
+ /**
74
+ * A comment on lines, where it was made, or `undefined` for one on a whole file. Its `original_*`
75
+ * fields keep where it was made, which GitHub's `line` doesn't once a push moves it.
76
+ */
77
+ const lineCommentOf = (comment: RestComment): LineComment | undefined => {
78
+ const side = sideOf(comment.side);
79
+ const line = comment.original_line ?? comment.line ?? undefined;
80
+ if (line === undefined || side === undefined) return undefined;
81
+
82
+ const start = comment.original_start_line ?? comment.start_line ?? undefined;
83
+ const range =
84
+ start === undefined || start === line
85
+ ? {}
86
+ : { startLine: start, startSide: sideOf(comment.start_side ?? undefined) ?? side };
87
+
88
+ return {
89
+ id: Number(comment.id),
90
+ login: comment.user?.login ?? 'ghost',
91
+ body: comment.body,
92
+ created: comment.created_at,
93
+ commit: comment.original_commit_id,
94
+ replyTo: comment.in_reply_to_id,
95
+ pictures: picturesOf([comment.user]),
96
+ path: comment.path,
97
+ side,
98
+ line,
99
+ ...range,
100
+ };
101
+ };
102
+
103
+ const linesOf = (comments: readonly RestComment[]) =>
104
+ comments.flatMap((comment) => lineCommentOf(comment) ?? []);
105
+
106
+ /** Whether a thread begun with `first` is outdated: made on a commit that isn't `head`. */
107
+ export const isOutdated = (first: LineComment, head: string) => first.commit !== head;
108
+
109
+ /**
110
+ * The comments on `head`'s diff: threads begun on it, with their replies. A thread begun on an
111
+ * earlier head is outdated, and its lines may hold other code now, so it doesn't show there.
112
+ */
113
+ export const onHead = (comments: readonly LineComment[], head: string) => {
114
+ const begun = new Set(
115
+ comments.flatMap((comment) =>
116
+ comment.replyTo === undefined && !isOutdated(comment, head) ? [comment.id] : [],
117
+ ),
118
+ );
119
+
120
+ return comments.filter((comment) => begun.has(comment.replyTo ?? comment.id));
121
+ };
122
+
123
+ /** The threads begun on an earlier head than `head`, oldest first, each with its replies. */
124
+ export const outdatedThreads = (comments: readonly LineComment[], head: string) => {
125
+ const threads = new Map<number, LineComment[]>(
126
+ comments.flatMap((comment) =>
127
+ comment.replyTo === undefined && isOutdated(comment, head) ? [[comment.id, []]] : [],
128
+ ),
129
+ );
130
+
131
+ for (const comment of comments) threads.get(comment.replyTo ?? comment.id)?.push(comment);
132
+
133
+ return [...threads.values()];
134
+ };
135
+
136
+ /** `pull`'s saved review comments on lines of its diff as it stands, oldest first. */
137
+ export const lineCommentsOf = (place: RepoPlace, pull: number) =>
138
+ queryOptions({
139
+ queryKey: ['pull-line-comments', place.owner, place.repo, pull],
140
+ queryFn: async () => {
141
+ const read = await everyPage(async (after) => {
142
+ const answer = await github.GET('/repos/{owner}/{repo}/pulls/{pull_number}/comments', {
143
+ // `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
144
+ params: { path: { ...place, pull_number: pull }, query: { ...{ per_page: 100, after } } },
145
+ });
146
+ if (answer.data === undefined) throw failure("The review comments didn't load", answer);
147
+
148
+ return { rows: linesOf(answer.data), link: answer.response.headers.get('link') };
149
+ });
150
+
151
+ return read.rows;
152
+ },
153
+ staleTime: 10_000,
154
+ });
155
+
156
+ /** The drafts of the viewer's pending review `review`, started elsewhere, such as with `gh`. */
157
+ export const pendingCommentsOf = (place: RepoPlace, pull: number, review: number | undefined) =>
158
+ queryOptions({
159
+ queryKey: ['pull-pending-comments', place.owner, place.repo, pull, review],
160
+ queryFn: async () => {
161
+ if (review === undefined) return [];
162
+
163
+ // A pending review holds at most 300 drafts (Q513): three pages of 100.
164
+ const read = await everyPage(async (after) => {
165
+ const answer = await github.GET(
166
+ '/repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/comments',
167
+ {
168
+ params: {
169
+ path: { ...place, pull_number: pull, review_id: review },
170
+ query: { ...{ per_page: 100, after } },
171
+ },
172
+ },
173
+ );
174
+ if (answer.data === undefined) throw failure("The pending review didn't load", answer);
175
+
176
+ return { rows: linesOf(answer.data), link: answer.response.headers.get('link') };
177
+ });
178
+
179
+ return read.rows;
180
+ },
181
+ staleTime: 10_000,
182
+ });
183
+
184
+ /** The drafts the page holds for `pull`, kept across its tabs until the review is submitted. */
185
+ export const draftsOf = (place: RepoPlace, pull: number) =>
186
+ queryOptions({
187
+ queryKey: ['pull-review-drafts', place.owner, place.repo, pull],
188
+ queryFn: (): readonly Draft[] => [],
189
+ staleTime: Infinity,
190
+ gcTime: Infinity,
191
+ });
192
+
193
+ /** What **Review changes** holds before it's submitted: its summary, and what the review says. */
194
+ export interface ReviewDraft {
195
+ readonly body: string;
196
+ readonly event: ReviewEvent;
197
+ }
198
+
199
+ export const noReviewDraft: ReviewDraft = { body: '', event: 'COMMENT' };
200
+
201
+ /**
202
+ * The review `pull`'s **Review changes** holds, beside its line drafts and kept as they are: across
203
+ * closing it, the pull request's tabs and a push, until it's submitted or discarded. It's under the
204
+ * pull request's own key, so one pull request's submit leaves another's draft alone.
205
+ */
206
+ export const reviewDraftOf = (place: RepoPlace, pull: number) =>
207
+ queryOptions({
208
+ queryKey: ['pull-review-summary', place.owner, place.repo, pull],
209
+ queryFn: (): ReviewDraft => noReviewDraft,
210
+ staleTime: Infinity,
211
+ gcTime: Infinity,
212
+ });
213
+
214
+ /**
215
+ * Asks before the page unloads, by a reload or a link out of the app, while any pull request's
216
+ * review drafts or summary are unsent: they live only in the page, since the drop-in adds none to
217
+ * a pending review (Q529). A link inside the app keeps them.
218
+ */
219
+ export const useAskBeforeLosingDrafts = (client: QueryClient) =>
220
+ useEffect(() => {
221
+ const ask = (event: BeforeUnloadEvent) => {
222
+ const held = client.getQueriesData<readonly Draft[]>({ queryKey: ['pull-review-drafts'] });
223
+ const summaries = client.getQueriesData<ReviewDraft>({ queryKey: ['pull-review-summary'] });
224
+ const unsent =
225
+ held.some(([, drafts]) => (drafts?.length ?? 0) > 0) ||
226
+ summaries.some(([, draft]) => (draft?.body.trim() ?? '') !== '');
227
+ if (unsent) event.preventDefault();
228
+ };
229
+
230
+ addEventListener('beforeunload', ask);
231
+
232
+ return () => removeEventListener('beforeunload', ask);
233
+ }, [client]);
234
+
235
+ /** The commit `pull`'s diff is from: where its base and head last met, as Git finds it. */
236
+ export const mergeBaseOf = (place: RepoPlace, pull: PullDetail) =>
237
+ queryOptions({
238
+ queryKey: ['pull-merge-base', place.owner, place.repo, pull.base.sha, pull.head.sha],
239
+ queryFn: async () => {
240
+ const answer = await git.POST('/repos/{repo}/-/commits/merge-base', {
241
+ params: { path: { repo: `${place.owner}/${place.repo}` } },
242
+ body: { commits: [pull.base.sha, pull.head.sha] },
243
+ });
244
+ if (answer.data === undefined) throw failure("The diff's base didn't load", answer);
245
+
246
+ return answer.data.bases[0] ?? pull.base.sha;
247
+ },
248
+ staleTime: Infinity,
249
+ });
250
+
251
+ /** The fields GitHub's REST takes for a comment on `place`'s lines. */
252
+ const placeFields = (place: LinePlace) => {
253
+ const fields = { path: place.path, line: place.line, side: place.side };
254
+ if (place.startLine === undefined) return fields;
255
+
256
+ return { ...fields, start_line: place.startLine, start_side: place.startSide ?? place.side };
257
+ };
258
+
259
+ /**
260
+ * Posts one comment, a review of its own as GitHub's does, on lines of the head whose diff they
261
+ * were picked from, which a push since leaves outdated.
262
+ */
263
+ export const commentOnLines = async (
264
+ place: RepoPlace,
265
+ pull: number,
266
+ draft: LinePlace & { readonly body: string; readonly head: string },
267
+ ) => {
268
+ const answer = await github.POST('/repos/{owner}/{repo}/pulls/{pull_number}/comments', {
269
+ params: { path: { ...place, pull_number: pull } },
270
+ body: { body: draft.body, commit_id: draft.head, ...placeFields(draft) },
271
+ });
272
+ if (answer.error !== undefined) throw failure("The comment wasn't added", answer);
273
+ };
274
+
275
+ /**
276
+ * Posts a reply in `thread`. A reply takes its thread's place, as GitHub's does, which ignores all
277
+ * but its body: the place GitHub's types ask for is the thread's.
278
+ */
279
+ export const replyTo = async (
280
+ place: RepoPlace,
281
+ pull: PullDetail,
282
+ thread: LineComment,
283
+ body: string,
284
+ ) => {
285
+ const answer = await github.POST('/repos/{owner}/{repo}/pulls/{pull_number}/comments', {
286
+ params: { path: { ...place, pull_number: pull.number } },
287
+ body: { body, in_reply_to: thread.id, commit_id: pull.head.sha, path: thread.path },
288
+ });
289
+ if (answer.error !== undefined) throw failure("The reply wasn't added", answer);
290
+ };
291
+
292
+ /**
293
+ * Submits a review of `review.head` with `drafts` as its comments, in one call: the head they were
294
+ * written on, so each lands on the lines it was written on.
295
+ */
296
+ export const submitReview = async (
297
+ place: RepoPlace,
298
+ pull: number,
299
+ review: {
300
+ readonly event: ReviewEvent;
301
+ readonly body: string;
302
+ readonly head: string;
303
+ readonly drafts: readonly Draft[];
304
+ },
305
+ ) => {
306
+ const answer = await github.POST('/repos/{owner}/{repo}/pulls/{pull_number}/reviews', {
307
+ params: { path: { ...place, pull_number: pull } },
308
+ body: {
309
+ commit_id: review.head,
310
+ event: review.event,
311
+ body: review.body,
312
+ comments: review.drafts.map((draft) => ({ body: draft.body, ...placeFields(draft) })),
313
+ },
314
+ });
315
+ if (answer.error !== undefined) throw failure("The review wasn't submitted", answer);
316
+ };
317
+
318
+ /** Submits the viewer's pending review `review`, started elsewhere, with its drafts. */
319
+ export const submitPending = async (
320
+ place: RepoPlace,
321
+ pull: number,
322
+ review: number,
323
+ submit: { readonly event: ReviewEvent; readonly body: string },
324
+ ) => {
325
+ const answer = await github.POST(
326
+ '/repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/events',
327
+ { params: { path: { ...place, pull_number: pull, review_id: review } }, body: submit },
328
+ );
329
+ if (answer.error !== undefined) throw failure("The review wasn't submitted", answer);
330
+ };
331
+
332
+ /** Deletes the viewer's pending review `review` and its drafts. */
333
+ export const discardPending = async (place: RepoPlace, pull: number, review: number) => {
334
+ const answer = await github.DELETE(
335
+ '/repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}',
336
+ { params: { path: { ...place, pull_number: pull, review_id: review } } },
337
+ );
338
+ if (answer.error !== undefined) throw failure("The pending review wasn't discarded", answer);
339
+ };
340
+
341
+ /** Reads `pull`'s review comments, its reviews and the pull request again, after a review. */
342
+ export const refreshReviews = (client: QueryClient, place: RepoPlace, pull: number) =>
343
+ Promise.all([
344
+ client.invalidateQueries({ queryKey: lineCommentsOf(place, pull).queryKey }),
345
+ client.invalidateQueries({
346
+ queryKey: ['pull-pending-comments', place.owner, place.repo, pull],
347
+ }),
348
+ client.invalidateQueries({ queryKey: reviewsOf(place, pull).queryKey }),
349
+ refreshPull(client, place, pull),
350
+ ]);