ref0-git 0.2.0 → 0.4.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 (210) hide show
  1. package/app/apps/github/.dev.vars.example +2 -1
  2. package/app/apps/github/generated/git-rest.ts +191 -25
  3. package/app/apps/github/generated/routeTree.gen.ts +21 -0
  4. package/app/apps/github/package.json +1 -1
  5. package/app/apps/github/src/branches/branch-list.tsx +8 -4
  6. package/app/apps/github/src/branches/branches.ts +10 -5
  7. package/app/apps/github/src/camo/addresses.ts +120 -0
  8. package/app/apps/github/src/camo/client.ts +125 -0
  9. package/app/apps/github/src/camo/fetch.ts +201 -0
  10. package/app/apps/github/src/camo/lookup.ts +23 -0
  11. package/app/apps/github/src/camo/node.ts +50 -0
  12. package/app/apps/github/src/camo/proxy.ts +116 -0
  13. package/app/apps/github/src/camo/sign-images.ts +307 -0
  14. package/app/apps/github/src/camo/signing.ts +80 -0
  15. package/app/apps/github/src/clients/allowed.ts +111 -18
  16. package/app/apps/github/src/clients/clients.ts +76 -61
  17. package/app/apps/github/src/clients/transport.ts +13 -0
  18. package/app/apps/github/src/code/code-tree.tsx +3 -1
  19. package/app/apps/github/src/code/file-view.tsx +15 -6
  20. package/app/apps/github/src/code/files.ts +26 -19
  21. package/app/apps/github/src/code/go-to-file.tsx +2 -1
  22. package/app/apps/github/src/code/load.ts +41 -23
  23. package/app/apps/github/src/code/markdown-files.ts +13 -2
  24. package/app/apps/github/src/code/ref-pages.ts +14 -5
  25. package/app/apps/github/src/code/ref-switcher.tsx +4 -3
  26. package/app/apps/github/src/code/refs.ts +42 -8
  27. package/app/apps/github/src/code/repo-home.tsx +6 -2
  28. package/app/apps/github/src/code/repo.ts +12 -6
  29. package/app/apps/github/src/code/saved.ts +5 -3
  30. package/app/apps/github/src/code/trees.ts +11 -9
  31. package/app/apps/github/src/components/markdown/markdown.css +6 -0
  32. package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
  33. package/app/apps/github/src/components/owner-card.tsx +3 -1
  34. package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
  35. package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
  36. package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
  37. package/app/apps/github/src/components/signin/device-card.tsx +9 -2
  38. package/app/apps/github/src/components/user-avatar.tsx +2 -1
  39. package/app/apps/github/src/context/context.ts +13 -0
  40. package/app/apps/github/src/diffs/blobs.ts +37 -14
  41. package/app/apps/github/src/diffs/diff-job.ts +53 -0
  42. package/app/apps/github/src/diffs/diff-worker.ts +6 -0
  43. package/app/apps/github/src/diffs/diffing.ts +136 -0
  44. package/app/apps/github/src/diffs/files.ts +4 -3
  45. package/app/apps/github/src/diffs/hunks.tsx +101 -53
  46. package/app/apps/github/src/diffs/patch.ts +20 -11
  47. package/app/apps/github/src/history/commit-diff.ts +10 -5
  48. package/app/apps/github/src/history/commit-list.tsx +3 -1
  49. package/app/apps/github/src/history/commit-page.tsx +4 -2
  50. package/app/apps/github/src/history/history.ts +12 -10
  51. package/app/apps/github/src/hooks/allowed.ts +9 -9
  52. package/app/apps/github/src/hooks/avatars.ts +3 -3
  53. package/app/apps/github/src/hooks/open-counts.ts +5 -4
  54. package/app/apps/github/src/hooks/profiles.ts +26 -12
  55. package/app/apps/github/src/hooks/repos.ts +78 -25
  56. package/app/apps/github/src/inbox/count.ts +30 -29
  57. package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
  58. package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
  59. package/app/apps/github/src/inbox/marks.ts +26 -15
  60. package/app/apps/github/src/inbox/release-tags.ts +7 -6
  61. package/app/apps/github/src/inbox/subjects.ts +5 -4
  62. package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
  63. package/app/apps/github/src/inbox/subscriptions.ts +95 -35
  64. package/app/apps/github/src/inbox/threads.ts +6 -6
  65. package/app/apps/github/src/issues/changes.ts +40 -16
  66. package/app/apps/github/src/issues/counts.ts +8 -5
  67. package/app/apps/github/src/issues/issue-list.tsx +20 -6
  68. package/app/apps/github/src/issues/issue-page.tsx +30 -14
  69. package/app/apps/github/src/issues/issues.ts +195 -46
  70. package/app/apps/github/src/issues/label-dialog.tsx +8 -11
  71. package/app/apps/github/src/issues/labels-page.tsx +35 -3
  72. package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
  73. package/app/apps/github/src/issues/milestones-page.tsx +269 -0
  74. package/app/apps/github/src/issues/new-issue.tsx +3 -1
  75. package/app/apps/github/src/issues/sidebar.tsx +8 -6
  76. package/app/apps/github/src/markdown/README.md +22 -17
  77. package/app/apps/github/src/markdown/context.ts +83 -10
  78. package/app/apps/github/src/markdown/images.ts +3 -2
  79. package/app/apps/github/src/markdown/lookup.ts +17 -11
  80. package/app/apps/github/src/markdown/page-budget.ts +50 -0
  81. package/app/apps/github/src/markdown/patches.ts +74 -32
  82. package/app/apps/github/src/markdown/query.ts +7 -2
  83. package/app/apps/github/src/markdown/remote.ts +106 -0
  84. package/app/apps/github/src/markdown/render.ts +101 -24
  85. package/app/apps/github/src/markdown/texts.ts +43 -0
  86. package/app/apps/github/src/markdown/words-module.d.ts +5 -0
  87. package/app/apps/github/src/markdown/words-plugin.ts +135 -0
  88. package/app/apps/github/src/names/repos.ts +1 -1
  89. package/app/apps/github/src/palette/palette.tsx +28 -10
  90. package/app/apps/github/src/palette/rows.tsx +93 -40
  91. package/app/apps/github/src/palette/server.ts +10 -7
  92. package/app/apps/github/src/palette/targets.ts +1 -0
  93. package/app/apps/github/src/policy.ts +137 -61
  94. package/app/apps/github/src/private-repos.ts +5 -5
  95. package/app/apps/github/src/pulls/compare-page.tsx +6 -3
  96. package/app/apps/github/src/pulls/files-tab.tsx +480 -214
  97. package/app/apps/github/src/pulls/held-summary.ts +178 -0
  98. package/app/apps/github/src/pulls/live.ts +6 -4
  99. package/app/apps/github/src/pulls/merge-box.tsx +17 -10
  100. package/app/apps/github/src/pulls/pull-list.tsx +6 -3
  101. package/app/apps/github/src/pulls/pull-page.tsx +19 -10
  102. package/app/apps/github/src/pulls/pull.ts +68 -40
  103. package/app/apps/github/src/pulls/pulls.ts +39 -22
  104. package/app/apps/github/src/pulls/review-drafts.ts +131 -0
  105. package/app/apps/github/src/pulls/review.ts +374 -99
  106. package/app/apps/github/src/pulls/threads.tsx +152 -0
  107. package/app/apps/github/src/queue/queue-page.tsx +15 -8
  108. package/app/apps/github/src/queue/queue.ts +35 -20
  109. package/app/apps/github/src/releases/latest-release.tsx +3 -1
  110. package/app/apps/github/src/releases/overview.tsx +4 -2
  111. package/app/apps/github/src/releases/release-form.tsx +8 -5
  112. package/app/apps/github/src/releases/release-list.tsx +8 -5
  113. package/app/apps/github/src/releases/release-view.tsx +1 -0
  114. package/app/apps/github/src/releases/releases.ts +33 -23
  115. package/app/apps/github/src/releases/tag-list.tsx +3 -1
  116. package/app/apps/github/src/router.tsx +5 -2
  117. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
  118. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
  119. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
  120. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
  121. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
  122. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
  123. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
  124. package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
  125. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
  126. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
  127. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
  128. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
  129. package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
  130. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
  131. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
  132. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
  133. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
  134. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
  135. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
  136. package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
  137. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
  138. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
  139. package/app/apps/github/src/routes/-nav.tsx +10 -2
  140. package/app/apps/github/src/routes/-root-testing.ts +29 -6
  141. package/app/apps/github/src/routes/__root.tsx +9 -4
  142. package/app/apps/github/src/routes/index.tsx +3 -1
  143. package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
  144. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
  145. package/app/apps/github/src/seed/acme.ts +1 -1
  146. package/app/apps/github/src/seed/seed.ts +199 -120
  147. package/app/apps/github/src/server.ts +24 -15
  148. package/app/apps/github/src/settings/account-avatar.tsx +4 -1
  149. package/app/apps/github/src/settings/general-settings.tsx +3 -1
  150. package/app/apps/github/src/settings/general.ts +4 -4
  151. package/app/apps/github/src/settings/hook-form.tsx +3 -1
  152. package/app/apps/github/src/settings/hook-list.tsx +5 -2
  153. package/app/apps/github/src/settings/hooks.ts +7 -7
  154. package/app/apps/github/src/settings/org-settings.tsx +3 -1
  155. package/app/apps/github/src/settings/orgs.ts +21 -11
  156. package/app/apps/github/src/settings/settings-layout.tsx +3 -1
  157. package/app/apps/github/src/signin/approval.ts +4 -3
  158. package/app/apps/github/src/signin/auth.ts +9 -2
  159. package/app/apps/github/src/signin/device-code.ts +8 -3
  160. package/app/apps/github/src/signin/device-prompt.ts +28 -3
  161. package/app/apps/github/src/signin/revoke.ts +36 -0
  162. package/app/apps/github/tsconfig.json +4 -1
  163. package/app/apps/github/vite.config.ts +8 -0
  164. package/app/pnpm-workspace.yaml +9 -5
  165. package/app/tsconfig.base.json +1 -0
  166. package/dist/cli/child.mjs +1 -1
  167. package/dist/cli/credentials.mjs +4 -4
  168. package/dist/cli/documents.mjs +32 -22
  169. package/dist/cli/events.mjs +1 -1
  170. package/dist/cli/failure.mjs +20 -7
  171. package/dist/cli/folders.mjs +2 -2
  172. package/dist/cli/git-remote-ref0.mjs +47 -22
  173. package/dist/cli/git.mjs +26 -5
  174. package/dist/cli/helpers.mjs +168 -35
  175. package/dist/cli/hosts.mjs +3 -3
  176. package/dist/cli/output.mjs +2 -2
  177. package/dist/cli/prompt.mjs +1 -1
  178. package/dist/cli/queue.mjs +7 -7
  179. package/dist/cli/ref0-git.mjs +2 -2
  180. package/dist/cli/repos.mjs +35 -18
  181. package/dist/cli/resources.mjs +5 -5
  182. package/dist/cli/retry-after.mjs +8 -0
  183. package/dist/cli/setup.mjs +172 -66
  184. package/dist/cli/sign-in.mjs +65 -23
  185. package/dist/cli/sign-ins.mjs +70 -13
  186. package/dist/cli/sqlite.mjs +2 -2
  187. package/dist/cli/tokens.mjs +3 -3
  188. package/dist/cli/vendor.mjs +1 -1
  189. package/dist/init/app.mjs +18 -20
  190. package/dist/init/choices.mjs +1 -1
  191. package/dist/init/cloudflare.mjs +15 -19
  192. package/dist/init/create.mjs +4 -3
  193. package/dist/init/detect.mjs +4 -4
  194. package/dist/init/files.mjs +121 -9
  195. package/dist/init/frameworks.mjs +16 -0
  196. package/dist/init/git-module.mjs +22 -7
  197. package/dist/init/jsonc.mjs +9 -7
  198. package/dist/init/metadata.mjs +9 -3
  199. package/dist/init/mounts.mjs +13 -10
  200. package/dist/init/next.mjs +3 -5
  201. package/dist/init/node-app.mjs +3 -3
  202. package/dist/init/node.mjs +41 -42
  203. package/dist/init/nuxt.mjs +153 -27
  204. package/dist/init/stores.mjs +14 -9
  205. package/dist/init/sveltekit.mjs +4 -2
  206. package/dist/init/template.mjs +9 -6
  207. package/dist/init/templates.mjs +64 -48
  208. package/dist/init/vercel.mjs +37 -36
  209. package/dist/init/versions.mjs +3 -3
  210. package/package.json +6 -5
@@ -9,7 +9,10 @@ import { OrgSettings } from '../../../settings/org-settings.tsx';
9
9
  export const Route = createFileRoute('/orgs/$owner/settings')({
10
10
  loader: async ({ params, context }) => {
11
11
  // The owner's level reads the same owner, at the same time, so the two share the one read.
12
- const owner = await cached(context.queryClient, ownerAt(params.owner, context.viewer?.login));
12
+ const owner = await cached(
13
+ context.queryClient,
14
+ ownerAt(context.clients, params.owner, context.viewer?.login),
15
+ );
13
16
  if (owner?.kind !== 'org') throw notFound();
14
17
  },
15
18
  component: OrgSettingsPage,
@@ -2,7 +2,7 @@
2
2
  * What the seed makes: the org `acme`, with Pip and Mo from ref0's cast, and three of its repos,
3
3
  * each with a description, a license and a history in its own language, and most with branches,
4
4
  * pull requests and issues, so a local copy is a demo to try. Every step
5
- * is named, by a repo's ID, a branch, a label, a title or a tag, and the seed looks each up by that
5
+ * is named, by a repo's name, a branch, a label, a title or a tag, and the seed looks each up by that
6
6
  * name before it makes it.
7
7
  */
8
8
 
@@ -1,21 +1,19 @@
1
- import type {
2
- CreatedToken,
3
- GitAdapter,
4
- GitError,
5
- Oid,
6
- RefName,
7
- RepoId,
8
- Result,
9
- Signature,
10
- } from '@ref0/git';
1
+ import type { CreatedToken, GitError, Oid, RefName, RepoName, Result, Signature } from '@ref0/git';
11
2
  import { createRestClient } from '@ref0/git/rest';
3
+ import type { Change, Committed, Read, Scope, Snapshot } from '@ref0/infra';
12
4
  import type { RestClient } from '@ref0/git/rest';
13
5
  import * as Schema from 'effect/Schema';
14
6
 
15
7
  import { org, pip, repos } from './acme.ts';
16
8
  import type { Person, SeedCommit, SeedIssue, SeedPull, SeedRepo } from './acme.ts';
17
9
 
18
- /** What the seed writes through: the host's own handler and its store, and the admin secret. */
10
+ /** The records the seed keeps its progress in, beside Git's own: `read` and `commit`, as a store's. */
11
+ export interface SeedRecords {
12
+ readonly read: (scope: Scope, reads: Read[]) => Promise<Snapshot>;
13
+ readonly commit: (scope: Scope, change: Change) => Promise<Committed>;
14
+ }
15
+
16
+ /** What the seed writes through: the host's own handler and its records, and the admin secret. */
19
17
  export interface SeedHost {
20
18
  /** The host's handler, which every write goes through, as a request from outside would. */
21
19
  readonly fetch: (request: Request) => Promise<Response>;
@@ -23,8 +21,8 @@ export interface SeedHost {
23
21
  readonly origin: string;
24
22
  /** Signs in as the admin, who makes the org's repos and each person's token. */
25
23
  readonly adminToken: string;
26
- /** The adapter's store, which keeps the seed's progress beside Git's own records. */
27
- readonly store: Store;
24
+ /** Git's records, which keep the seed's progress beside Git's own. */
25
+ readonly store: SeedRecords;
28
26
  }
29
27
 
30
28
  /** What a call to `seed` did: made what was missing, or left a host that needs none. */
@@ -46,8 +44,6 @@ type Progress = typeof Progress.Type;
46
44
 
47
45
  const decodeProgress = Schema.decodeUnknownSync(Progress);
48
46
 
49
- type Store = GitAdapter['store'];
50
-
51
47
  /** The `app/seed` record, in a scope of the app's own, apart from Git's `git/` scopes. */
52
48
  const progressScope = 'app';
53
49
 
@@ -66,7 +62,7 @@ const value = <A>(result: Result<A>, doing: string): A => {
66
62
 
67
63
  const missing = (error: GitError) => error.code === 'NOT_FOUND';
68
64
 
69
- const readProgress = async (store: Store) => {
65
+ const readProgress = async (store: SeedRecords) => {
70
66
  const snapshot = await store.read(progressScope, [progressKey]);
71
67
  const row = snapshot.results[0]?.[0];
72
68
 
@@ -77,7 +73,7 @@ const readProgress = async (store: Store) => {
77
73
  };
78
74
 
79
75
  /** Saves `progress` if nothing moved the record since `version`; whether it did. */
80
- const saveProgress = async (store: Store, version: number, progress: Progress) => {
76
+ const saveProgress = async (store: SeedRecords, version: number, progress: Progress) => {
81
77
  const committed = await store.commit(progressScope, {
82
78
  id: `seed-${progress.state}-${progress.since}-${progress.tokensExpire?.at(-1) ?? 0}`,
83
79
  expect: version,
@@ -91,7 +87,7 @@ const saveProgress = async (store: Store, version: number, progress: Progress) =
91
87
  * The progress to go on from: a cut seed's, or a new one when the host holds no repos. A host
92
88
  * whose seed is done, or that has repos of its own, gets none.
93
89
  */
94
- const begin = async (store: Store, admin: RestClient): Promise<Progress | undefined> => {
90
+ const begin = async (store: SeedRecords, admin: RestClient): Promise<Progress | undefined> => {
95
91
  const { version, progress } = await readProgress(store);
96
92
  if (progress !== undefined) return progress.state === 'running' ? progress : undefined;
97
93
 
@@ -152,14 +148,35 @@ const dropInCall =
152
148
  /** What the seed reads back from the drop-in, to find what it made before. */
153
149
  const Numbered = Schema.Struct({ number: Schema.Number });
154
150
 
155
- const Issues = Schema.Array(
156
- Schema.Struct({
157
- number: Schema.Number,
158
- title: Schema.String,
159
- state: Schema.String,
160
- pull_request: Schema.optional(Schema.Unknown),
161
- }),
162
- );
151
+ const MilestoneRef = Schema.NullOr(Numbered);
152
+
153
+ const CreatedItem = Schema.Struct({
154
+ number: Schema.Number,
155
+ milestone: MilestoneRef,
156
+ });
157
+
158
+ const Described = Schema.Struct({
159
+ description: Schema.NullOr(Schema.String),
160
+ });
161
+
162
+ const ExistingPull = Schema.Struct({
163
+ number: Schema.Number,
164
+ head: Schema.Struct({ label: Schema.String }),
165
+ milestone: MilestoneRef,
166
+ merged_at: Schema.NullOr(Schema.String),
167
+ });
168
+
169
+ type ExistingPull = typeof ExistingPull.Type;
170
+
171
+ const ExistingIssue = Schema.Struct({
172
+ number: Schema.Number,
173
+ title: Schema.String,
174
+ state: Schema.String,
175
+ milestone: MilestoneRef,
176
+ pull_request: Schema.optional(Schema.Unknown),
177
+ });
178
+
179
+ type ExistingIssue = typeof ExistingIssue.Type;
163
180
 
164
181
  const Authored = Schema.Array(
165
182
  Schema.Struct({
@@ -168,14 +185,18 @@ const Authored = Schema.Array(
168
185
  }),
169
186
  );
170
187
 
171
- const decodePulls = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Array(Numbered)));
188
+ const decodePulls = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Array(ExistingPull)));
172
189
 
173
- const decodeIssues = Schema.decodeUnknownSync(Schema.fromJsonString(Issues));
190
+ const decodeIssues = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Array(ExistingIssue)));
174
191
 
175
192
  const decodeAuthored = Schema.decodeUnknownSync(Schema.fromJsonString(Authored));
176
193
 
177
194
  const decodeNumbered = Schema.decodeUnknownSync(Schema.fromJsonString(Numbered));
178
195
 
196
+ const decodeCreated = Schema.decodeUnknownSync(Schema.fromJsonString(CreatedItem));
197
+
198
+ const decodeDescribed = Schema.decodeUnknownSync(Schema.fromJsonString(Described));
199
+
179
200
  /** A repo's milestones, by their titles. */
180
201
  const decodeTitled = Schema.decodeUnknownSync(
181
202
  Schema.fromJsonString(
@@ -183,17 +204,6 @@ const decodeTitled = Schema.decodeUnknownSync(
183
204
  ),
184
205
  );
185
206
 
186
- /** The milestone an issue or a pull request is on. */
187
- const decodeMilestoned = Schema.decodeUnknownSync(
188
- Schema.fromJsonString(
189
- Schema.Struct({ milestone: Schema.NullOr(Schema.Struct({ number: Schema.Number })) }),
190
- ),
191
- );
192
-
193
- const decodeMerged = Schema.decodeUnknownSync(
194
- Schema.fromJsonString(Schema.Struct({ merged: Schema.Boolean })),
195
- );
196
-
197
207
  /**
198
208
  * Who the seed acts as: the admin's Git calls and drop-in calls, and each person's Git calls and
199
209
  * drop-in calls.
@@ -205,19 +215,23 @@ interface Cast {
205
215
  readonly call: (person: Person) => Call;
206
216
  }
207
217
 
208
- const makeRepo = async (admin: RestClient, id: RepoId) => {
209
- const found = await admin.repos.get(id, {});
210
- if (found.kind === 'success') return;
218
+ const ensureRepo = async (cast: Cast, id: RepoName, path: string, description: string) => {
219
+ const found = await cast.adminCall('GET', path);
211
220
 
212
- if (!missing(found.error)) value(found, `read ${id}`);
221
+ if (found.status === 404) {
222
+ value(await cast.admin.repos.create({ name: id, public: true }), `make ${id}`);
223
+ } else if (decodeDescribed(found.text).description === (description || null)) {
224
+ return;
225
+ }
213
226
 
214
- value(await admin.repos.create({ id, public: true }), `make ${id}`);
227
+ // A repo's settings are its admin's to change, which a person's `write` token isn't.
228
+ await cast.adminCall('PATCH', path, { description });
215
229
  };
216
230
 
217
231
  /** Each commit in turn on `parent`, as `git commit` makes them; their IDs, oldest first. */
218
232
  const commitAll = async (
219
233
  git: RestClient,
220
- id: RepoId,
234
+ id: RepoName,
221
235
  parent: Oid | undefined,
222
236
  commits: readonly SeedCommit[],
223
237
  since: number,
@@ -241,42 +255,60 @@ const commitAll = async (
241
255
 
242
256
  /**
243
257
  * The repo's history, pushed as Pip: its commits, each dated from `since`, so a seed started again
244
- * makes the same objects, then each branch and the tag that isn't there yet, at once.
258
+ * makes the same objects, then each branch and the tag that isn't there yet, at once. Checks the
259
+ * expected refs first so a resumed seed skips rebuilding commits and tags once every ref exists.
245
260
  */
246
- const pushHistory = async (git: RestClient, id: RepoId, repo: SeedRepo, since: number) => {
247
- const main = await commitAll(git, id, undefined, repo.main, since);
248
- const refs: { readonly ref: RefName; readonly to: Oid }[] = [];
249
- refs.push({ ref: 'refs/heads/main', to: main.at(-1) ?? '' });
250
-
251
- for (const branch of repo.branches) {
252
- const made = await commitAll(git, id, main[branch.from], branch.commits, since);
253
- refs.push({ ref: `refs/heads/${branch.name}`, to: made.at(-1) ?? '' });
254
- }
255
-
261
+ const pushHistory = async (git: RestClient, id: RepoName, repo: SeedRepo, since: number) => {
256
262
  const { release } = repo;
257
-
258
- if (release !== undefined) {
259
- const tagged = repo.main[release.at];
260
- const tag = await git.tags.create(id, {
261
- object: main[release.at] ?? '',
262
- tag: release.tag,
263
- tagger: signature(pip, since, (tagged?.daysAgo ?? 0) - 1),
264
- message: `${release.title}\n`,
265
- });
266
- refs.push({ ref: `refs/tags/${release.tag}`, to: value(tag, `tag ${release.tag}`).oid });
267
- }
268
-
269
- const absent = [];
270
-
271
- for (const { ref, to } of refs) {
263
+ const targets: readonly {
264
+ readonly ref: RefName;
265
+ readonly build: (main: readonly Oid[]) => Promise<Oid>;
266
+ }[] = [
267
+ { ref: 'refs/heads/main', build: (main) => Promise.resolve(main.at(-1) ?? '') },
268
+ ...repo.branches.map((branch) => ({
269
+ ref: `refs/heads/${branch.name}`,
270
+ build: async (main: readonly Oid[]) =>
271
+ (await commitAll(git, id, main[branch.from], branch.commits, since)).at(-1) ?? '',
272
+ })),
273
+ ...(release === undefined
274
+ ? []
275
+ : [
276
+ {
277
+ ref: `refs/tags/${release.tag}`,
278
+ build: async (main: readonly Oid[]) => {
279
+ const tagged = repo.main[release.at];
280
+ const tag = await git.tags.create(id, {
281
+ object: main[release.at] ?? '',
282
+ tag: release.tag,
283
+ tagger: signature(pip, since, (tagged?.daysAgo ?? 0) - 1),
284
+ message: `${release.title}\n`,
285
+ });
286
+
287
+ return value(tag, `tag ${release.tag}`).oid;
288
+ },
289
+ },
290
+ ]),
291
+ ];
292
+
293
+ const missingRefs = new Set<RefName>();
294
+
295
+ for (const { ref } of targets) {
272
296
  const found = await git.refs.get(id, { ref });
273
297
  if (found.kind === 'success') continue;
274
298
 
275
299
  if (!missing(found.error)) value(found, `read ${ref}`);
276
- absent.push({ ref, from: null, to });
300
+ missingRefs.add(ref);
277
301
  }
278
302
 
279
- if (absent.length === 0) return;
303
+ if (missingRefs.size === 0) return;
304
+
305
+ const main = await commitAll(git, id, undefined, repo.main, since);
306
+ const absent = [];
307
+
308
+ for (const { ref, build } of targets) {
309
+ const to = await build(main);
310
+ if (missingRefs.has(ref)) absent.push({ ref, from: null, to });
311
+ }
280
312
 
281
313
  const updated = value(await git.refs.update(id, { updates: absent, atomic: true }), 'push');
282
314
  const refused = updated.updates.find((update) => update.kind === 'rejected');
@@ -309,14 +341,16 @@ const makeMilestones = async (call: Call, path: string, repo: SeedRepo) => {
309
341
  };
310
342
 
311
343
  /** Puts the issue or pull request `number` on `milestone`, unless it's on it already. */
312
- const placeOn = async (call: Call, path: string, number: number, milestone?: number) => {
313
- if (milestone === undefined) return;
314
-
315
- const issue = decodeMilestoned((await call('GET', `${path}/issues/${number}`)).text);
344
+ const placeOn = async (
345
+ call: Call,
346
+ path: string,
347
+ number: number,
348
+ currentMilestone: number | null,
349
+ milestone?: number,
350
+ ) => {
351
+ if (milestone === undefined || currentMilestone === milestone) return;
316
352
 
317
- if (issue.milestone?.number !== milestone) {
318
- await call('PATCH', `${path}/issues/${number}`, { milestone });
319
- }
353
+ await call('PATCH', `${path}/issues/${number}`, { milestone });
320
354
  };
321
355
 
322
356
  /** Whether `person` already wrote `body` among a pull request's reviews or an issue's comments. */
@@ -331,13 +365,12 @@ const openPull = async (
331
365
  path: string,
332
366
  pull: SeedPull,
333
367
  milestones: ReadonlyMap<string, number>,
368
+ found: ExistingPull | undefined,
334
369
  ) => {
335
370
  const author = cast.call(pull.by);
336
- const query = `state=all&head=${org.login}:${encodeURIComponent(pull.branch)}`;
337
- const [found] = decodePulls((await author('GET', `${path}/pulls?${query}`)).text);
338
- const number =
339
- found?.number ??
340
- decodeNumbered(
371
+ const item =
372
+ found ??
373
+ decodeCreated(
341
374
  (
342
375
  await author('POST', `${path}/pulls`, {
343
376
  title: pull.title,
@@ -346,24 +379,26 @@ const openPull = async (
346
379
  base: 'main',
347
380
  })
348
381
  ).text,
349
- ).number;
350
- await placeOn(author, path, number, milestones.get(pull.milestone ?? ''));
382
+ );
383
+ await placeOn(
384
+ author,
385
+ path,
386
+ item.number,
387
+ item.milestone?.number ?? null,
388
+ milestones.get(pull.milestone ?? ''),
389
+ );
351
390
 
352
391
  const reviewer = cast.call(pull.review.by);
353
- const reviews = await reviewer('GET', `${path}/pulls/${number}/reviews`);
392
+ const reviews = await reviewer('GET', `${path}/pulls/${item.number}/reviews`);
354
393
 
355
394
  if (!wrote(reviews.text, pull.review.by)) {
356
395
  const { event, body } = pull.review;
357
- await reviewer('POST', `${path}/pulls/${number}/reviews`, { event, body });
396
+ await reviewer('POST', `${path}/pulls/${item.number}/reviews`, { event, body });
358
397
  }
359
398
 
360
- if (!pull.merged) return;
399
+ if (!pull.merged || found?.merged_at != null) return;
361
400
 
362
- const state = decodeMerged((await author('GET', `${path}/pulls/${number}`)).text);
363
-
364
- if (!state.merged) {
365
- await author('PUT', `${path}/pulls/${number}/merge`, { merge_method: 'merge' });
366
- }
401
+ await author('PUT', `${path}/pulls/${item.number}/merge`, { merge_method: 'merge' });
367
402
  };
368
403
 
369
404
  /** The issue by its title, opened by its author if it isn't open yet, its comments, then closed. */
@@ -372,15 +407,12 @@ const openIssue = async (
372
407
  path: string,
373
408
  issue: SeedIssue,
374
409
  milestones: ReadonlyMap<string, number>,
410
+ found: ExistingIssue | undefined,
375
411
  ) => {
376
412
  const author = cast.call(issue.by);
377
- const listed = decodeIssues((await author('GET', `${path}/issues?state=all&per_page=100`)).text);
378
- const found = listed.find(
379
- (item) => item.pull_request === undefined && item.title === issue.title,
380
- );
381
- const number =
382
- found?.number ??
383
- decodeNumbered(
413
+ const item =
414
+ found ??
415
+ decodeCreated(
384
416
  (
385
417
  await author('POST', `${path}/issues`, {
386
418
  title: issue.title,
@@ -388,20 +420,26 @@ const openIssue = async (
388
420
  labels: issue.labels,
389
421
  })
390
422
  ).text,
391
- ).number;
392
- await placeOn(author, path, number, milestones.get(issue.milestone ?? ''));
423
+ );
424
+ await placeOn(
425
+ author,
426
+ path,
427
+ item.number,
428
+ item.milestone?.number ?? null,
429
+ milestones.get(issue.milestone ?? ''),
430
+ );
393
431
 
394
432
  for (const comment of issue.comments) {
395
433
  const commenter = cast.call(comment.by);
396
- const comments = await commenter('GET', `${path}/issues/${number}/comments?per_page=100`);
434
+ const comments = await commenter('GET', `${path}/issues/${item.number}/comments?per_page=100`);
397
435
 
398
436
  if (!wrote(comments.text, comment.by, comment.body)) {
399
- await commenter('POST', `${path}/issues/${number}/comments`, { body: comment.body });
437
+ await commenter('POST', `${path}/issues/${item.number}/comments`, { body: comment.body });
400
438
  }
401
439
  }
402
440
 
403
441
  if (issue.closed && found?.state !== 'closed') {
404
- await author('PATCH', `${path}/issues/${number}`, {
442
+ await author('PATCH', `${path}/issues/${item.number}`, {
405
443
  state: 'closed',
406
444
  state_reason: 'completed',
407
445
  });
@@ -423,20 +461,48 @@ const publishRelease = async (call: Call, path: string, repo: SeedRepo) => {
423
461
  };
424
462
 
425
463
  const seedRepo = async (cast: Cast, repo: SeedRepo, since: number) => {
426
- const id: RepoId = `${org.login}/${repo.name}`;
464
+ const id: RepoName = `${org.login}/${repo.name}`;
427
465
  const path = `/repos/${id}`;
466
+ const asPip = cast.call(pip);
428
467
 
429
- await makeRepo(cast.admin, id);
430
- // A repo's settings are its admin's to change, which a person's `write` token isn't.
431
- await cast.adminCall('PATCH', path, { description: repo.description });
468
+ await ensureRepo(cast, id, path, repo.description);
432
469
  await pushHistory(cast.git(pip), id, repo, since);
433
- await makeLabels(cast.call(pip), path, repo);
434
- const milestones = await makeMilestones(cast.call(pip), path, repo);
470
+ await makeLabels(asPip, path, repo);
471
+ const milestones = await makeMilestones(asPip, path, repo);
472
+
473
+ if (repo.pulls.length > 0) {
474
+ const listedPulls = decodePulls(
475
+ (await asPip('GET', `${path}/pulls?state=all&per_page=100`)).text,
476
+ );
477
+ const pullsByHead = new Map<string, ExistingPull>();
478
+
479
+ for (const item of listedPulls) {
480
+ if (!pullsByHead.has(item.head.label)) pullsByHead.set(item.head.label, item);
481
+ }
482
+
483
+ for (const pull of repo.pulls) {
484
+ await openPull(cast, path, pull, milestones, pullsByHead.get(`${org.login}:${pull.branch}`));
485
+ }
486
+ }
487
+
488
+ if (repo.issues.length > 0) {
489
+ const listedIssues = decodeIssues(
490
+ (await asPip('GET', `${path}/issues?state=all&per_page=100`)).text,
491
+ );
492
+ const issuesByTitle = new Map<string, ExistingIssue>();
435
493
 
436
- for (const pull of repo.pulls) await openPull(cast, path, pull, milestones);
494
+ for (const item of listedIssues) {
495
+ if (item.pull_request === undefined && !issuesByTitle.has(item.title)) {
496
+ issuesByTitle.set(item.title, item);
497
+ }
498
+ }
499
+
500
+ for (const issue of repo.issues) {
501
+ await openIssue(cast, path, issue, milestones, issuesByTitle.get(issue.title));
502
+ }
503
+ }
437
504
 
438
- for (const issue of repo.issues) await openIssue(cast, path, issue, milestones);
439
- await publishRelease(cast.call(pip), path, repo);
505
+ await publishRelease(asPip, path, repo);
440
506
  };
441
507
 
442
508
  const members: ReadonlySet<string> = new Set(org.members.map((person) => person.login));
@@ -500,7 +566,7 @@ export const seed = async (host: SeedHost): Promise<SeedOutcome> => {
500
566
  if (!marked) throw new Error('Another start is seeding this host');
501
567
 
502
568
  const issued = new Map<string, CreatedToken>();
503
- let revoked: readonly Result<void>[] = [];
569
+ const revoked: Result<void>[] = [];
504
570
 
505
571
  try {
506
572
  for (const person of org.members) {
@@ -515,17 +581,30 @@ export const seed = async (host: SeedHost): Promise<SeedOutcome> => {
515
581
  issued.set(person.login, value(token, `make ${person.login}'s token`));
516
582
  }
517
583
 
584
+ const gitClients = new Map<string, RestClient>();
585
+ const dropInCalls = new Map<string, Call>();
518
586
  const secret = (person: Person) => issued.get(person.login)?.secret ?? '';
587
+ const memo = <A>(cache: Map<string, A>, person: Person, make: (token: string) => A): A => {
588
+ const existing = cache.get(person.login);
589
+ if (existing !== undefined) return existing;
590
+
591
+ const made = make(secret(person));
592
+ cache.set(person.login, made);
593
+
594
+ return made;
595
+ };
596
+
519
597
  const cast: Cast = {
520
598
  admin,
521
599
  adminCall: dropInCall(host, host.adminToken),
522
- git: (person) => client(secret(person)),
523
- call: (person) => dropInCall(host, secret(person)),
600
+ git: (person) => memo(gitClients, person, client),
601
+ call: (person) => memo(dropInCalls, person, (token) => dropInCall(host, token)),
524
602
  };
525
603
 
526
604
  for (const repo of repos) await seedRepo(cast, repo, progress.since);
527
605
  } finally {
528
- revoked = await Promise.all([...issued.values()].map((token) => admin.tokens.revoke(token.id)));
606
+ // One at a time: revokes at once in one scope miss each other's writes, and some run out of tries.
607
+ for (const token of issued.values()) revoked.push(await admin.tokens.revoke(token.id));
529
608
  }
530
609
 
531
610
  // A revoke that failed leaves the seed running, so the next call revokes what it left.
@@ -1,18 +1,10 @@
1
+ import { Records } from '@ref0/infra';
1
2
  import handler, { createServerEntry } from '@tanstack/react-start/server-entry';
2
3
 
4
+ import { workersFetch } from './camo/fetch.ts';
5
+ import { imageProxy } from './camo/proxy.ts';
3
6
  import type { AppContext } from './context/context.ts';
4
- import {
5
- adapter,
6
- auth,
7
- directory,
8
- env,
9
- git,
10
- github,
11
- pictures,
12
- policy,
13
- rest,
14
- sessionKey,
15
- } from './git.ts';
7
+ import { auth, directory, env, git, github, pictures, policy, rest, sessionKey } from './git.ts';
16
8
  import { hostRules } from './policy.ts';
17
9
  import { shownRules } from './settings/rules.ts';
18
10
  import { sessionCookieOf, sessionEnder, sessionFrom } from './signin/auth.ts';
@@ -27,6 +19,18 @@ const owned = async (request: Request) =>
27
19
  /** Git's answer for a URL it doesn't own: the app's server calls never reach the app. */
28
20
  const api = async (request: Request) => (await owned(request)) ?? rest.fetch(request);
29
21
 
22
+ /**
23
+ * The image proxy (Q860): a text's remote images load through `/_camo/`, and the pages' CSP loads
24
+ * no other. Without it, and with `IMAGE_PROXY=off`, they load from their own origin.
25
+ */
26
+ const images = imageProxy({
27
+ secret: env.SESSION_SECRET,
28
+ appOrigin: env.APP_ORIGIN,
29
+ setting: env.IMAGE_PROXY,
30
+ fetch: workersFetch,
31
+ cache: caches.default,
32
+ });
33
+
30
34
  /** The host's push rules, as a repo's settings show them. */
31
35
  const rules = shownRules(hostRules);
32
36
 
@@ -53,7 +57,11 @@ const seeded = () => {
53
57
  fetch: api,
54
58
  origin: env.APP_ORIGIN,
55
59
  adminToken: env.ADMIN_TOKEN,
56
- store: adapter.store,
60
+ // Git's records, on its runtime, keep the seed's progress beside Git's own.
61
+ store: {
62
+ read: (scope, reads) => git.runtime.runPromise(Records.read(scope, reads)),
63
+ commit: (scope, change) => git.runtime.runPromise(Records.commit(scope, change)),
64
+ },
57
65
  });
58
66
  })
59
67
  .then(
@@ -66,7 +74,7 @@ const seeded = () => {
66
74
 
67
75
  /** Q8's order: the drop-in, then Git, then the app. A URL one owns never falls through. */
68
76
  export default createServerEntry({
69
- fetch: async (incoming) => {
77
+ fetch: images.around(async (incoming) => {
70
78
  // A host session is the app's server's to set in this Worker, never a caller's to send
71
79
  // (Q520): every route, the APIs, the app and any upgrade, sees the request without one.
72
80
  const request = withoutHostSession(incoming);
@@ -90,8 +98,9 @@ export default createServerEntry({
90
98
  avatars: pictures,
91
99
  accounts: directory,
92
100
  git,
101
+ images,
93
102
  };
94
103
 
95
104
  return handler.fetch(request, { context });
96
- },
105
+ }),
97
106
  });
@@ -1,3 +1,4 @@
1
+ import { useClients } from '../clients/clients.ts';
1
2
  import { avatarUrl } from '../components/avatar-url.ts';
2
3
  import { type Account, UserAvatar } from '../components/user-avatar.tsx';
3
4
  import { avatarAt } from '../hooks/avatars.ts';
@@ -23,6 +24,8 @@ export function AccountAvatar({
23
24
  /** Why the viewer can't change it, or none when they can. */
24
25
  readonly refusal?: string | undefined;
25
26
  }) {
27
+ const clients = useClients();
28
+
26
29
  return (
27
30
  <AvatarSection
28
31
  place={{ owner: login }}
@@ -34,7 +37,7 @@ export function AccountAvatar({
34
37
  preview={<UserAvatar login={login} account={account} size="xl" />}
35
38
  onShown={(client, hash) =>
36
39
  client.setQueryData(
37
- avatarAt(login).queryKey,
40
+ avatarAt(clients, login).queryKey,
38
41
  hash === null ? null : avatarUrl({ owner: login }, hash),
39
42
  )
40
43
  }
@@ -4,6 +4,7 @@ import { LockIcon } from 'lucide-react';
4
4
  import { type FormEvent, type ReactNode, useState } from 'react';
5
5
  import { toast } from 'sonner';
6
6
 
7
+ import { useClients } from '../clients/clients.ts';
7
8
  import type { RepoPlace } from '../code/places.ts';
8
9
  import { ConfirmAction } from '../components/confirm-action.tsx';
9
10
  import { setIconHash } from '../components/repos/icon-hashes.ts';
@@ -125,8 +126,9 @@ function Section({
125
126
  * buttons, then the danger zone. Each is changed as the viewer, through the host's sign-in.
126
127
  */
127
128
  export function GeneralSettings({ place }: { readonly place: RepoPlace }) {
129
+ const clients = useClients();
128
130
  const allowed = useAllowed(place);
129
- const asked = useQuery(generalSettings(place));
131
+ const asked = useQuery(generalSettings(clients, place));
130
132
 
131
133
  if (!allowed.has('repo.update')) {
132
134
  return (
@@ -1,7 +1,7 @@
1
1
  import { queryOptions } from '@tanstack/react-query';
2
2
  import * as Schema from 'effect/Schema';
3
3
 
4
- import { github } from '../clients/clients.ts';
4
+ import type { Clients } from '../clients/clients.ts';
5
5
  import { hostAnswer } from '../clients/host-answer.ts';
6
6
  import type { RepoPlace } from '../code/places.ts';
7
7
  import { refNames } from '../code/repo.ts';
@@ -21,15 +21,15 @@ export interface General {
21
21
  }
22
22
 
23
23
  /** The repo's General settings, and its first 100 branches, which its default may be. */
24
- export const generalSettings = (place: RepoPlace) =>
24
+ export const generalSettings = (clients: Clients, place: RepoPlace) =>
25
25
  queryOptions({
26
26
  queryKey: ['general', place.owner, place.repo],
27
27
  queryFn: async () => {
28
- const answer = await github.GET('/repos/{owner}/{repo}', { params: { path: place } });
28
+ const answer = await clients.github.GET('/repos/{owner}/{repo}', { params: { path: place } });
29
29
  if (answer.data === undefined) throw failure("The settings didn't load", answer);
30
30
 
31
31
  const repo = answer.data;
32
- const branches = await refNames(place, 'branches', undefined);
32
+ const branches = await refNames(clients, place, 'branches', undefined);
33
33
  const general: General = {
34
34
  name: repo.name,
35
35
  description: repo.description ?? '',