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
@@ -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