ref0-git 0.12.0 → 0.20.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 (63) hide show
  1. package/app/apps/github/generated/git-rest.ts +320 -4
  2. package/app/apps/github/generated/routeTree.gen.ts +42 -21
  3. package/app/apps/github/migrations/postgres/0001_auth.sql +8 -1
  4. package/app/apps/github/migrations/sql/0005_repo_grants.sql +10 -0
  5. package/app/apps/github/src/clients/allowed.ts +9 -4
  6. package/app/apps/github/src/clients/host-calls.ts +59 -34
  7. package/app/apps/github/src/components/repos/your-repos.tsx +57 -11
  8. package/app/apps/github/src/components/states/states.tsx +1 -19
  9. package/app/apps/github/src/components/view-tabs.tsx +6 -2
  10. package/app/apps/github/src/context/context.ts +51 -5
  11. package/app/apps/github/src/context/host.ts +72 -36
  12. package/app/apps/github/src/context/repo-grants.ts +35 -0
  13. package/app/apps/github/src/hooks/repos.ts +14 -3
  14. package/app/apps/github/src/issues/issue-list.tsx +11 -3
  15. package/app/apps/github/src/issues/issues.ts +11 -8
  16. package/app/apps/github/src/lists/across-list.tsx +358 -0
  17. package/app/apps/github/src/lists/across.ts +239 -0
  18. package/app/apps/github/src/names/owners.ts +3 -1
  19. package/app/apps/github/src/palette/targets.ts +3 -2
  20. package/app/apps/github/src/policy.ts +493 -102
  21. package/app/apps/github/src/private-repos.ts +24 -24
  22. package/app/apps/github/src/pulls/pulls.ts +2 -1
  23. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +1 -1
  24. package/app/apps/github/src/routes/-nav.tsx +40 -12
  25. package/app/apps/github/src/routes/index.tsx +2 -1
  26. package/app/apps/github/src/routes/issues.tsx +15 -0
  27. package/app/apps/github/src/routes/orgs/$owner/-org-list.ts +31 -0
  28. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +10 -3
  29. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +10 -3
  30. package/app/apps/github/src/routes/pulls.tsx +15 -0
  31. package/app/apps/github/src/seed/seed.ts +104 -52
  32. package/app/apps/github/src/server.ts +17 -7
  33. package/app/apps/github/src/settings/access-page.tsx +308 -0
  34. package/app/apps/github/src/settings/access.ts +156 -0
  35. package/app/apps/github/src/settings/settings-layout.tsx +0 -16
  36. package/app/apps/github/src/signin/approval.ts +24 -16
  37. package/app/apps/github/src/signin/auth.ts +29 -19
  38. package/app/apps/github/src/signin/orgs.ts +57 -14
  39. package/app/apps/github/src/signin/repo-grants.ts +141 -0
  40. package/app/apps/github/src/signin/revoke.ts +9 -17
  41. package/app/apps/github/src/signin/unborn.ts +33 -20
  42. package/app/pnpm-workspace.yaml +2 -2
  43. package/dist/cli/child.mjs +73 -3
  44. package/dist/cli/commands.mjs +2 -0
  45. package/dist/cli/documents.mjs +42 -2
  46. package/dist/cli/keys.mjs +431 -0
  47. package/dist/cli/main.mjs +148 -0
  48. package/dist/cli/prompt.mjs +40 -1
  49. package/dist/cli/ref0-git.mjs +4 -141
  50. package/dist/cli/setup.mjs +118 -16
  51. package/dist/cli/sign-in.mjs +1 -1
  52. package/dist/cli/tools-node.mjs +20 -0
  53. package/dist/cli/tools.mjs +12 -0
  54. package/dist/init/app.mjs +5 -2
  55. package/dist/init/cloudflare.mjs +8 -3
  56. package/dist/init/git-module.mjs +13 -8
  57. package/dist/init/metadata.mjs +1 -1
  58. package/dist/init/node.mjs +1 -1
  59. package/dist/init/template.mjs +1 -0
  60. package/dist/init/templates.mjs +24 -19
  61. package/dist/init/versions.mjs +1 -1
  62. package/package.json +5 -5
  63. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +0 -8
@@ -20,7 +20,8 @@ import { ownerProblem } from '../names/owners.ts';
20
20
  * cursor their `Link` names (Q391). The drop-in serves no `/search/repositories`, so search and
21
21
  * language are the browser's, over every page, up to `maxFiltered` rows. The viewer's own list
22
22
  * filters visibility with `visibility`, beside `affiliation=owner` (GitHub refuses either beside
23
- * `type`), and an org's every type with `type`. A person's list reads neither, so the browser
23
+ * `type`), as the repos shared with the viewer do beside `affiliation=collaborator` (#1998), and
24
+ * an org's every type with `type`. A person's list reads neither, so the browser
24
25
  * filters it, as it does sources and forks on the viewer's.
25
26
  */
26
27
 
@@ -39,9 +40,13 @@ export interface RepoRow {
39
40
  readonly license: string | null;
40
41
  }
41
42
 
42
- /** Whose repositories a page lists, as the route found its owner. */
43
+ /**
44
+ * Whose repositories a page lists, as the route found its owner, or the repos others shared with
45
+ * the viewer `login`, which `/` lists apart from their own.
46
+ */
43
47
  export type Owner =
44
48
  | { readonly kind: 'viewer'; readonly login: string }
49
+ | { readonly kind: 'shared'; readonly login: string }
45
50
  | { readonly kind: 'org'; readonly login: string }
46
51
  | { readonly kind: 'user'; readonly login: string };
47
52
 
@@ -254,6 +259,7 @@ const serverType = (owner: Owner, type: RepoType): RepoType => {
254
259
  case 'org':
255
260
  return type;
256
261
  case 'viewer':
262
+ case 'shared':
257
263
  return visibilityOf(type);
258
264
  case 'user':
259
265
  return 'all';
@@ -322,9 +328,14 @@ const answerOf = async (
322
328
  params: { path: { username: owner.login }, query: { ...paging } },
323
329
  });
324
330
  case 'viewer':
331
+ case 'shared':
325
332
  return clients.github.GET('/user/repos', {
326
333
  params: {
327
- query: { ...paging, affiliation: 'owner', visibility: visibilityOf(query.type) },
334
+ query: {
335
+ ...paging,
336
+ affiliation: owner.kind === 'viewer' ? 'owner' : 'collaborator',
337
+ visibility: visibilityOf(query.type),
338
+ },
328
339
  },
329
340
  });
330
341
  }
@@ -16,7 +16,7 @@ import { cn } from '#/lib/cn';
16
16
 
17
17
  import { day, Go, usePreloaded } from '../code/controls.tsx';
18
18
  import { useClients } from '../clients/clients.ts';
19
- import type { RepoPlace } from '../code/places.ts';
19
+ import { repoHref, type RepoPlace } from '../code/places.ts';
20
20
  import { ItemList, More } from '../components/item-list.tsx';
21
21
  import { OwnerCard } from '../components/owner-card.tsx';
22
22
  import { UserAvatar } from '../components/user-avatar.tsx';
@@ -71,18 +71,21 @@ export const issueHref = (place: RepoPlace, number: number) =>
71
71
 
72
72
  /**
73
73
  * An issue's or a pull request's row: `icon` for its state, its title, labels, and who opened it
74
- * when, and `note` after that, such as "Draft".
74
+ * when, and `note` after that, such as "Draft". In a list across repos, `repo` names its repo
75
+ * before its title, as GitHub's own lists do.
75
76
  */
76
77
  export function IssueRow({
77
78
  href,
78
79
  icon,
79
80
  issue,
80
81
  note,
82
+ repo,
81
83
  }: {
82
84
  readonly href: string;
83
85
  readonly icon: ReactNode;
84
86
  readonly issue: Issue;
85
87
  readonly note?: string;
88
+ readonly repo?: RepoPlace;
86
89
  }) {
87
90
  const comments = `${issue.comments} ${issue.comments === 1 ? 'comment' : 'comments'}`;
88
91
 
@@ -91,6 +94,11 @@ export function IssueRow({
91
94
  <ItemMedia>{icon}</ItemMedia>
92
95
  <ItemContent className="min-w-0">
93
96
  <ItemTitle className="line-clamp-none flex max-w-full flex-wrap gap-1.5 text-sm/6 font-semibold sm:text-base/6 wrap-anywhere">
97
+ {repo !== undefined && (
98
+ <Go href={repoHref(repo)} className="font-normal text-muted-foreground hover:underline">
99
+ {repo.owner}/{repo.repo}
100
+ </Go>
101
+ )}
94
102
  <Go href={href} className="hover:underline">
95
103
  {issue.title}
96
104
  </Go>
@@ -136,7 +144,7 @@ export function IssueRow({
136
144
  }
137
145
 
138
146
  /** An issue's state, as its row's icon: open in green, closed in purple. */
139
- function IssueIcon({ issue }: { readonly issue: Issue }) {
147
+ export function IssueIcon({ issue }: { readonly issue: Issue }) {
140
148
  const open = issue.state === 'open';
141
149
  const Icon = open ? CircleDotIcon : CircleCheckIcon;
142
150
 
@@ -235,10 +235,13 @@ export type Listed = IssueFields & {
235
235
  readonly pull_request?: { readonly merged_at?: string | null };
236
236
  };
237
237
 
238
- /** A page a list reads, from `after`: what it lists, and where the next page starts. */
239
- export type Lister = (
238
+ /**
239
+ * A page a list reads, from `after`: what it lists, and where the next page starts. A list across
240
+ * repos reads items that carry their repo's URL too.
241
+ */
242
+ export type Lister<Item extends Listed = Listed> = (
240
243
  after: string | undefined,
241
- ) => Promise<{ readonly listed: readonly Listed[]; readonly next: string | undefined }>;
244
+ ) => Promise<{ readonly listed: readonly Item[]; readonly next: string | undefined }>;
242
245
 
243
246
  /** The repo's issue list under `query`, a page from `after`, the drop-in's cursor. */
244
247
  export const listedBy =
@@ -274,8 +277,8 @@ export const searchedBy =
274
277
  };
275
278
 
276
279
  /** How a list reads on: what it keeps of each page, and up to how many pages. */
277
- export interface Reading<Row> {
278
- readonly keep: (listed: readonly Listed[]) => Promise<readonly Row[]>;
280
+ export interface Reading<Row, Item extends Listed = Listed> {
281
+ readonly keep: (listed: readonly Item[]) => Promise<readonly Row[]>;
279
282
  readonly reads: number;
280
283
  }
281
284
 
@@ -284,10 +287,10 @@ export interface Reading<Row> {
284
287
  * page `keep` makes no rows of reads on to the next, so no page shows nothing while more is
285
288
  * left, up to `reads` pages.
286
289
  */
287
- export const readOn = async <Row>(
288
- lister: Lister,
290
+ export const readOn = async <Row, Item extends Listed = Listed>(
291
+ lister: Lister<Item>,
289
292
  after: string | undefined,
290
- { keep, reads }: Reading<Row>,
293
+ { keep, reads }: Reading<Row, Item>,
291
294
  ): Promise<{ readonly rows: readonly Row[]; readonly next: string | undefined }> => {
292
295
  let cursor = after;
293
296
 
@@ -0,0 +1,358 @@
1
+ import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { CircleDotIcon, GitPullRequestIcon, InfoIcon, type LucideIcon } from 'lucide-react';
3
+ import type { ReactNode } from 'react';
4
+
5
+ import { cn } from '#/lib/cn';
6
+
7
+ import { useClients } from '../clients/clients.ts';
8
+ import { Go } from '../code/controls.tsx';
9
+ import { Count } from '../components/count.tsx';
10
+ import { ItemList, More } from '../components/item-list.tsx';
11
+ import { pullStatuses } from '../components/pull-status.tsx';
12
+ import {
13
+ Empty,
14
+ EmptyDescription,
15
+ EmptyHeader,
16
+ EmptyMedia,
17
+ EmptyTitle,
18
+ } from '../components/ui/empty.tsx';
19
+ import { Skeleton } from '../components/ui/skeleton.tsx';
20
+ import { Tabs } from '../components/ui/tabs.tsx';
21
+ import { ViewTabs } from '../components/view-tabs.tsx';
22
+ import { IssueIcon, IssueRow, issueHref, LoadAlert, NoneMatched } from '../issues/issue-list.tsx';
23
+ import { pullHref } from '../pulls/pull-list.tsx';
24
+ import { statusOf } from '../pulls/pulls.ts';
25
+ import { SignedOut } from '../components/states/states.tsx';
26
+ import {
27
+ type AcrossPage,
28
+ type AcrossRow,
29
+ type IssueFilterName,
30
+ issueFilters,
31
+ orgList,
32
+ pullFilters,
33
+ yourHref,
34
+ type YourFilter,
35
+ yourIssues,
36
+ yourPulls,
37
+ } from './across.ts';
38
+
39
+ /** A list across repos as `useInfiniteQuery` takes it, such as `yourIssues`' or `orgList`'s. */
40
+ type AcrossQuery = ReturnType<typeof orgList>;
41
+
42
+ /** A row of a list across repos: its repo's name, then the issue's or pull request's own row. */
43
+ function AcrossItem({ row }: { readonly row: AcrossRow }) {
44
+ if (row.kind === 'issue') {
45
+ return (
46
+ <IssueRow
47
+ href={issueHref(row.place, row.issue.number)}
48
+ icon={<IssueIcon issue={row.issue} />}
49
+ issue={row.issue}
50
+ repo={row.place}
51
+ />
52
+ );
53
+ }
54
+
55
+ const status = statusOf(row.issue);
56
+ const { Icon, name, tone } = pullStatuses[status];
57
+
58
+ return (
59
+ <IssueRow
60
+ href={pullHref(row.place, row.issue.number)}
61
+ icon={<Icon aria-label={name} className={cn('size-5', tone)} />}
62
+ issue={row.issue}
63
+ repo={row.place}
64
+ {...(status === 'draft' ? { note: name } : {})}
65
+ />
66
+ );
67
+ }
68
+
69
+ /**
70
+ * The line over a list whose search read only part of what it could: the drop-in's search of a
71
+ * person's involvement reads at most its 20 repos a page, the most recently active first.
72
+ */
73
+ export function SomeMissing() {
74
+ return (
75
+ <p className="flex items-center gap-2 border-b px-3 py-2 text-sm text-muted-foreground sm:px-4">
76
+ <InfoIcon aria-hidden className="size-4 shrink-0" />
77
+ Some results may be missing: this search reads your 20 most recently active repositories
78
+ </p>
79
+ );
80
+ }
81
+
82
+ /** What a list across repos says with nothing in it. */
83
+ export interface Nothing {
84
+ readonly kind: AcrossRow['kind'];
85
+ readonly title: string;
86
+ readonly description: string;
87
+ }
88
+
89
+ /** Each kind's icon, for a list with nothing in it. */
90
+ const emptyIcons: Readonly<Record<AcrossRow['kind'], LucideIcon>> = {
91
+ issue: CircleDotIcon,
92
+ pull: GitPullRequestIcon,
93
+ };
94
+
95
+ function NothingHere({ nothing }: { readonly nothing: Nothing }) {
96
+ const Icon = emptyIcons[nothing.kind];
97
+
98
+ return (
99
+ <Empty>
100
+ <EmptyHeader>
101
+ <EmptyMedia variant="icon">
102
+ <Icon />
103
+ </EmptyMedia>
104
+ <EmptyTitle>{nothing.title}</EmptyTitle>
105
+ <EmptyDescription>{nothing.description}</EmptyDescription>
106
+ </EmptyHeader>
107
+ </Empty>
108
+ );
109
+ }
110
+
111
+ /**
112
+ * A list across repos, a page at a time as the reader asks for more, each row naming its repo.
113
+ * A page that kept nothing while more is left says so and offers more, never that there's none.
114
+ */
115
+ export function AcrossList({
116
+ list,
117
+ label,
118
+ more,
119
+ nothing,
120
+ }: {
121
+ readonly list: AcrossQuery;
122
+ readonly label: string;
123
+ readonly more: string;
124
+ readonly nothing: Nothing;
125
+ }) {
126
+ const pages = useInfiniteQuery(list);
127
+ const loaded: readonly AcrossPage[] = pages.data?.pages ?? [];
128
+ const rows = loaded.flatMap((page) => page.rows);
129
+ if (pages.isPending) return <Skeleton className="h-40" />;
130
+
131
+ if (pages.error !== null && rows.length === 0) return <LoadAlert message={pages.error.message} />;
132
+
133
+ return (
134
+ <>
135
+ {loaded.some((page) => page.incomplete) && <SomeMissing />}
136
+ {rows.length === 0 ? (
137
+ pages.hasNextPage ? (
138
+ <NoneMatched more />
139
+ ) : (
140
+ <NothingHere nothing={nothing} />
141
+ )
142
+ ) : (
143
+ <ItemList
144
+ aria-label={label}
145
+ rows={rows}
146
+ keyOf={(row) => `${row.place.owner}/${row.place.repo}#${row.issue.number}`}
147
+ row={(row) => <AcrossItem row={row} />}
148
+ />
149
+ )}
150
+ <More pages={pages} label={more} />
151
+ </>
152
+ );
153
+ }
154
+
155
+ /** Each filter's tab name, as GitHub's own lists across repos name them. */
156
+ const filterNames: Readonly<Record<YourFilter, string>> = {
157
+ created: 'Created',
158
+ assigned: 'Assigned',
159
+ mentioned: 'Mentioned',
160
+ 'review-requested': 'Review requests',
161
+ };
162
+
163
+ /**
164
+ * Your issues' or Your pull requests' page: the filter tabs, each a link to its own page at
165
+ * `path`, the one shown raised with the count of the rows `list` has read, `+` while more is
166
+ * left, over `children`, the list.
167
+ */
168
+ export function YourList({
169
+ path,
170
+ filters,
171
+ filter,
172
+ list,
173
+ label,
174
+ children,
175
+ }: {
176
+ readonly path: string;
177
+ readonly filters: readonly YourFilter[];
178
+ readonly filter: YourFilter;
179
+ readonly list: AcrossQuery;
180
+ readonly label: string;
181
+ readonly children: ReactNode;
182
+ }) {
183
+ const pages = useInfiniteQuery(list);
184
+ const read = pages.data?.pages.reduce((rows, page) => rows + page.rows.length, 0);
185
+ const count = read === undefined ? undefined : <Count value={read} more={pages.hasNextPage} />;
186
+
187
+ return (
188
+ <section aria-label={label} className="border">
189
+ <div className="flex flex-wrap items-center gap-2 border-b bg-muted/50 px-3 py-1.5">
190
+ <Tabs value={filter}>
191
+ <ViewTabs
192
+ label="Filter"
193
+ views={filters.map((each) => ({
194
+ value: each,
195
+ label: filterNames[each],
196
+ link: <Go href={yourHref(path, filters, each)} />,
197
+ end: each === filter ? count : undefined,
198
+ }))}
199
+ />
200
+ </Tabs>
201
+ </div>
202
+ {children}
203
+ </section>
204
+ );
205
+ }
206
+
207
+ /** What an org's tab calls its list, its button for more, and what it lists. */
208
+ interface OrgWords {
209
+ readonly label: string;
210
+ readonly more: string;
211
+ readonly what: string;
212
+ }
213
+
214
+ /** Each kind's words on an org's tab. */
215
+ const orgWords: Readonly<Record<AcrossRow['kind'], OrgWords>> = {
216
+ issue: { label: 'Issues', more: 'More issues', what: 'issues' },
217
+ pull: { label: 'Pull requests', more: 'More pull requests', what: 'pull requests' },
218
+ };
219
+
220
+ /** Each kind's path on an org's level, under `/orgs/{org}/`. */
221
+ const orgPaths: Readonly<Record<AcrossRow['kind'], string>> = { issue: 'issues', pull: 'pulls' };
222
+
223
+ /**
224
+ * An org's Issues or Pull requests tab: its open ones in every repo of its the viewer may read,
225
+ * or, for a visitor, a sign-in, since `/orgs/{org}/issues` answers only someone signed in.
226
+ */
227
+ export function OrgTab({
228
+ signedIn,
229
+ org,
230
+ kind,
231
+ }: {
232
+ readonly signedIn: boolean;
233
+ readonly org: string;
234
+ readonly kind: AcrossRow['kind'];
235
+ }) {
236
+ const clients = useClients();
237
+ const { label, more, what } = orgWords[kind];
238
+
239
+ if (!signedIn) {
240
+ return (
241
+ <SignedOut
242
+ returnTo={`/orgs/${encodeURIComponent(org)}/${orgPaths[kind]}`}
243
+ what={`${org}'s ${what}`}
244
+ />
245
+ );
246
+ }
247
+
248
+ return (
249
+ <section aria-label={label} className="border">
250
+ <AcrossList
251
+ list={orgList(clients, org, kind)}
252
+ label={label}
253
+ more={more}
254
+ nothing={{
255
+ kind,
256
+ title: `No open ${what} in ${org}`,
257
+ description: `Open ${what} in ${org}'s repositories you can read come here.`,
258
+ }}
259
+ />
260
+ </section>
261
+ );
262
+ }
263
+
264
+ /** Your issues' words for none, under each filter. */
265
+ const noIssues: Readonly<Record<IssueFilterName, string>> = {
266
+ created: 'No open issues created by you',
267
+ assigned: 'No open issues assigned to you',
268
+ mentioned: 'No open issues mentioning you',
269
+ };
270
+
271
+ /**
272
+ * Your issues: the signed-in viewer's open issues across every repo they may read, created by
273
+ * them, assigned to them or mentioning them; a visitor's is a sign-in.
274
+ */
275
+ export function YourIssues({
276
+ signedIn,
277
+ filter,
278
+ }: {
279
+ readonly signedIn: boolean;
280
+ readonly filter: IssueFilterName;
281
+ }) {
282
+ const clients = useClients();
283
+
284
+ if (!signedIn) {
285
+ return <SignedOut returnTo={yourHref('/issues', issueFilters, filter)} what="your issues" />;
286
+ }
287
+
288
+ const list = yourIssues(clients, filter);
289
+
290
+ return (
291
+ <YourList path="/issues" filters={issueFilters} filter={filter} list={list} label="Your issues">
292
+ <AcrossList
293
+ key={filter}
294
+ list={list}
295
+ label="Issues"
296
+ more="More issues"
297
+ nothing={{
298
+ kind: 'issue',
299
+ title: noIssues[filter],
300
+ description: 'Issues in every repository you can read come here.',
301
+ }}
302
+ />
303
+ </YourList>
304
+ );
305
+ }
306
+
307
+ /** Your pull requests' words for none, under each filter. */
308
+ const noPulls: Readonly<Record<YourFilter, string>> = {
309
+ created: 'No open pull requests created by you',
310
+ assigned: 'No open pull requests assigned to you',
311
+ mentioned: 'No open pull requests mentioning you',
312
+ 'review-requested': 'No open pull requests asking for your review',
313
+ };
314
+
315
+ /**
316
+ * Your pull requests: the signed-in viewer's open pull requests across every repo they may read,
317
+ * created by them, assigned to them, mentioning them or asking for their review; a visitor's is a
318
+ * sign-in.
319
+ */
320
+ export function YourPulls({
321
+ signedIn,
322
+ filter,
323
+ }: {
324
+ readonly signedIn: boolean;
325
+ readonly filter: YourFilter;
326
+ }) {
327
+ const clients = useClients();
328
+
329
+ if (!signedIn) {
330
+ return (
331
+ <SignedOut returnTo={yourHref('/pulls', pullFilters, filter)} what="your pull requests" />
332
+ );
333
+ }
334
+
335
+ const list = yourPulls(clients, filter);
336
+
337
+ return (
338
+ <YourList
339
+ path="/pulls"
340
+ filters={pullFilters}
341
+ filter={filter}
342
+ list={list}
343
+ label="Your pull requests"
344
+ >
345
+ <AcrossList
346
+ key={filter}
347
+ list={list}
348
+ label="Pull requests"
349
+ more="More pull requests"
350
+ nothing={{
351
+ kind: 'pull',
352
+ title: noPulls[filter],
353
+ description: 'Pull requests in every repository you can read come here.',
354
+ }}
355
+ />
356
+ </YourList>
357
+ );
358
+ }