ref0-git 0.14.0 → 0.25.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 (45) hide show
  1. package/app/apps/github/generated/git-rest.ts +170 -3
  2. package/app/apps/github/generated/routeTree.gen.ts +42 -21
  3. package/app/apps/github/src/clients/host-calls.ts +59 -34
  4. package/app/apps/github/src/components/states/states.tsx +1 -19
  5. package/app/apps/github/src/components/view-tabs.tsx +6 -2
  6. package/app/apps/github/src/context/context.ts +7 -4
  7. package/app/apps/github/src/context/host.ts +72 -36
  8. package/app/apps/github/src/issues/issue-list.tsx +11 -3
  9. package/app/apps/github/src/issues/issues.ts +11 -8
  10. package/app/apps/github/src/lists/across-list.tsx +358 -0
  11. package/app/apps/github/src/lists/across.ts +239 -0
  12. package/app/apps/github/src/names/owners.ts +3 -1
  13. package/app/apps/github/src/palette/targets.ts +3 -2
  14. package/app/apps/github/src/policy.ts +23 -30
  15. package/app/apps/github/src/private-repos.ts +24 -24
  16. package/app/apps/github/src/pulls/pulls.ts +2 -1
  17. package/app/apps/github/src/routes/-nav.tsx +40 -12
  18. package/app/apps/github/src/routes/issues.tsx +15 -0
  19. package/app/apps/github/src/routes/orgs/$owner/-org-list.ts +31 -0
  20. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +10 -3
  21. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +10 -3
  22. package/app/apps/github/src/routes/pulls.tsx +15 -0
  23. package/app/apps/github/src/seed/seed.ts +104 -52
  24. package/app/apps/github/src/server.ts +17 -7
  25. package/app/apps/github/src/signin/approval.ts +24 -16
  26. package/app/apps/github/src/signin/attempts.ts +1 -1
  27. package/app/apps/github/src/signin/auth.ts +27 -19
  28. package/app/apps/github/src/signin/device-prompt.ts +1 -2
  29. package/app/apps/github/src/signin/revoke.ts +9 -17
  30. package/app/apps/github/src/signin/unborn.ts +33 -20
  31. package/app/pnpm-workspace.yaml +2 -2
  32. package/dist/cli/setup.mjs +3 -3
  33. package/dist/cli/sign-in.mjs +2 -3
  34. package/dist/init/app.mjs +5 -4
  35. package/dist/init/cloudflare.mjs +14 -8
  36. package/dist/init/create.mjs +1 -1
  37. package/dist/init/git-module.mjs +13 -5
  38. package/dist/init/metadata.mjs +1 -1
  39. package/dist/init/node.mjs +1 -1
  40. package/dist/init/stores.mjs +1 -1
  41. package/dist/init/template.mjs +3 -0
  42. package/dist/init/templates.mjs +34 -21
  43. package/dist/init/versions.mjs +1 -1
  44. package/package.json +5 -5
  45. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +0 -8
@@ -0,0 +1,239 @@
1
+ import { flow } from 'effect/Function';
2
+ import * as Option from 'effect/Option';
3
+ import * as Schema from 'effect/Schema';
4
+
5
+ import type { Clients } from '../clients/clients.ts';
6
+ import type { RepoPlace } from '../code/places.ts';
7
+ import { failure } from '../hooks/answers.ts';
8
+ import { nextCursor } from '../hooks/repos.ts';
9
+ import {
10
+ issueOf,
11
+ issuesPerPage,
12
+ type Issue,
13
+ type Listed,
14
+ type Lister,
15
+ readOn,
16
+ } from '../issues/issues.ts';
17
+ import { pullOf, type Pull } from '../pulls/pulls.ts';
18
+
19
+ /** An issue or a pull request in a list across repos, with the repo it's in. */
20
+ export type AcrossRow =
21
+ | { readonly kind: 'issue'; readonly place: RepoPlace; readonly issue: Issue }
22
+ | { readonly kind: 'pull'; readonly place: RepoPlace; readonly issue: Pull };
23
+
24
+ /**
25
+ * A page of a list across repos, the cursor of the one after it, and whether the drop-in said
26
+ * the search behind it read only part of what it could have, as `incomplete_results` says.
27
+ */
28
+ export interface AcrossPage {
29
+ readonly rows: readonly AcrossRow[];
30
+ readonly next: string | undefined;
31
+ readonly incomplete: boolean;
32
+ }
33
+
34
+ /** The viewer's part in what Your issues and Your pull requests list, as GitHub's tabs name it. */
35
+ export type YourFilter = 'created' | 'assigned' | 'mentioned' | 'review-requested';
36
+
37
+ /** Your issues' filters, in the order the tabs show them, the first the page's own. */
38
+ export const issueFilters = [
39
+ 'created',
40
+ 'assigned',
41
+ 'mentioned',
42
+ ] as const satisfies readonly YourFilter[];
43
+
44
+ /** A filter `GET /issues` takes, as Your issues' tabs name them. */
45
+ export type IssueFilterName = (typeof issueFilters)[number];
46
+
47
+ /** Your pull requests' filters, in the order the tabs show them, the first the page's own. */
48
+ export const pullFilters = [
49
+ ...issueFilters,
50
+ 'review-requested',
51
+ ] as const satisfies readonly YourFilter[];
52
+
53
+ /**
54
+ * The pages a list reads at most before it shows what it has: an org's tab keeps one kind of what
55
+ * `/orgs/{org}/issues` lists, and a page the drop-in's bound ended comes back short or empty with
56
+ * a cursor. Past this many reads with nothing kept, the list offers more rather than reading on.
57
+ */
58
+ export const acrossReadsMost = 4;
59
+
60
+ /**
61
+ * The repo `listed` is in, from its `repository_url`, which ends `/repos/{owner}/{repo}`: read as
62
+ * text past the last `/repos/`, since a URL's parser drops a `.` or `..` segment.
63
+ */
64
+ export const placeOfListed = (listed: { readonly repository_url: string }): RepoPlace => {
65
+ const url = listed.repository_url;
66
+ const [owner = '', repo = ''] = url
67
+ .slice(url.lastIndexOf('/repos/') + '/repos/'.length)
68
+ .split('/')
69
+ .map(decodeURIComponent);
70
+
71
+ return { owner, repo };
72
+ };
73
+
74
+ /** An issue or a pull request as a list across repos reads it, with its repo's URL. */
75
+ type AcrossListed = Listed & { readonly repository_url: string };
76
+
77
+ /** `listed` as a list across repos shows it: an issue, or a pull request with its own state. */
78
+ const rowOf = (listed: AcrossListed): AcrossRow =>
79
+ listed.pull_request === undefined
80
+ ? { kind: 'issue', place: placeOfListed(listed), issue: issueOf(listed) }
81
+ : { kind: 'pull', place: placeOfListed(listed), issue: pullOf(listed) };
82
+
83
+ /** The rows of `listed` of `kind`: what a list that shows one kind keeps of a page of both. */
84
+ const keepOf =
85
+ (kind: AcrossRow['kind']) =>
86
+ async (listed: readonly AcrossListed[]): Promise<readonly AcrossRow[]> =>
87
+ listed.flatMap((each) => {
88
+ const row = rowOf(each);
89
+
90
+ return row.kind === kind ? [row] : [];
91
+ });
92
+
93
+ /**
94
+ * A page of the viewer's open issues across every repo they may read, by their part in each:
95
+ * `GET /issues`, which lists issues alone with `pulls=false`.
96
+ */
97
+ const yourIssuesLister =
98
+ (clients: Clients, filter: IssueFilterName): Lister<AcrossListed> =>
99
+ async (after) => {
100
+ // `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
101
+ const query = { filter, state: 'open' as const, per_page: issuesPerPage, pulls: false, after };
102
+ const answer = await clients.github.GET('/issues', { params: { query: { ...query } } });
103
+ if (answer.data === undefined) throw failure("Your issues didn't load", answer);
104
+
105
+ return { listed: answer.data, next: nextCursor(answer.response.headers.get('link')) };
106
+ };
107
+
108
+ /** A page of every open issue and pull request in `org`'s repos the viewer may read. */
109
+ const orgLister =
110
+ (clients: Clients, org: string, what: string): Lister<AcrossListed> =>
111
+ async (after) => {
112
+ // `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
113
+ const query = { filter: 'all', state: 'open', per_page: issuesPerPage, after } as const;
114
+ const answer = await clients.github.GET('/orgs/{org}/issues', {
115
+ params: { path: { org }, query: { ...query } },
116
+ });
117
+ if (answer.data === undefined) throw failure(`${what} didn't load`, answer);
118
+
119
+ return { listed: answer.data, next: nextCursor(answer.response.headers.get('link')) };
120
+ };
121
+
122
+ /** The search qualifier that finds what the viewer has `filter`'s part in. */
123
+ const qualifiers: Readonly<Record<YourFilter, string>> = {
124
+ created: 'author:@me',
125
+ assigned: 'assignee:@me',
126
+ mentioned: 'mentions:@me',
127
+ 'review-requested': 'review-requested:@me',
128
+ };
129
+
130
+ /** The search Your pull requests runs under `filter`: open pull requests, from the viewer's index. */
131
+ export const yourPullsQuery = (filter: YourFilter) => `is:pr is:open ${qualifiers[filter]}`;
132
+
133
+ /**
134
+ * A page of the viewer's open pull requests across every repo, by their part in each: the
135
+ * drop-in's search, which reads the viewer's involvement index when the query names no repo.
136
+ * `GET /issues` has no pull requests alone, and a search pages by number, with no cursor past
137
+ * the drop-in's bound, which `incomplete_results` reports.
138
+ */
139
+ const yourPullsPage = async (
140
+ clients: Clients,
141
+ filter: YourFilter,
142
+ after: string | undefined,
143
+ ): Promise<AcrossPage> => {
144
+ const page = after === undefined ? 1 : Number(after);
145
+ const answer = await clients.github.GET('/search/issues', {
146
+ params: { query: { q: yourPullsQuery(filter), per_page: issuesPerPage, page } },
147
+ });
148
+ if (answer.data === undefined) throw failure("Your pull requests didn't load", answer);
149
+
150
+ return {
151
+ rows: answer.data.items.map(rowOf),
152
+ next: nextCursor(answer.response.headers.get('link'), 'page'),
153
+ incomplete: answer.data.incomplete_results,
154
+ };
155
+ };
156
+
157
+ /**
158
+ * The rows `keep` makes of what `lister` gives, after `after`, read on past a page it keeps none
159
+ * of, or one a bound of the drop-in's ended empty, up to `acrossReadsMost` pages.
160
+ */
161
+ const keptPage = async (
162
+ lister: Lister<AcrossListed>,
163
+ keep: (listed: readonly AcrossListed[]) => Promise<readonly AcrossRow[]>,
164
+ after: string | undefined,
165
+ ): Promise<AcrossPage> => {
166
+ const { rows, next } = await readOn(lister, after, { keep, reads: acrossReadsMost });
167
+
168
+ return { rows, next, incomplete: false };
169
+ };
170
+
171
+ /** Every row of a page, for a list the drop-in already keeps to one kind. */
172
+ const keepAll = async (listed: readonly AcrossListed[]): Promise<readonly AcrossRow[]> =>
173
+ listed.map(rowOf);
174
+
175
+ const firstPage: string | undefined = undefined;
176
+
177
+ /** A list across repos as the reader pages it: `read` from each page's cursor. */
178
+ const pagedBy = (
179
+ queryKey: readonly unknown[],
180
+ read: (after: string | undefined) => Promise<AcrossPage>,
181
+ ) => ({
182
+ queryKey,
183
+ queryFn: ({ pageParam }: { readonly pageParam: string | undefined }) => read(pageParam),
184
+ initialPageParam: firstPage,
185
+ getNextPageParam: (last: AcrossPage) => last.next,
186
+ staleTime: 10_000,
187
+ });
188
+
189
+ /** The viewer's open issues under `filter`, a page at a time as they ask for more. */
190
+ export const yourIssues = (clients: Clients, filter: IssueFilterName) =>
191
+ pagedBy(['across', 'issues', filter], (after) =>
192
+ keptPage(yourIssuesLister(clients, filter), keepAll, after),
193
+ );
194
+
195
+ /** The viewer's open pull requests under `filter`, a page at a time as they ask for more. */
196
+ export const yourPulls = (clients: Clients, filter: YourFilter) =>
197
+ pagedBy(['across', 'pulls', filter], (after) => yourPullsPage(clients, filter, after));
198
+
199
+ /**
200
+ * `org`'s open issues, or its pull requests, a page at a time. Both read `/orgs/{org}/issues` with
201
+ * `filter=all`, which lists both kinds, each tab keeping its own: a search's `org:` names no
202
+ * person to read the index of, so it keeps the drop-in's cap of 5 repos a search.
203
+ */
204
+ export const orgList = (clients: Clients, org: string, kind: AcrossRow['kind']) => {
205
+ const what = kind === 'issue' ? `${org}'s issues` : `${org}'s pull requests`;
206
+
207
+ return pagedBy(['across', 'org', org.toLowerCase(), kind], (after) =>
208
+ keptPage(orgLister(clients, org, what), keepOf(kind), after),
209
+ );
210
+ };
211
+
212
+ /** The `filter=` part of Your issues' and Your pull requests' URLs, as the router hands it over. */
213
+ const Parts = Schema.Struct({ filter: Schema.optional(Schema.Unknown) });
214
+
215
+ const readText = flow(Schema.decodeUnknownOption(Schema.String), Option.getOrUndefined);
216
+
217
+ /** Your issues' and Your pull requests' URL query: the filter it names, if it names one. */
218
+ export interface YourSearch {
219
+ readonly filter?: string | undefined;
220
+ }
221
+
222
+ /** The URL's query for a page of `filters`: the filter it names, else none, the page's own. */
223
+ export const readYourSearch = flow(
224
+ Schema.decodeUnknownOption(Parts),
225
+ Option.match({
226
+ onNone: (): YourSearch => ({}),
227
+ onSome: ({ filter }): YourSearch => ({ filter: readText(filter) }),
228
+ }),
229
+ );
230
+
231
+ /** The filter `filters`' page shows for `named`: its first, the page's own, unless it names another. */
232
+ export const yourFilterOf = <Filter extends YourFilter>(
233
+ filters: readonly [Filter, ...Filter[]],
234
+ named: string | undefined,
235
+ ): Filter => filters.find((filter) => filter === named) ?? filters[0];
236
+
237
+ /** The URL of `path`'s page under `filter`: none for the page's own, its first filter. */
238
+ export const yourHref = (path: string, filters: readonly YourFilter[], filter: YourFilter) =>
239
+ filter === filters[0] ? path : `${path}?${new URLSearchParams({ filter })}`;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The logins no person or org may take. The app's own first path segments: a repo at
3
3
  * `/{owner}/{repo}` under one would be shadowed by the app's page, or shadow it. `login`, `logout`
4
- * and `signup` are sign-in's, `new`, `notifications`, `settings` and `orgs` the app's pages, `uploads` and
4
+ * and `signup` are sign-in's, `new`, `notifications`, `issues`, `pulls`, `settings` and `orgs` the app's pages, `uploads` and
5
5
  * `downloads` its release assets' routes, `icons` its avatars', `repos`, `tokens` and `me` Git's
6
6
  * REST, and the rest what the drop-in, Better Auth's `/api/auth` and the build serve. And `admin`,
7
7
  * so no one looks like the admin, whose actor is `_admin`, which no login can spell. Start's
@@ -14,12 +14,14 @@ export const reservedOwners: ReadonlySet<string> = new Set([
14
14
  'avatars',
15
15
  'downloads',
16
16
  'icons',
17
+ 'issues',
17
18
  'login',
18
19
  'logout',
19
20
  'me',
20
21
  'new',
21
22
  'notifications',
22
23
  'orgs',
24
+ 'pulls',
23
25
  'repos',
24
26
  'settings',
25
27
  'signup',
@@ -73,16 +73,17 @@ export const repoPath = (owner: string, repo: string) => `/${segment(owner)}/${s
73
73
  const everywhere: readonly Target[] = [
74
74
  { label: 'Home', href: '/' },
75
75
  { label: 'Settings', note: 'Your account', href: '/settings', section: 'settings' },
76
+ { label: 'Your issues', href: '/issues', section: 'issues' },
77
+ { label: 'Your pull requests', href: '/pulls', section: 'pulls' },
76
78
  { label: 'New repository', href: '/new' },
77
79
  ];
78
80
 
79
- /** An org's own pages, under `/orgs/$owner/`. */
81
+ /** An org's own pages, under `/orgs/$owner/`: its releases are each repo's. */
80
82
  const orgPages = (org: string): readonly Target[] =>
81
83
  (
82
84
  [
83
85
  ['Issues', 'issues', 'issues'],
84
86
  ['Pull requests', 'pulls', 'pulls'],
85
- ['Releases', 'releases', 'releases'],
86
87
  ['Settings', 'settings', 'settings'],
87
88
  ['Tokens', 'tokens', 'tokens'],
88
89
  ] as const
@@ -271,11 +271,6 @@ const tokenEndedRefusal = {
271
271
  message: "This token's person no longer holds the org or the shared repo it's over",
272
272
  };
273
273
 
274
- /** At most `most` of an owner's private repos the caller may read, as the owner index asks. */
275
- export type ReadableRepos = (
276
- input: GitHubReadableReposInput,
277
- ) => Effect.Effect<Awaited<ReturnType<GitHubReadableRepos>>, GitError>;
278
-
279
274
  /**
280
275
  * The host's policy and directory, the drop-in's and Git's, over its people and orgs: Git's
281
276
  * `Policy`'s decision, the drop-in's `authorize` and `People`, and the owner index's hook.
@@ -284,7 +279,7 @@ export interface HostPolicy {
284
279
  readonly authorize: Policy.PolicyService['authorize'];
285
280
  readonly authorizeGitHub: GitHubAuthorize;
286
281
  readonly people: PeopleFor;
287
- readonly readableRepos: ReadableRepos;
282
+ readonly readableRepos: GitHubReadableRepos;
288
283
  }
289
284
 
290
285
  /** The host's policy over its repos' grants, with the drop-in's `RepoGrants` over the same rows. */
@@ -294,13 +289,13 @@ export interface GrantsPolicy extends HostPolicy {
294
289
 
295
290
  /**
296
291
  * At most `most` of the private repos under `prefix`, and whether it holds more past them, listed
297
- * through `host`, the drop-in's unchecked `repos.list` (Q788).
292
+ * through Git's unchecked `repos.list`, as `Git.host` calls it (Q788). It runs in the search's
293
+ * fiber, so its store calls count on the search's request, and interrupting the search stops it.
298
294
  */
299
295
  export type PrivateRepos = (
300
296
  prefix: string,
301
297
  most: number,
302
- host: GitHubReadableReposInput['host'],
303
- ) => Promise<{ readonly names: readonly RepoName[]; readonly more: boolean }>;
298
+ ) => Effect.Effect<{ readonly names: readonly RepoName[]; readonly more: boolean }, GitError>;
304
299
 
305
300
  /**
306
301
  * Where the drop-in's people find an uploaded picture (Q757): the app's origin, whose
@@ -311,14 +306,19 @@ export interface Pictures {
311
306
  readonly avatars: Pick<Avatars, 'hash'>;
312
307
  }
313
308
 
314
- /** The internal ID of the repo named `name` now, `undefined` when none is. */
315
- export type RepoIdOf = (name: RepoName, signal: AbortSignal) => Promise<InternalRepoId | undefined>;
309
+ /**
310
+ * The internal ID of the repo named `name` now, `undefined` when none is, read in the caller's
311
+ * fiber, so its store calls count on the caller's request.
312
+ */
313
+ export type RepoIdOf = (name: RepoName) => Effect.Effect<InternalRepoId | undefined, GitError>;
316
314
 
317
- /** The name `internalId`'s repo has now, `undefined` once none holds it. */
315
+ /**
316
+ * The name `internalId`'s repo has now, `undefined` once none holds it, read in the caller's
317
+ * fiber, so its store calls count on the caller's request.
318
+ */
318
319
  export type RepoNameOf = (
319
320
  internalId: InternalRepoId,
320
- signal: AbortSignal,
321
- ) => Promise<RepoName | undefined>;
321
+ ) => Effect.Effect<RepoName | undefined, GitError>;
322
322
 
323
323
  /**
324
324
  * What the starter's policy reads past its orgs: its `Pictures`, both or neither,
@@ -375,7 +375,7 @@ export function hostPolicy(orgs: Orgs, options: HostPolicyOptions = {}): HostPol
375
375
  const {
376
376
  origin,
377
377
  avatars,
378
- privateRepos = async () => ({ names: [], more: false }),
378
+ privateRepos = () => Effect.succeed({ names: [], more: false }),
379
379
  repoName,
380
380
  grants,
381
381
  repoId,
@@ -476,9 +476,7 @@ export function hostPolicy(orgs: Orgs, options: HostPolicyOptions = {}): HostPol
476
476
  ): Effect.Effect<InternalRepoId | undefined, GitError> => {
477
477
  if (access?.name === name) return Effect.succeed(access.internalId);
478
478
 
479
- return repoId === undefined
480
- ? Effect.succeed(undefined)
481
- : read((signal) => repoId(name, signal));
479
+ return repoId === undefined ? Effect.succeed(undefined) : repoId(name);
482
480
  };
483
481
 
484
482
  /** Whether `actor` belongs to the org `org`, in any role. */
@@ -532,7 +530,7 @@ export function hostPolicy(orgs: Orgs, options: HostPolicyOptions = {}): HostPol
532
530
  const { repo } = input;
533
531
  if (repo === undefined) return undefined;
534
532
 
535
- const now = yield* read(() => repoName(repo.internalId, input.signal));
533
+ const now = yield* repoName(repo.internalId);
536
534
 
537
535
  return now === undefined ? undefined : ownerOf(now);
538
536
  });
@@ -758,11 +756,7 @@ export function hostPolicy(orgs: Orgs, options: HostPolicyOptions = {}): HostPol
758
756
 
759
757
  const named = Math.min(grantsPage, Math.floor((most + ownerCallsPast) / nameReads));
760
758
  const page = yield* read(() => grants.shared(person.id, { limit: named }));
761
- const names = yield* Effect.forEach(
762
- page.items,
763
- (internalId) => read((signal) => repoName(internalId, signal)),
764
- { concurrency: 8 },
765
- );
759
+ const names = yield* Effect.forEach(page.items, repoName, { concurrency: 8 });
766
760
  const covered = names.filter(
767
761
  (name): name is RepoName => name !== undefined && covers(cover, name),
768
762
  );
@@ -782,8 +776,8 @@ export function hostPolicy(orgs: Orgs, options: HostPolicyOptions = {}): HostPol
782
776
  * `authorize` holds as any name. Git lists them newest made first, since it keeps no time a repo
783
777
  * was updated.
784
778
  */
785
- const readableRepos: ReadableRepos = Effect.fnUntraced(function* (input) {
786
- const { actor, owner, most, token, host } = input;
779
+ const readableRepos: GitHubReadableRepos = Effect.fnUntraced(function* (input) {
780
+ const { actor, owner, most, token } = input;
787
781
  const none = { names: [], more: false };
788
782
  if (actor.anonymous === true || !(yield* tokenHolds(input))) return none;
789
783
 
@@ -798,7 +792,7 @@ export function hostPolicy(orgs: Orgs, options: HostPolicyOptions = {}): HostPol
798
792
 
799
793
  const { prefix } = cover;
800
794
 
801
- return yield* read(() => privateRepos(prefix, most, host));
795
+ return yield* privateRepos(prefix, most);
802
796
  });
803
797
 
804
798
  /**
@@ -1058,9 +1052,8 @@ const repoGrantsOver = (
1058
1052
  const named = yield* Effect.forEach(
1059
1053
  page.items,
1060
1054
  (internalId) =>
1061
- Effect.map(
1062
- read((signal) => repoName(internalId, signal)),
1063
- (name) => (name === undefined ? undefined : ({ name, internalId } satisfies GrantRepo)),
1055
+ Effect.map(repoName(internalId), (name) =>
1056
+ name === undefined ? undefined : ({ name, internalId } satisfies GrantRepo),
1064
1057
  ),
1065
1058
  { concurrency: 8 },
1066
1059
  );
@@ -1,11 +1,14 @@
1
- import type { Actor, RepoCalls, RepoName } from '@ref0/git';
1
+ import { Git, Repos } from '@ref0/git';
2
+ import type { Actor, Caller, RepoName } from '@ref0/git';
3
+ import * as Effect from 'effect/Effect';
2
4
 
5
+ import type { OnHost } from './context/host.ts';
3
6
  import { admin } from './policy.ts';
4
7
  import type { PrivateRepos } from './policy.ts';
5
8
 
6
9
  /**
7
10
  * At most `most` of the private repos under `prefix`, among the newest `most` there, newest made
8
- * first: those `host` lists, unchecked, less what Git's `list` lists a caller not signed in,
11
+ * first: those Git's `list` lists as `Git.host`, unchecked, less what it lists a caller not signed in,
9
12
  * which reads the public repos' own index. Both lists are one page of `most`, newest first by one
10
13
  * key, a repo's created row, so the two windows hold the same repos and differ by the private ones
11
14
  * alone. The search asks for as many as it checks of the owner, so a private repo is named as far
@@ -16,32 +19,29 @@ import type { PrivateRepos } from './policy.ts';
16
19
  * it; the host's list reads its created rows and their entries, two; the public index, one; and a
17
20
  * server's first sealed cursor reads its key, one, and adds it when none is stored yet, one more.
18
21
  * A server that holds the key reads nothing for it (`listPublic` and `listCreated` in Git's
19
- * `store/catalogue.ts`, `cursorSeal` in `store/cursor-seal.ts`).
22
+ * `store/catalogue.ts`, `cursorSeal` in `store/cursor-seal.ts`). Both lists read through `onHost`,
23
+ * in the search's fiber, so they count on its request and stop with it.
20
24
  */
21
25
  export const privateReposOf =
22
- (list: RepoCalls['list']): PrivateRepos =>
23
- async (prefix, most, host) => {
24
- if (most <= 0) return { names: [], more: true };
26
+ (onHost: OnHost): PrivateRepos =>
27
+ (prefix, most) => {
28
+ if (most <= 0) return Effect.succeed({ names: [], more: true });
25
29
 
26
- const listed = async (from: RepoCalls['list'], actor: Actor) => {
27
- const page = await from({
28
- actor,
29
- prefix,
30
- order: 'newest',
31
- page: { limit: most },
30
+ const input = { prefix, order: 'newest', page: { limit: most } } as const;
31
+ // A list that fails names nothing, and isn't whole.
32
+ const listOf = (actor: Actor, by?: Caller) =>
33
+ Effect.match(onHost(Repos.list({ ...input, actor }, by)), {
34
+ onFailure: () => ({ names: [], whole: false }),
35
+ onSuccess: (page) => ({ names: page.items, whole: page.next === undefined }),
32
36
  });
33
- if (page.kind !== 'success') return { names: [], whole: false };
37
+ // The host's own list reads no actor: the admin's stands in, as `repos.list` takes one.
38
+ const all = listOf(admin, Git.host);
39
+ const shown = listOf({ anonymous: true });
34
40
 
35
- return { names: page.value.items, whole: page.value.next === undefined };
36
- };
41
+ return Effect.map(Effect.all([all, shown], { concurrency: 2 }), ([listed, open]) => {
42
+ const opened = new Set<RepoName>(open.names);
43
+ const hidden = listed.names.filter((name) => !opened.has(name));
37
44
 
38
- // The host's own calls read no actor: the admin's stands in, as `repos.list` takes one.
39
- const [all, shown] = await Promise.all([
40
- listed(host.list, admin),
41
- listed(list, { anonymous: true }),
42
- ]);
43
- const open = new Set<RepoName>(shown.names);
44
- const hidden = all.names.filter((name) => !open.has(name));
45
-
46
- return { names: hidden, more: !all.whole || !shown.whole };
45
+ return { names: hidden, more: !listed.whole || !open.whole };
46
+ });
47
47
  };
@@ -34,7 +34,8 @@ export const statusOf = (pull: Pick<Pull, 'state' | 'draft' | 'merged'>): PullSt
34
34
  return pull.draft ? 'draft' : 'open';
35
35
  };
36
36
 
37
- const pullOf = (issue: Listed): Pull => ({
37
+ /** A pull request as a list reads it, from the issues list or a search. */
38
+ export const pullOf = (issue: Listed): Pull => ({
38
39
  ...issueOf(issue),
39
40
  draft: issue.draft ?? false,
40
41
  merged: issue.pull_request?.merged_at ?? null,
@@ -97,12 +97,21 @@ export const placeOf = (path: string, viewer: string | undefined): Place | undef
97
97
  return second === undefined ? { owner: first } : { owner: first, repo: second };
98
98
  };
99
99
 
100
+ /** The viewer's own lists across their repos, Your issues and Your pull requests, by their paths. */
101
+ const yourLists: ReadonlyMap<string, Section> = new Map([
102
+ ['issues', 'issues'],
103
+ ['pulls', 'pulls'],
104
+ ]);
105
+
100
106
  /** The section `path` is in, at its level: any page no other section holds is Code's. */
101
107
  export const sectionOf = (path: string): Section => {
102
- const [first, , third] = segmentsOf(path);
103
- const orgs: readonly string[] = ['issues', 'pulls', 'releases', 'tokens', 'settings'];
108
+ const [first, second, third] = segmentsOf(path);
109
+ const orgs: readonly string[] = ['issues', 'pulls', 'tokens', 'settings'];
104
110
  if (first === 'settings') return 'settings';
105
111
 
112
+ const yours = first === undefined || second !== undefined ? undefined : yourLists.get(first);
113
+ if (yours !== undefined) return yours;
114
+
106
115
  if (first === 'orgs') {
107
116
  return orgs.find((section): section is Section => section === third) ?? 'code';
108
117
  }
@@ -115,7 +124,9 @@ const segment = encodeURIComponent;
115
124
  /**
116
125
  * Where `section` is at `place`: a repo's own page, or its org's under `/orgs/$owner/`, so no
117
126
  * org page clashes with a repo of the same name. The viewer's repositories are their home, `/`,
118
- * and their own settings `/settings`, as GitHub's are.
127
+ * their own settings `/settings`, and their issues and pull requests across every repo they may
128
+ * read `/issues` and `/pulls`, as GitHub's are. Releases are a repo's alone: at an owner's level,
129
+ * they lead to its repositories.
119
130
  */
120
131
  export const sectionHref = (place: Place, section: Section, viewer: string | undefined) => {
121
132
  const owner = segment(place.owner);
@@ -126,9 +137,14 @@ export const sectionHref = (place: Place, section: Section, viewer: string | und
126
137
  return section === 'code' ? home : `${home}/${section}`;
127
138
  }
128
139
 
129
- if (section === 'settings' && place.owner === viewer) return '/settings';
140
+ if (
141
+ place.owner === viewer &&
142
+ (section === 'settings' || section === 'issues' || section === 'pulls')
143
+ )
144
+ return `/${section}`;
130
145
 
131
- if (section !== 'code') return `/orgs/${owner}/${section}`;
146
+ // An owner's level has no releases of its own: each is a repo's, so its repositories stand in.
147
+ if (section !== 'code' && section !== 'releases') return `/orgs/${owner}/${section}`;
132
148
 
133
149
  return place.owner === viewer ? '/' : `/${owner}`;
134
150
  };
@@ -146,7 +162,12 @@ export const headingOf = (
146
162
  ) => {
147
163
  if (place === undefined) return 'Git';
148
164
 
149
- if (segmentsOf(path).length === 0) return 'Repositories';
165
+ const segments = segmentsOf(path);
166
+ if (segments.length === 0) return 'Repositories';
167
+
168
+ if (segments.length === 1 && segments[0] === 'issues') return 'Your issues';
169
+
170
+ if (segments.length === 1 && segments[0] === 'pulls') return 'Your pull requests';
150
171
 
151
172
  const named = place.repo === undefined ? place.owner : `${place.owner}/${place.repo}`;
152
173
 
@@ -197,12 +218,14 @@ const useOpenCounts = (place: RepoPlace | undefined, repo: Repo | undefined) =>
197
218
  };
198
219
 
199
220
  /**
200
- * The sidebar's items, the same at every level, in the same order: Repositories, or Code inside a
201
- * repo, then Issues, Pull requests, Releases, Tokens and Settings, each pointing at the org or at
202
- * the repo, the current one marked. Tokens and Settings are a signed-in person's, another
203
- * person's level has no Settings, and a repo's Settings show only to those who may change them. Inside a repo, Issues and Pull requests show
204
- * their open counts at their end, where their keys show while ⌘ is held. A count that hasn't come,
205
- * or failed, leaves the end empty; the org level has no counts to show.
221
+ * The sidebar's items, in the same order at every level: Repositories, or Code inside a repo,
222
+ * then Issues, Pull requests, Releases, Tokens and Settings, each pointing at the org or at the
223
+ * repo, the current one marked. Releases are a repo's alone. Another person's level has no Issues,
224
+ * Pull requests or Settings, and the viewer's own Issues and Pull requests are theirs across every
225
+ * repo. Tokens and Settings are a signed-in person's, and a repo's Settings show only to those who
226
+ * may change them. Inside a repo, Issues and Pull requests show their open counts at their end,
227
+ * where their keys show while ⌘ is held. A count that hasn't come, or failed, leaves the end empty;
228
+ * the org level has no counts to show.
206
229
  */
207
230
  export function Nav({
208
231
  place,
@@ -234,6 +257,11 @@ export function Nav({
234
257
  const shown = sections.filter(({ section }) => {
235
258
  if (section === 'tokens') return viewer !== undefined;
236
259
 
260
+ // An org's releases are each repo's, and a person's lists across repos are theirs alone.
261
+ if (section === 'releases') return inRepo !== undefined;
262
+
263
+ if (section === 'issues' || section === 'pulls') return inRepo !== undefined || !person;
264
+
237
265
  if (section === 'settings')
238
266
  return inRepo === undefined ? viewer !== undefined && !person : settingsOpen(allowed);
239
267
 
@@ -0,0 +1,15 @@
1
+ import { createFileRoute } from '@tanstack/react-router';
2
+
3
+ import { issueFilters, readYourSearch, yourFilterOf } from '../lists/across.ts';
4
+ import { YourIssues } from '../lists/across-list.tsx';
5
+
6
+ /** Your issues, under the filter its URL names, the viewer's across every repo they may read. */
7
+ export const Route = createFileRoute('/issues')({
8
+ validateSearch: readYourSearch,
9
+ component: function Issues() {
10
+ const { viewer } = Route.useRouteContext();
11
+ const filter = yourFilterOf(issueFilters, Route.useSearch().filter);
12
+
13
+ return <YourIssues signedIn={viewer !== null} filter={filter} />;
14
+ },
15
+ });
@@ -0,0 +1,31 @@
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import { notFound, redirect } from '@tanstack/react-router';
3
+
4
+ import { cached } from '../../../clients/cached.ts';
5
+ import type { Clients } from '../../../clients/clients.ts';
6
+ import { ownerAt } from '../../../hooks/repos.ts';
7
+
8
+ /**
9
+ * The org an org's list across its repos is of, as the owner's level read it: the viewer's own
10
+ * level goes to `yours`, Your issues or Your pull requests, and a person's has no such list, as
11
+ * GitHub's `/orgs/{org}/issues` lists an org's alone.
12
+ */
13
+ export const orgListed = async (
14
+ login: string,
15
+ context: {
16
+ readonly queryClient: QueryClient;
17
+ readonly clients: Clients;
18
+ readonly viewer: { readonly login: string } | null;
19
+ },
20
+ yours: '/issues' | '/pulls',
21
+ ) => {
22
+ const owner = await cached(
23
+ context.queryClient,
24
+ ownerAt(context.clients, login, context.viewer?.login),
25
+ );
26
+ if (owner?.kind === 'viewer') throw redirect({ href: yours });
27
+
28
+ if (owner?.kind !== 'org') throw notFound();
29
+
30
+ return { org: owner.login };
31
+ };