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.
- package/app/apps/github/generated/git-rest.ts +320 -4
- package/app/apps/github/generated/routeTree.gen.ts +42 -21
- package/app/apps/github/migrations/postgres/0001_auth.sql +8 -1
- package/app/apps/github/migrations/sql/0005_repo_grants.sql +10 -0
- package/app/apps/github/src/clients/allowed.ts +9 -4
- package/app/apps/github/src/clients/host-calls.ts +59 -34
- package/app/apps/github/src/components/repos/your-repos.tsx +57 -11
- package/app/apps/github/src/components/states/states.tsx +1 -19
- package/app/apps/github/src/components/view-tabs.tsx +6 -2
- package/app/apps/github/src/context/context.ts +51 -5
- package/app/apps/github/src/context/host.ts +72 -36
- package/app/apps/github/src/context/repo-grants.ts +35 -0
- package/app/apps/github/src/hooks/repos.ts +14 -3
- package/app/apps/github/src/issues/issue-list.tsx +11 -3
- package/app/apps/github/src/issues/issues.ts +11 -8
- package/app/apps/github/src/lists/across-list.tsx +358 -0
- package/app/apps/github/src/lists/across.ts +239 -0
- package/app/apps/github/src/names/owners.ts +3 -1
- package/app/apps/github/src/palette/targets.ts +3 -2
- package/app/apps/github/src/policy.ts +493 -102
- package/app/apps/github/src/private-repos.ts +24 -24
- package/app/apps/github/src/pulls/pulls.ts +2 -1
- package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +1 -1
- package/app/apps/github/src/routes/-nav.tsx +40 -12
- package/app/apps/github/src/routes/index.tsx +2 -1
- package/app/apps/github/src/routes/issues.tsx +15 -0
- package/app/apps/github/src/routes/orgs/$owner/-org-list.ts +31 -0
- package/app/apps/github/src/routes/orgs/$owner/issues.tsx +10 -3
- package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +10 -3
- package/app/apps/github/src/routes/pulls.tsx +15 -0
- package/app/apps/github/src/seed/seed.ts +104 -52
- package/app/apps/github/src/server.ts +17 -7
- package/app/apps/github/src/settings/access-page.tsx +308 -0
- package/app/apps/github/src/settings/access.ts +156 -0
- package/app/apps/github/src/settings/settings-layout.tsx +0 -16
- package/app/apps/github/src/signin/approval.ts +24 -16
- package/app/apps/github/src/signin/auth.ts +29 -19
- package/app/apps/github/src/signin/orgs.ts +57 -14
- package/app/apps/github/src/signin/repo-grants.ts +141 -0
- package/app/apps/github/src/signin/revoke.ts +9 -17
- package/app/apps/github/src/signin/unborn.ts +33 -20
- package/app/pnpm-workspace.yaml +2 -2
- package/dist/cli/child.mjs +73 -3
- package/dist/cli/commands.mjs +2 -0
- package/dist/cli/documents.mjs +42 -2
- package/dist/cli/keys.mjs +431 -0
- package/dist/cli/main.mjs +148 -0
- package/dist/cli/prompt.mjs +40 -1
- package/dist/cli/ref0-git.mjs +4 -141
- package/dist/cli/setup.mjs +118 -16
- package/dist/cli/sign-in.mjs +1 -1
- package/dist/cli/tools-node.mjs +20 -0
- package/dist/cli/tools.mjs +12 -0
- package/dist/init/app.mjs +5 -2
- package/dist/init/cloudflare.mjs +8 -3
- package/dist/init/git-module.mjs +13 -8
- package/dist/init/metadata.mjs +1 -1
- package/dist/init/node.mjs +1 -1
- package/dist/init/template.mjs +1 -0
- package/dist/init/templates.mjs +24 -19
- package/dist/init/versions.mjs +1 -1
- package/package.json +5 -5
- package/app/apps/github/src/routes/orgs/$owner/releases.tsx +0 -8
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import
|
|
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 `
|
|
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
|
-
(
|
|
23
|
-
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createFileRoute } from '@tanstack/react-router';
|
|
2
2
|
|
|
3
|
-
import { AccessPage } from '../../../../settings/
|
|
3
|
+
import { AccessPage } from '../../../../settings/access-page.tsx';
|
|
4
4
|
|
|
5
5
|
export const Route = createFileRoute('/$owner/$repo/settings/access')({ component: Access });
|
|
6
6
|
|
|
@@ -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', '
|
|
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
|
-
*
|
|
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 (
|
|
140
|
+
if (
|
|
141
|
+
place.owner === viewer &&
|
|
142
|
+
(section === 'settings' || section === 'issues' || section === 'pulls')
|
|
143
|
+
)
|
|
144
|
+
return `/${section}`;
|
|
130
145
|
|
|
131
|
-
|
|
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
|
-
|
|
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
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
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
|
|
|
@@ -22,6 +22,7 @@ export const Route = createFileRoute('/')({
|
|
|
22
22
|
const owners = [
|
|
23
23
|
{ kind: 'viewer' as const, login },
|
|
24
24
|
...orgs.map((org) => ({ kind: 'org' as const, login: org })),
|
|
25
|
+
{ kind: 'shared' as const, login },
|
|
25
26
|
];
|
|
26
27
|
|
|
27
28
|
await Promise.all(
|
|
@@ -33,7 +34,7 @@ export const Route = createFileRoute('/')({
|
|
|
33
34
|
component: Home,
|
|
34
35
|
});
|
|
35
36
|
|
|
36
|
-
/** The viewer's repositories
|
|
37
|
+
/** The viewer's repositories, their orgs', and those shared with them. */
|
|
37
38
|
function Home() {
|
|
38
39
|
const { viewer } = Route.useRouteContext();
|
|
39
40
|
const navigate = Route.useNavigate();
|
|
@@ -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
|
+
};
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { createFileRoute } from '@tanstack/react-router';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { OrgTab } from '../../../lists/across-list.tsx';
|
|
4
|
+
import { orgListed } from './-org-list.ts';
|
|
4
5
|
|
|
5
|
-
/** An
|
|
6
|
+
/** An org's open issues across its repos the viewer may read. */
|
|
6
7
|
export const Route = createFileRoute('/orgs/$owner/issues')({
|
|
7
|
-
|
|
8
|
+
loader: ({ params, context }) => orgListed(params.owner, context, '/issues'),
|
|
9
|
+
component: function OrgIssues() {
|
|
10
|
+
const { org } = Route.useLoaderData();
|
|
11
|
+
const { viewer } = Route.useRouteContext();
|
|
12
|
+
|
|
13
|
+
return <OrgTab signedIn={viewer !== null} org={org} kind="issue" />;
|
|
14
|
+
},
|
|
8
15
|
});
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { createFileRoute } from '@tanstack/react-router';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { OrgTab } from '../../../lists/across-list.tsx';
|
|
4
|
+
import { orgListed } from './-org-list.ts';
|
|
4
5
|
|
|
5
|
-
/** An
|
|
6
|
+
/** An org's open pull requests across its repos the viewer may read. */
|
|
6
7
|
export const Route = createFileRoute('/orgs/$owner/pulls')({
|
|
7
|
-
|
|
8
|
+
loader: ({ params, context }) => orgListed(params.owner, context, '/pulls'),
|
|
9
|
+
component: function OrgPulls() {
|
|
10
|
+
const { org } = Route.useLoaderData();
|
|
11
|
+
const { viewer } = Route.useRouteContext();
|
|
12
|
+
|
|
13
|
+
return <OrgTab signedIn={viewer !== null} org={org} kind="pull" />;
|
|
14
|
+
},
|
|
8
15
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
2
|
+
|
|
3
|
+
import { pullFilters, readYourSearch, yourFilterOf } from '../lists/across.ts';
|
|
4
|
+
import { YourPulls } from '../lists/across-list.tsx';
|
|
5
|
+
|
|
6
|
+
/** Your pull requests, under the filter its URL names, the viewer's across every repo they may read. */
|
|
7
|
+
export const Route = createFileRoute('/pulls')({
|
|
8
|
+
validateSearch: readYourSearch,
|
|
9
|
+
component: function Pulls() {
|
|
10
|
+
const { viewer } = Route.useRouteContext();
|
|
11
|
+
const filter = yourFilterOf(pullFilters, Route.useSearch().filter);
|
|
12
|
+
|
|
13
|
+
return <YourPulls signedIn={viewer !== null} filter={filter} />;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -215,6 +215,11 @@ const decodeCreated = Schema.decodeUnknownSync(Schema.fromJsonString(CreatedItem
|
|
|
215
215
|
|
|
216
216
|
const decodeDescribed = Schema.decodeUnknownSync(Schema.fromJsonString(Described));
|
|
217
217
|
|
|
218
|
+
/** A repo's labels, by their names. */
|
|
219
|
+
const decodeNamed = Schema.decodeUnknownSync(
|
|
220
|
+
Schema.fromJsonString(Schema.Array(Schema.Struct({ name: Schema.String }))),
|
|
221
|
+
);
|
|
222
|
+
|
|
218
223
|
/** A repo's milestones, by their titles. */
|
|
219
224
|
const decodeTitled = Schema.decodeUnknownSync(
|
|
220
225
|
Schema.fromJsonString(
|
|
@@ -233,17 +238,21 @@ interface Cast {
|
|
|
233
238
|
readonly call: (person: Person) => Call;
|
|
234
239
|
}
|
|
235
240
|
|
|
241
|
+
/** Ensures repo `id` exists with `description`; returns `true` when this run just created it. */
|
|
236
242
|
const ensureRepo = async (cast: Cast, id: RepoName, path: string, description: string) => {
|
|
237
243
|
const found = await cast.adminCall('GET', path);
|
|
244
|
+
const created = found.status === 404;
|
|
238
245
|
|
|
239
|
-
if (
|
|
246
|
+
if (created) {
|
|
240
247
|
value(await answer(cast.admin.repos.create({ name: id, public: true })), `make ${id}`);
|
|
241
248
|
} else if (decodeDescribed(found.text).description === (description || null)) {
|
|
242
|
-
return;
|
|
249
|
+
return false;
|
|
243
250
|
}
|
|
244
251
|
|
|
245
252
|
// A repo's settings are its admin's to change, which a person's `write` token isn't.
|
|
246
253
|
await cast.adminCall('PATCH', path, { description });
|
|
254
|
+
|
|
255
|
+
return created;
|
|
247
256
|
};
|
|
248
257
|
|
|
249
258
|
/** Each commit in turn on `parent`, as `git commit` makes them; their IDs, oldest first. */
|
|
@@ -278,7 +287,13 @@ const commitAll = async (
|
|
|
278
287
|
* makes the same objects, then each branch and the tag that isn't there yet, at once. Checks the
|
|
279
288
|
* expected refs first so a resumed seed skips rebuilding commits and tags once every ref exists.
|
|
280
289
|
*/
|
|
281
|
-
const pushHistory = async (
|
|
290
|
+
const pushHistory = async (
|
|
291
|
+
git: RestClientCalls,
|
|
292
|
+
id: RepoName,
|
|
293
|
+
repo: SeedRepo,
|
|
294
|
+
since: number,
|
|
295
|
+
fresh: boolean,
|
|
296
|
+
) => {
|
|
282
297
|
const { release } = repo;
|
|
283
298
|
const targets: readonly {
|
|
284
299
|
readonly ref: RefName;
|
|
@@ -314,12 +329,19 @@ const pushHistory = async (git: RestClientCalls, id: RepoName, repo: SeedRepo, s
|
|
|
314
329
|
|
|
315
330
|
const missingRefs = new Set<RefName>();
|
|
316
331
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
332
|
+
if (fresh) {
|
|
333
|
+
for (const { ref } of targets) missingRefs.add(ref);
|
|
334
|
+
} else {
|
|
335
|
+
const checks = await Promise.all(
|
|
336
|
+
targets.map(async ({ ref }) => ({ ref, found: await answer(git.refs.get(id, { ref })) })),
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
for (const { ref, found } of checks) {
|
|
340
|
+
if (found.kind === 'success') continue;
|
|
320
341
|
|
|
321
|
-
|
|
322
|
-
|
|
342
|
+
if (!missing(found.error)) value(found, `read ${ref}`);
|
|
343
|
+
missingRefs.add(ref);
|
|
344
|
+
}
|
|
323
345
|
}
|
|
324
346
|
|
|
325
347
|
if (missingRefs.size === 0) return;
|
|
@@ -341,21 +363,39 @@ const pushHistory = async (git: RestClientCalls, id: RepoName, repo: SeedRepo, s
|
|
|
341
363
|
};
|
|
342
364
|
|
|
343
365
|
/** Each label that isn't there yet, made by Pip. */
|
|
344
|
-
const makeLabels = async (call: Call, path: string, repo: SeedRepo) => {
|
|
366
|
+
const makeLabels = async (call: Call, path: string, repo: SeedRepo, fresh: boolean) => {
|
|
367
|
+
if (fresh) {
|
|
368
|
+
for (const label of repo.labels) await call('POST', `${path}/labels`, { ...label });
|
|
369
|
+
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const existing = new Set(
|
|
374
|
+
decodeNamed((await call('GET', `${path}/labels?per_page=100`)).text).map((label) =>
|
|
375
|
+
label.name.toLowerCase(),
|
|
376
|
+
),
|
|
377
|
+
);
|
|
378
|
+
|
|
345
379
|
for (const label of repo.labels) {
|
|
380
|
+
if (existing.has(label.name.toLowerCase())) continue;
|
|
381
|
+
|
|
382
|
+
// Labels past page 1 (up to 1,000 per repo) aren't in the batch; confirm by name before POST.
|
|
346
383
|
const found = await call('GET', `${path}/labels/${encodeURIComponent(label.name)}`);
|
|
347
384
|
if (found.status === 404) await call('POST', `${path}/labels`, { ...label });
|
|
348
385
|
}
|
|
349
386
|
};
|
|
350
387
|
|
|
351
388
|
/** Each of the repo's milestones' numbers, by its title: made where it isn't there yet. */
|
|
352
|
-
const makeMilestones = async (call: Call, path: string, repo: SeedRepo) => {
|
|
353
|
-
const
|
|
354
|
-
(await call('GET', `${path}/milestones?state=all&per_page=100`)).text,
|
|
355
|
-
);
|
|
389
|
+
const makeMilestones = async (call: Call, path: string, repo: SeedRepo, fresh: boolean) => {
|
|
390
|
+
const titles = repo.milestones ?? [];
|
|
356
391
|
const numbers = new Map<string, number>();
|
|
392
|
+
if (titles.length === 0) return numbers;
|
|
357
393
|
|
|
358
|
-
|
|
394
|
+
const listed = fresh
|
|
395
|
+
? []
|
|
396
|
+
: decodeTitled((await call('GET', `${path}/milestones?state=all&per_page=100`)).text);
|
|
397
|
+
|
|
398
|
+
for (const title of titles) {
|
|
359
399
|
const number =
|
|
360
400
|
listed.find((milestone) => milestone.title === title)?.number ??
|
|
361
401
|
decodeNumbered((await call('POST', `${path}/milestones`, { title })).text).number;
|
|
@@ -414,9 +454,11 @@ const openPull = async (
|
|
|
414
454
|
);
|
|
415
455
|
|
|
416
456
|
const reviewer = cast.call(pull.review.by);
|
|
417
|
-
const reviews = await reviewer('GET', `${path}/pulls/${item.number}/reviews`);
|
|
418
457
|
|
|
419
|
-
if (
|
|
458
|
+
if (
|
|
459
|
+
found === undefined ||
|
|
460
|
+
!wrote((await reviewer('GET', `${path}/pulls/${item.number}/reviews`)).text, pull.review.by)
|
|
461
|
+
) {
|
|
420
462
|
const { event, body } = pull.review;
|
|
421
463
|
await reviewer('POST', `${path}/pulls/${item.number}/reviews`, { event, body });
|
|
422
464
|
}
|
|
@@ -435,31 +477,33 @@ const openIssue = async (
|
|
|
435
477
|
found: ExistingIssue | undefined,
|
|
436
478
|
) => {
|
|
437
479
|
const author = cast.call(issue.by);
|
|
480
|
+
const milestone = milestones.get(issue.milestone ?? '');
|
|
481
|
+
const base = { title: issue.title, body: issue.body, labels: issue.labels };
|
|
438
482
|
const item =
|
|
439
483
|
found ??
|
|
440
484
|
decodeCreated(
|
|
441
485
|
(
|
|
442
|
-
await author(
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
486
|
+
await author(
|
|
487
|
+
'POST',
|
|
488
|
+
`${path}/issues`,
|
|
489
|
+
milestone === undefined ? base : { ...base, milestone },
|
|
490
|
+
)
|
|
447
491
|
).text,
|
|
448
492
|
);
|
|
449
|
-
await placeOn(
|
|
450
|
-
author,
|
|
451
|
-
path,
|
|
452
|
-
item.number,
|
|
453
|
-
item.milestone?.number ?? null,
|
|
454
|
-
milestones.get(issue.milestone ?? ''),
|
|
455
|
-
);
|
|
456
493
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
494
|
+
await placeOn(author, path, item.number, item.milestone?.number ?? null, milestone);
|
|
495
|
+
|
|
496
|
+
if (issue.comments.length > 0) {
|
|
497
|
+
const existingComments =
|
|
498
|
+
found === undefined
|
|
499
|
+
? undefined
|
|
500
|
+
: (await author('GET', `${path}/issues/${item.number}/comments?per_page=100`)).text;
|
|
460
501
|
|
|
461
|
-
|
|
462
|
-
|
|
502
|
+
for (const comment of issue.comments) {
|
|
503
|
+
if (existingComments === undefined || !wrote(existingComments, comment.by, comment.body)) {
|
|
504
|
+
const commenter = cast.call(comment.by);
|
|
505
|
+
await commenter('POST', `${path}/issues/${item.number}/comments`, { body: comment.body });
|
|
506
|
+
}
|
|
463
507
|
}
|
|
464
508
|
}
|
|
465
509
|
|
|
@@ -471,12 +515,14 @@ const openIssue = async (
|
|
|
471
515
|
}
|
|
472
516
|
};
|
|
473
517
|
|
|
474
|
-
const publishRelease = async (call: Call, path: string, repo: SeedRepo) => {
|
|
518
|
+
const publishRelease = async (call: Call, path: string, repo: SeedRepo, fresh: boolean) => {
|
|
475
519
|
const { release } = repo;
|
|
476
520
|
if (release === undefined) return;
|
|
477
521
|
|
|
478
|
-
|
|
479
|
-
|
|
522
|
+
if (!fresh) {
|
|
523
|
+
const found = await call('GET', `${path}/releases/tags/${encodeURIComponent(release.tag)}`);
|
|
524
|
+
if (found.status !== 404) return;
|
|
525
|
+
}
|
|
480
526
|
|
|
481
527
|
await call('POST', `${path}/releases`, {
|
|
482
528
|
tag_name: release.tag,
|
|
@@ -490,19 +536,22 @@ const seedRepo = async (cast: Cast, repo: SeedRepo, since: number) => {
|
|
|
490
536
|
const path = `/repos/${id}`;
|
|
491
537
|
const asPip = cast.call(pip);
|
|
492
538
|
|
|
493
|
-
await ensureRepo(cast, id, path, repo.description);
|
|
494
|
-
await pushHistory(cast.git(pip), id, repo, since);
|
|
495
|
-
await makeLabels(asPip, path, repo);
|
|
496
|
-
const milestones = await makeMilestones(asPip, path, repo);
|
|
539
|
+
const fresh = await ensureRepo(cast, id, path, repo.description);
|
|
540
|
+
await pushHistory(cast.git(pip), id, repo, since, fresh);
|
|
541
|
+
await makeLabels(asPip, path, repo, fresh);
|
|
542
|
+
const milestones = await makeMilestones(asPip, path, repo, fresh);
|
|
497
543
|
|
|
498
544
|
if (repo.pulls.length > 0) {
|
|
499
|
-
const listedPulls = decodePulls(
|
|
500
|
-
(await asPip('GET', `${path}/pulls?state=all&per_page=100`)).text,
|
|
501
|
-
);
|
|
502
545
|
const pullsByHead = new Map<string, ExistingPull>();
|
|
503
546
|
|
|
504
|
-
|
|
505
|
-
|
|
547
|
+
if (!fresh) {
|
|
548
|
+
const listedPulls = decodePulls(
|
|
549
|
+
(await asPip('GET', `${path}/pulls?state=all&per_page=100`)).text,
|
|
550
|
+
);
|
|
551
|
+
|
|
552
|
+
for (const item of listedPulls) {
|
|
553
|
+
if (!pullsByHead.has(item.head.label)) pullsByHead.set(item.head.label, item);
|
|
554
|
+
}
|
|
506
555
|
}
|
|
507
556
|
|
|
508
557
|
for (const pull of repo.pulls) {
|
|
@@ -511,14 +560,17 @@ const seedRepo = async (cast: Cast, repo: SeedRepo, since: number) => {
|
|
|
511
560
|
}
|
|
512
561
|
|
|
513
562
|
if (repo.issues.length > 0) {
|
|
514
|
-
const listedIssues = decodeIssues(
|
|
515
|
-
(await asPip('GET', `${path}/issues?state=all&per_page=100`)).text,
|
|
516
|
-
);
|
|
517
563
|
const issuesByTitle = new Map<string, ExistingIssue>();
|
|
518
564
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
565
|
+
if (!fresh) {
|
|
566
|
+
const listedIssues = decodeIssues(
|
|
567
|
+
(await asPip('GET', `${path}/issues?state=all&per_page=100`)).text,
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
for (const item of listedIssues) {
|
|
571
|
+
if (item.pull_request === undefined && !issuesByTitle.has(item.title)) {
|
|
572
|
+
issuesByTitle.set(item.title, item);
|
|
573
|
+
}
|
|
522
574
|
}
|
|
523
575
|
}
|
|
524
576
|
|
|
@@ -527,7 +579,7 @@ const seedRepo = async (cast: Cast, repo: SeedRepo, since: number) => {
|
|
|
527
579
|
}
|
|
528
580
|
}
|
|
529
581
|
|
|
530
|
-
await publishRelease(asPip, path, repo);
|
|
582
|
+
await publishRelease(asPip, path, repo, fresh);
|
|
531
583
|
};
|
|
532
584
|
|
|
533
585
|
const members: ReadonlySet<string> = new Set(org.members.map((person) => person.login));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Git } from '@ref0/git';
|
|
1
|
+
import { Git, Repos } from '@ref0/git';
|
|
2
2
|
import { Records } from '@ref0/infra';
|
|
3
3
|
import handler, { createServerEntry } from '@tanstack/react-start/server-entry';
|
|
4
4
|
import * as Effect from 'effect/Effect';
|
|
5
5
|
|
|
6
6
|
import { workersFetch } from './camo/fetch.ts';
|
|
7
7
|
import { imageProxy } from './camo/proxy.ts';
|
|
8
|
-
import type { AppContext } from './context/context.ts';
|
|
9
|
-
import { auth, directory, env, pictures, policy,
|
|
10
|
-
import {
|
|
8
|
+
import type { AppContext, HostGit } from './context/context.ts';
|
|
9
|
+
import { auth, directory, env, host, pictures, policy, runtime, sessionKey } from './git.ts';
|
|
10
|
+
import { routeOn, tokensOn } from './context/host.ts';
|
|
11
11
|
import { ingressOf } from './ingress.ts';
|
|
12
12
|
import { hostRules } from './policy.ts';
|
|
13
13
|
import { shownRules } from './settings/rules.ts';
|
|
@@ -30,8 +30,11 @@ const gate = deviceAttemptGate({
|
|
|
30
30
|
/** The front door, then Git's routes, the drop-in's among them, for outside and the app alike. */
|
|
31
31
|
const { owned, api } = ingressOf({ gate, git: routeOn(runtime) });
|
|
32
32
|
|
|
33
|
-
/** Git's own calls, as host calls read them. */
|
|
34
|
-
const git = {
|
|
33
|
+
/** Git's own calls, as host calls read them, each an Effect, which the server function runs. */
|
|
34
|
+
const git = {
|
|
35
|
+
repos: { list: (input) => host(Repos.list(input)) },
|
|
36
|
+
tokens: tokensOn(host),
|
|
37
|
+
} satisfies HostGit;
|
|
35
38
|
|
|
36
39
|
/**
|
|
37
40
|
* The image proxy (Q860): a text's remote images load through `/_camo/`, and the pages' CSP loads
|
|
@@ -108,7 +111,14 @@ export default createServerEntry({
|
|
|
108
111
|
session: async (each) => sessionFrom(await auth(), sessionKey)(each),
|
|
109
112
|
endSession: async (each) => sessionEnder(await auth())(each),
|
|
110
113
|
sessionCookie: async () => sessionCookieOf(await auth())(),
|
|
111
|
-
|
|
114
|
+
// The server functions' own edge: who a credential names, as their Promise reads it.
|
|
115
|
+
identify: (each) =>
|
|
116
|
+
runtime.runPromise(
|
|
117
|
+
Effect.match(Git.identify(each), {
|
|
118
|
+
onFailure: (error) => ({ kind: 'error', error }) as const,
|
|
119
|
+
onSuccess: (value) => ({ kind: 'success', value }) as const,
|
|
120
|
+
}),
|
|
121
|
+
),
|
|
112
122
|
authorize: policy.authorize,
|
|
113
123
|
authorizeGitHub: policy.authorizeGitHub,
|
|
114
124
|
rules,
|