ref0-git 0.7.0 → 0.8.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 +8 -11
- package/app/apps/github/src/components/signin/device-card.tsx +2 -2
- package/app/apps/github/src/seed/seed.ts +59 -36
- package/app/apps/github/src/signin/device-code.ts +2 -2
- package/app/apps/github/src/signin/device-prompt.ts +6 -6
- package/app/pnpm-workspace.yaml +2 -2
- package/dist/cli/events.mjs +10 -13
- package/dist/cli/failure.mjs +4 -10
- package/dist/cli/hosts.mjs +2 -2
- package/dist/cli/queue.mjs +14 -23
- package/dist/cli/repos.mjs +10 -19
- package/dist/cli/resources.mjs +2 -2
- package/dist/cli/setup.mjs +33 -40
- package/dist/cli/sign-in.mjs +4 -4
- package/dist/cli/tokens.mjs +7 -11
- package/dist/cli/vendor.mjs +21 -1
- package/dist/init/app.mjs +6 -4
- package/dist/init/astro.mjs +2 -2
- package/dist/init/cloudflare.mjs +95 -50
- package/dist/init/detect.mjs +4 -4
- package/dist/init/git-module.mjs +89 -30
- package/dist/init/metadata.mjs +7 -2
- package/dist/init/mounts.mjs +12 -20
- package/dist/init/next.mjs +1 -1
- package/dist/init/node.mjs +24 -35
- package/dist/init/nuxt.mjs +6 -7
- package/dist/init/react-router.mjs +2 -2
- package/dist/init/routes.mjs +13 -22
- package/dist/init/sveltekit.mjs +3 -3
- package/dist/init/template.mjs +6 -13
- package/dist/init/templates.mjs +31 -48
- package/dist/init/vercel.mjs +18 -22
- package/dist/init/versions.mjs +32 -4
- package/package.json +5 -5
|
@@ -1386,7 +1386,7 @@ export interface components {
|
|
|
1386
1386
|
TokenInfo: {
|
|
1387
1387
|
id: string;
|
|
1388
1388
|
/** @enum {string} */
|
|
1389
|
-
scope: "read" | "report" | "write";
|
|
1389
|
+
scope: "read" | "report" | "write" | "admin";
|
|
1390
1390
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1391
1391
|
createdAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1392
1392
|
repo: string;
|
|
@@ -1394,7 +1394,7 @@ export interface components {
|
|
|
1394
1394
|
} | {
|
|
1395
1395
|
id: string;
|
|
1396
1396
|
/** @enum {string} */
|
|
1397
|
-
scope: "read" | "report" | "write";
|
|
1397
|
+
scope: "read" | "report" | "write" | "admin";
|
|
1398
1398
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1399
1399
|
createdAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1400
1400
|
prefix: string;
|
|
@@ -1403,7 +1403,7 @@ export interface components {
|
|
|
1403
1403
|
TokenRecord: {
|
|
1404
1404
|
id: string;
|
|
1405
1405
|
/** @enum {string} */
|
|
1406
|
-
scope: "read" | "report" | "write";
|
|
1406
|
+
scope: "read" | "report" | "write" | "admin";
|
|
1407
1407
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1408
1408
|
createdAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1409
1409
|
subject: {
|
|
@@ -1418,7 +1418,7 @@ export interface components {
|
|
|
1418
1418
|
} | {
|
|
1419
1419
|
id: string;
|
|
1420
1420
|
/** @enum {string} */
|
|
1421
|
-
scope: "read" | "report" | "write";
|
|
1421
|
+
scope: "read" | "report" | "write" | "admin";
|
|
1422
1422
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1423
1423
|
createdAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1424
1424
|
subject: {
|
|
@@ -1434,7 +1434,7 @@ export interface components {
|
|
|
1434
1434
|
CreatedToken: {
|
|
1435
1435
|
id: string;
|
|
1436
1436
|
/** @enum {string} */
|
|
1437
|
-
scope: "read" | "report" | "write";
|
|
1437
|
+
scope: "read" | "report" | "write" | "admin";
|
|
1438
1438
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1439
1439
|
createdAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1440
1440
|
subject: {
|
|
@@ -1450,7 +1450,7 @@ export interface components {
|
|
|
1450
1450
|
} | {
|
|
1451
1451
|
id: string;
|
|
1452
1452
|
/** @enum {string} */
|
|
1453
|
-
scope: "read" | "report" | "write";
|
|
1453
|
+
scope: "read" | "report" | "write" | "admin";
|
|
1454
1454
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1455
1455
|
createdAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1456
1456
|
subject: {
|
|
@@ -1528,9 +1528,6 @@ export interface components {
|
|
|
1528
1528
|
packs?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1529
1529
|
packBytes?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1530
1530
|
ownBytes?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1531
|
-
looseObjects?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1532
|
-
looseBytes?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1533
|
-
leavingBytes?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1534
1531
|
pushedAt?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1535
1532
|
maintainedAt?: number | ("Infinity" | "-Infinity" | "NaN");
|
|
1536
1533
|
};
|
|
@@ -4397,7 +4394,7 @@ export interface operations {
|
|
|
4397
4394
|
content: {
|
|
4398
4395
|
"application/json": {
|
|
4399
4396
|
/** @enum {string} */
|
|
4400
|
-
scope: "read" | "report" | "write";
|
|
4397
|
+
scope: "read" | "report" | "write" | "admin";
|
|
4401
4398
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
4402
4399
|
subject: {
|
|
4403
4400
|
id: string;
|
|
@@ -4664,7 +4661,7 @@ export interface operations {
|
|
|
4664
4661
|
content: {
|
|
4665
4662
|
"application/json": {
|
|
4666
4663
|
/** @enum {string} */
|
|
4667
|
-
scope: "read" | "report" | "write";
|
|
4664
|
+
scope: "read" | "report" | "write" | "admin";
|
|
4668
4665
|
expiresAt: number | ("Infinity" | "-Infinity" | "NaN");
|
|
4669
4666
|
subject: {
|
|
4670
4667
|
id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GrantScope } from '@ref0/git';
|
|
2
2
|
import { MonitorSmartphoneIcon } from 'lucide-react';
|
|
3
3
|
|
|
4
4
|
import type { DeviceCardState } from '../../signin/device-code.ts';
|
|
@@ -20,7 +20,7 @@ import { Input } from '../ui/input.tsx';
|
|
|
20
20
|
const action = '/login/device';
|
|
21
21
|
|
|
22
22
|
/** What each token scope lets a device do, as the Card says it before Approve. */
|
|
23
|
-
const scopeSays: Readonly<Record<
|
|
23
|
+
const scopeSays: Readonly<Record<GrantScope, string>> = {
|
|
24
24
|
read: 'read every repository you can',
|
|
25
25
|
report: 'read every repository you can, and report CI results and deployments on them',
|
|
26
26
|
write: 'read and write every repository you can',
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { CreatedToken, GitError, Oid, RefName, RepoName, Result, Signature } from '@ref0/git';
|
|
2
|
-
import {
|
|
2
|
+
import { RestClient } from '@ref0/git';
|
|
3
|
+
import type { RestClientCalls } from '@ref0/git';
|
|
3
4
|
import type { Change, Committed, Read, Scope, Snapshot } from '@ref0/infra';
|
|
4
|
-
import
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as FetchHttpClient from 'effect/http/FetchHttpClient';
|
|
5
7
|
import * as Schema from 'effect/Schema';
|
|
6
8
|
|
|
7
9
|
import { org, pip, repos } from './acme.ts';
|
|
@@ -54,6 +56,15 @@ const day = 24 * 60 * 60 * 1000;
|
|
|
54
56
|
/** How long a person's seed token lasts: the seed revokes it when it ends, and a cut one expires. */
|
|
55
57
|
const tokenLife = 60 * 60 * 1000;
|
|
56
58
|
|
|
59
|
+
/** `call` run once, to Git's `Result`. */
|
|
60
|
+
const answer = <A>(call: Effect.Effect<A, GitError>): Promise<Result<A>> =>
|
|
61
|
+
Effect.runPromise(
|
|
62
|
+
Effect.match(call, {
|
|
63
|
+
onSuccess: (value): Result<A> => ({ kind: 'success', value }),
|
|
64
|
+
onFailure: (error): Result<A> => ({ kind: 'error', error }),
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
|
|
57
68
|
const value = <A>(result: Result<A>, doing: string): A => {
|
|
58
69
|
if (result.kind === 'success') return result.value;
|
|
59
70
|
|
|
@@ -87,11 +98,11 @@ const saveProgress = async (store: SeedRecords, version: number, progress: Progr
|
|
|
87
98
|
* The progress to go on from: a cut seed's, or a new one when the host holds no repos. A host
|
|
88
99
|
* whose seed is done, or that has repos of its own, gets none.
|
|
89
100
|
*/
|
|
90
|
-
const begin = async (store: SeedRecords, admin:
|
|
101
|
+
const begin = async (store: SeedRecords, admin: RestClientCalls): Promise<Progress | undefined> => {
|
|
91
102
|
const { version, progress } = await readProgress(store);
|
|
92
103
|
if (progress !== undefined) return progress.state === 'running' ? progress : undefined;
|
|
93
104
|
|
|
94
|
-
const listed = value(await admin.repos.list({ page: { limit: 1 } }), 'list the repos');
|
|
105
|
+
const listed = value(await answer(admin.repos.list({ page: { limit: 1 } })), 'list the repos');
|
|
95
106
|
if (listed.items.length > 0) return undefined;
|
|
96
107
|
|
|
97
108
|
const started: Progress = { state: 'running', since: Date.now() };
|
|
@@ -216,9 +227,9 @@ const decodeTitled = Schema.decodeUnknownSync(
|
|
|
216
227
|
* drop-in calls.
|
|
217
228
|
*/
|
|
218
229
|
interface Cast {
|
|
219
|
-
readonly admin:
|
|
230
|
+
readonly admin: RestClientCalls;
|
|
220
231
|
readonly adminCall: Call;
|
|
221
|
-
readonly git: (person: Person) =>
|
|
232
|
+
readonly git: (person: Person) => RestClientCalls;
|
|
222
233
|
readonly call: (person: Person) => Call;
|
|
223
234
|
}
|
|
224
235
|
|
|
@@ -226,7 +237,7 @@ const ensureRepo = async (cast: Cast, id: RepoName, path: string, description: s
|
|
|
226
237
|
const found = await cast.adminCall('GET', path);
|
|
227
238
|
|
|
228
239
|
if (found.status === 404) {
|
|
229
|
-
value(await cast.admin.repos.create({ name: id, public: true }), `make ${id}`);
|
|
240
|
+
value(await answer(cast.admin.repos.create({ name: id, public: true })), `make ${id}`);
|
|
230
241
|
} else if (decodeDescribed(found.text).description === (description || null)) {
|
|
231
242
|
return;
|
|
232
243
|
}
|
|
@@ -237,7 +248,7 @@ const ensureRepo = async (cast: Cast, id: RepoName, path: string, description: s
|
|
|
237
248
|
|
|
238
249
|
/** Each commit in turn on `parent`, as `git commit` makes them; their IDs, oldest first. */
|
|
239
250
|
const commitAll = async (
|
|
240
|
-
git:
|
|
251
|
+
git: RestClientCalls,
|
|
241
252
|
id: RepoName,
|
|
242
253
|
parent: Oid | undefined,
|
|
243
254
|
commits: readonly SeedCommit[],
|
|
@@ -247,12 +258,14 @@ const commitAll = async (
|
|
|
247
258
|
let tip = parent;
|
|
248
259
|
|
|
249
260
|
for (const commit of commits) {
|
|
250
|
-
const created = await
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
261
|
+
const created = await answer(
|
|
262
|
+
git.commits.create(id, {
|
|
263
|
+
parents: tip === undefined ? [] : [tip],
|
|
264
|
+
changes: Object.entries(commit.files).map(([path, content]) => ({ path, content })),
|
|
265
|
+
message: `${commit.message}\n`,
|
|
266
|
+
author: signature(commit.by, since, commit.daysAgo),
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
256
269
|
tip = value(created, `commit "${commit.message}" to ${id}`).oid;
|
|
257
270
|
made.push(tip);
|
|
258
271
|
}
|
|
@@ -265,7 +278,7 @@ const commitAll = async (
|
|
|
265
278
|
* makes the same objects, then each branch and the tag that isn't there yet, at once. Checks the
|
|
266
279
|
* expected refs first so a resumed seed skips rebuilding commits and tags once every ref exists.
|
|
267
280
|
*/
|
|
268
|
-
const pushHistory = async (git:
|
|
281
|
+
const pushHistory = async (git: RestClientCalls, id: RepoName, repo: SeedRepo, since: number) => {
|
|
269
282
|
const { release } = repo;
|
|
270
283
|
const targets: readonly {
|
|
271
284
|
readonly ref: RefName;
|
|
@@ -284,12 +297,14 @@ const pushHistory = async (git: RestClient, id: RepoName, repo: SeedRepo, since:
|
|
|
284
297
|
ref: `refs/tags/${release.tag}`,
|
|
285
298
|
build: async (main: readonly Oid[]) => {
|
|
286
299
|
const tagged = repo.main[release.at];
|
|
287
|
-
const tag = await
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
const tag = await answer(
|
|
301
|
+
git.tags.create(id, {
|
|
302
|
+
object: main[release.at] ?? '',
|
|
303
|
+
tag: release.tag,
|
|
304
|
+
tagger: signature(pip, since, (tagged?.daysAgo ?? 0) - 1),
|
|
305
|
+
message: `${release.title}\n`,
|
|
306
|
+
}),
|
|
307
|
+
);
|
|
293
308
|
|
|
294
309
|
return value(tag, `tag ${release.tag}`).oid;
|
|
295
310
|
},
|
|
@@ -300,7 +315,7 @@ const pushHistory = async (git: RestClient, id: RepoName, repo: SeedRepo, since:
|
|
|
300
315
|
const missingRefs = new Set<RefName>();
|
|
301
316
|
|
|
302
317
|
for (const { ref } of targets) {
|
|
303
|
-
const found = await git.refs.get(id, { ref });
|
|
318
|
+
const found = await answer(git.refs.get(id, { ref }));
|
|
304
319
|
if (found.kind === 'success') continue;
|
|
305
320
|
|
|
306
321
|
if (!missing(found.error)) value(found, `read ${ref}`);
|
|
@@ -317,7 +332,10 @@ const pushHistory = async (git: RestClient, id: RepoName, repo: SeedRepo, since:
|
|
|
317
332
|
if (missingRefs.has(ref)) absent.push({ ref, from: null, to });
|
|
318
333
|
}
|
|
319
334
|
|
|
320
|
-
const updated = value(
|
|
335
|
+
const updated = value(
|
|
336
|
+
await answer(git.refs.update(id, { updates: absent, atomic: true })),
|
|
337
|
+
'push',
|
|
338
|
+
);
|
|
321
339
|
const refused = updated.updates.find((update) => update.kind === 'rejected');
|
|
322
340
|
if (refused !== undefined) throw new Error(`The seed's push of ${refused.ref} was refused`);
|
|
323
341
|
};
|
|
@@ -520,14 +538,14 @@ const members: ReadonlySet<string> = new Set(org.members.map((person) => person.
|
|
|
520
538
|
* its ID, was lost, or its revoke never came. The host's own tokens expire at other times.
|
|
521
539
|
*/
|
|
522
540
|
const revokeLeft = async (
|
|
523
|
-
admin:
|
|
541
|
+
admin: RestClientCalls,
|
|
524
542
|
expiries: ReadonlySet<number>,
|
|
525
543
|
after?: string,
|
|
526
544
|
): Promise<void> => {
|
|
527
545
|
const active = { state: 'active' as const };
|
|
528
546
|
const input = after === undefined ? active : { ...active, page: { after } };
|
|
529
547
|
const page = value(
|
|
530
|
-
await admin.tokens.list({ prefix: `${org.login}/` }, input),
|
|
548
|
+
await answer(admin.tokens.list({ prefix: `${org.login}/` }, input)),
|
|
531
549
|
'list the tokens a cut seed left',
|
|
532
550
|
);
|
|
533
551
|
const left = page.items.filter(
|
|
@@ -535,7 +553,8 @@ const revokeLeft = async (
|
|
|
535
553
|
expiries.has(token.expiresAt) && token.scope === 'write' && members.has(token.subject.id),
|
|
536
554
|
);
|
|
537
555
|
|
|
538
|
-
for (const token of left)
|
|
556
|
+
for (const token of left)
|
|
557
|
+
value(await answer(admin.tokens.revoke(token.id)), 'revoke a token it left');
|
|
539
558
|
|
|
540
559
|
if (page.next !== undefined) await revokeLeft(admin, expiries, page.next);
|
|
541
560
|
};
|
|
@@ -551,7 +570,13 @@ const revokeLeft = async (
|
|
|
551
570
|
*/
|
|
552
571
|
export const seed = async (host: SeedHost): Promise<SeedOutcome> => {
|
|
553
572
|
const client = (token: string) =>
|
|
554
|
-
|
|
573
|
+
Effect.runSync(
|
|
574
|
+
Effect.provide(
|
|
575
|
+
RestClient.make({ url: host.origin, credentials: { token }, transport: host.fetch }),
|
|
576
|
+
// @effect-diagnostics-next-line unstableApiUsage:off
|
|
577
|
+
FetchHttpClient.layer,
|
|
578
|
+
),
|
|
579
|
+
);
|
|
555
580
|
const admin = client(host.adminToken);
|
|
556
581
|
|
|
557
582
|
const progress = await begin(host.store, admin);
|
|
@@ -577,18 +602,16 @@ export const seed = async (host: SeedHost): Promise<SeedOutcome> => {
|
|
|
577
602
|
|
|
578
603
|
try {
|
|
579
604
|
for (const person of org.members) {
|
|
580
|
-
const token = await
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
scope: 'write',
|
|
584
|
-
|
|
585
|
-
expiresAt: tokensExpire,
|
|
586
|
-
},
|
|
605
|
+
const token = await answer(
|
|
606
|
+
admin.tokens.create(
|
|
607
|
+
{ prefix: `${org.login}/` },
|
|
608
|
+
{ scope: 'write', subject: { id: person.login }, expiresAt: tokensExpire },
|
|
609
|
+
),
|
|
587
610
|
);
|
|
588
611
|
issued.set(person.login, value(token, `make ${person.login}'s token`));
|
|
589
612
|
}
|
|
590
613
|
|
|
591
|
-
const gitClients = new Map<string,
|
|
614
|
+
const gitClients = new Map<string, RestClientCalls>();
|
|
592
615
|
const dropInCalls = new Map<string, Call>();
|
|
593
616
|
const secret = (person: Person) => issued.get(person.login)?.secret ?? '';
|
|
594
617
|
const memo = <A>(cache: Map<string, A>, person: Person, make: (token: string) => A): A => {
|
|
@@ -611,7 +634,7 @@ export const seed = async (host: SeedHost): Promise<SeedOutcome> => {
|
|
|
611
634
|
for (const repo of repos) await seedRepo(cast, repo, progress.since);
|
|
612
635
|
} finally {
|
|
613
636
|
// One at a time: revokes at once in one scope miss each other's writes, and some run out of tries.
|
|
614
|
-
for (const token of issued.values()) revoked.push(await admin.tokens.revoke(token.id));
|
|
637
|
+
for (const token of issued.values()) revoked.push(await answer(admin.tokens.revoke(token.id)));
|
|
615
638
|
}
|
|
616
639
|
|
|
617
640
|
// A revoke that failed leaves the seed running, so the next call revokes what it left.
|
|
@@ -4,7 +4,7 @@ import { flow } from 'effect/Function';
|
|
|
4
4
|
import * as Option from 'effect/Option';
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { GrantScope } from '@ref0/git';
|
|
8
8
|
|
|
9
9
|
import { clientLabel, openPrompt, openRetry, tokenScopeOf } from './device-prompt.ts';
|
|
10
10
|
|
|
@@ -27,7 +27,7 @@ export type DeviceCardState =
|
|
|
27
27
|
readonly login: string;
|
|
28
28
|
readonly userCode: string;
|
|
29
29
|
/** What Approve grants over every repo `login` may reach: `tokenScopeOf` the device's scopes. */
|
|
30
|
-
readonly tokenScope:
|
|
30
|
+
readonly tokenScope: GrantScope;
|
|
31
31
|
/** How many days the token Approve mints lasts. */
|
|
32
32
|
readonly days: number;
|
|
33
33
|
/** The scopes the device asked for, which `tokenScope` reaches past `read` only if one names it. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { DeviceApproval,
|
|
1
|
+
import type { DeviceApproval, GrantScope } from '@ref0/git';
|
|
2
2
|
import { ghClientId, ghWriteScope } from '@ref0/git/auth';
|
|
3
|
-
import {
|
|
3
|
+
import { grantScopes } from '@ref0/git';
|
|
4
4
|
import * as Option from 'effect/Option';
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
@@ -42,17 +42,17 @@ const promptLife = 10 * 60 * 1000;
|
|
|
42
42
|
* unless it names one of these. `public_repo` reads, where GitHub would let it write public repos:
|
|
43
43
|
* a deliberate narrowing, since a Git token has no write over public repos alone.
|
|
44
44
|
*/
|
|
45
|
-
const pastRead: ReadonlyMap<string,
|
|
45
|
+
const pastRead: ReadonlyMap<string, GrantScope> = new Map([
|
|
46
46
|
[ghWriteScope, 'write'],
|
|
47
47
|
['repo:status', 'report'],
|
|
48
48
|
['repo_deployment', 'report'],
|
|
49
49
|
]);
|
|
50
50
|
|
|
51
51
|
/** Approve's token scope: each scope a device asks for maps as GitHub reads it; the widest wins. */
|
|
52
|
-
export const tokenScopeOf = (scopes: readonly string[]):
|
|
53
|
-
const reached = scopes.map((scope) =>
|
|
52
|
+
export const tokenScopeOf = (scopes: readonly string[]): GrantScope => {
|
|
53
|
+
const reached = scopes.map((scope) => grantScopes.indexOf(pastRead.get(scope) ?? 'read'));
|
|
54
54
|
|
|
55
|
-
return
|
|
55
|
+
return grantScopes[Math.max(0, ...reached)] ?? 'read';
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
/**
|
package/app/pnpm-workspace.yaml
CHANGED
|
@@ -40,8 +40,8 @@ catalog:
|
|
|
40
40
|
'@octokit/openapi-types': 29.0.1
|
|
41
41
|
# GitHub's GraphQL schema, as Octokit packages it from GitHub's public schema. MIT. The test
|
|
42
42
|
# data @ref0/github's served GraphQL schema is checked against: every type and field it serves
|
|
43
|
-
# is GitHub's at this pin. The latest release on
|
|
44
|
-
'@octokit/graphql-schema':
|
|
43
|
+
# is GitHub's at this pin. The latest release on 29 Nov 2026.
|
|
44
|
+
'@octokit/graphql-schema': 16.0.0
|
|
45
45
|
# Octokit's GitHub App auth, which @ref0/github's App tests sign JWTs and mint installation
|
|
46
46
|
# tokens with, as a CI job would. MIT.
|
|
47
47
|
'@octokit/auth-app': 8.3.1
|
package/dist/cli/events.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { failure, refused } from "./failure.mjs";
|
|
2
2
|
import { hostFlag } from "./hosts.mjs";
|
|
3
3
|
import { printable, streamed } from "./output.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { durationOf, remoteFor, repoArgument } from "./resources.mjs";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Stream from "effect/Stream";
|
|
6
7
|
import * as Option from "effect/Option";
|
|
7
8
|
import * as Predicate from "effect/Predicate";
|
|
8
9
|
import * as Command from "effect/cli/Command";
|
|
@@ -32,20 +33,16 @@ const listen = Command.make("listen", {
|
|
|
32
33
|
onSome: (set) => set.has(event.type)
|
|
33
34
|
}) && (entry === void 0 || namesEntry(event, entry));
|
|
34
35
|
const reading = Effect.gen(function* () {
|
|
35
|
-
const
|
|
36
|
-
const reader = yield* Effect.acquireRelease(Effect.sync(() => opened.value.getReader()), (held) => Effect.promise(() => held.cancel().catch(() => void 0)));
|
|
36
|
+
const remote = yield* remoteFor(flags.host);
|
|
37
37
|
let left = flags.follow ? Number.POSITIVE_INFINITY : Math.max(flags.count, 1);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
try: () => reader.read(),
|
|
41
|
-
catch: (error) => Predicate.hasProperty(error, "code") ? refused(error, opened.host) : failure("unreachable", `Lost ${opened.host}'s event stream`)
|
|
42
|
-
});
|
|
43
|
-
if (read.done) return yield* failure("stream_closed", `${printable(flags.repo)} was deleted before the events came`);
|
|
44
|
-
if (!matches(read.value)) continue;
|
|
45
|
-
if (!(yield* streamed(read.value))) return;
|
|
38
|
+
let done = false;
|
|
39
|
+
yield* remote.client.events.listen(flags.repo).pipe(Stream.filter(matches), Stream.mapError((error) => refused(error, remote.host)), Stream.runForEachWhile((event) => Effect.map(streamed(event), (printed) => {
|
|
46
40
|
left -= 1;
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
done = !printed || left <= 0;
|
|
42
|
+
return !done;
|
|
43
|
+
})), Effect.catchDefect(() => Effect.fail(failure("unreachable", `Lost ${remote.host}'s event stream`))));
|
|
44
|
+
if (!done) return yield* failure("stream_closed", `${printable(flags.repo)} was deleted before the events came`);
|
|
45
|
+
});
|
|
49
46
|
yield* within === void 0 ? reading : Effect.timeoutOrElse(reading, {
|
|
50
47
|
duration: within,
|
|
51
48
|
orElse: () => Effect.fail(failure("timeout", `No matching event came within ${Option.getOrElse(flags.timeout, () => "")}`))
|
package/dist/cli/failure.mjs
CHANGED
|
@@ -100,19 +100,13 @@ const tooManyWritesPause = (tried) => Duration.millis(250 * 2 ** tried);
|
|
|
100
100
|
const wroteNothing = (error) => error.code === "UNAVAILABLE" && Predicate.hasProperty(error.context, "reason") && error.context.reason === "too-many-writes";
|
|
101
101
|
/**
|
|
102
102
|
* A call's answer, or its refusal as the CLI's failure, sent again on `too-many-writes` at most
|
|
103
|
-
* `tooManyWritesTriesMost` times, each try said on stderr.
|
|
104
|
-
* so a cancel stops its request.
|
|
103
|
+
* `tooManyWritesTriesMost` times, each try said on stderr. Interrupting the run stops its request.
|
|
105
104
|
*/
|
|
106
105
|
const answered = (host, call) => {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
catch: () => failure("unreachable", `Couldn't reach ${host}`)
|
|
110
|
-
});
|
|
111
|
-
const tried = (tries) => Effect.flatMap(sent, (result) => {
|
|
112
|
-
if (result.kind === "success") return Effect.succeed(result.value);
|
|
113
|
-
if (tries >= 3 || !wroteNothing(result.error)) return Effect.fail(refused(result.error, host));
|
|
106
|
+
const tried = (tries) => Effect.catch(call, (error) => {
|
|
107
|
+
if (tries >= 3 || !wroteNothing(error)) return Effect.fail(refused(error, host));
|
|
114
108
|
return say(`${host} had too many writes at once. Trying again (${tries + 1} of 3)`).pipe(Effect.andThen(Effect.sleep(tooManyWritesPause(tries))), Effect.andThen(tried(tries + 1)));
|
|
115
109
|
});
|
|
116
|
-
return tried(0);
|
|
110
|
+
return Effect.catchDefect(tried(0), () => Effect.fail(failure("unreachable", `Couldn't reach ${host}`)));
|
|
117
111
|
};
|
|
118
112
|
export { CliFailure, answered, cancelled, diskFailed, exitCodes, failure, forget, leftBehind, leftovers, notPutBack, refused, snakeCase, unsafeCredential, usageFailure };
|
package/dist/cli/hosts.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import * as Redacted from "effect/Redacted";
|
|
|
9
9
|
import * as Option from "effect/Option";
|
|
10
10
|
import * as Schema from "effect/Schema";
|
|
11
11
|
import * as Flag from "effect/cli/Flag";
|
|
12
|
-
import {
|
|
12
|
+
import { RestClient } from "@ref0/git";
|
|
13
13
|
// src/cli/hosts.ts
|
|
14
14
|
/**
|
|
15
15
|
* The hosts `ref0-git` is signed in to, and the one a command talks to. Git's helpers can't list
|
|
@@ -118,7 +118,7 @@ const remoteOf = /* @__PURE__ */ Effect.fnUntraced(function* (chosen) {
|
|
|
118
118
|
endpoint,
|
|
119
119
|
origin,
|
|
120
120
|
host,
|
|
121
|
-
client:
|
|
121
|
+
client: yield* RestClient.make({
|
|
122
122
|
url: endpoint,
|
|
123
123
|
credentials: { token }
|
|
124
124
|
})
|
package/dist/cli/queue.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import * as Effect from "effect/Effect";
|
|
|
6
6
|
import * as Option from "effect/Option";
|
|
7
7
|
import * as Command from "effect/cli/Command";
|
|
8
8
|
import * as Flag from "effect/cli/Flag";
|
|
9
|
-
import * as Argument from "effect/cli/Argument";
|
|
10
9
|
import { branchRef, shortTarget } from "@ref0/git";
|
|
10
|
+
import * as Argument from "effect/cli/Argument";
|
|
11
11
|
// src/cli/queue.ts
|
|
12
12
|
/**
|
|
13
13
|
* `queue`: a repo's merge queue. An entry's, a hold's and a candidate's ID names its repo, so the
|
|
@@ -17,7 +17,7 @@ import { branchRef, shortTarget } from "@ref0/git";
|
|
|
17
17
|
const idArgument = (name, what) => Argument.String(name).pipe(Argument.withDescription(`The ${what}'s ID, as the queue printed it`));
|
|
18
18
|
const targetFlag = Flag.String("target").pipe(Flag.withDescription("The branch it merges into: the repo's default branch when it's left out"), Flag.withMetavar("BRANCH"), Flag.optional);
|
|
19
19
|
/** The branch `--target` names, else the repo's default branch, as the host says it. */
|
|
20
|
-
const targetOf = (remote, repo, target) => Option.isSome(target) ? Effect.succeed(branchRef(target.value)) : Effect.flatMap(answered(remote.host,
|
|
20
|
+
const targetOf = (remote, repo, target) => Option.isSome(target) ? Effect.succeed(branchRef(target.value)) : Effect.flatMap(answered(remote.host, remote.client.repos.get(repo, {})), (info) => info.defaultBranch === void 0 ? Effect.fail(usageFailure("no_default_branch", `${printable(repo)} shows you no default branch`, "Name the branch with --target")) : Effect.succeed(info.defaultBranch));
|
|
21
21
|
const add = Command.make("add", {
|
|
22
22
|
repo: repoArgument,
|
|
23
23
|
host: hostFlag,
|
|
@@ -31,22 +31,18 @@ const add = Command.make("add", {
|
|
|
31
31
|
const ask = (call) => answered(remote.host, call);
|
|
32
32
|
const source = branchRef(flags.source);
|
|
33
33
|
const target = yield* targetOf(remote, flags.repo, flags.target);
|
|
34
|
-
const tip = yield* ask(
|
|
35
|
-
|
|
36
|
-
signal
|
|
37
|
-
}));
|
|
38
|
-
const added = yield* ask((signal) => {
|
|
34
|
+
const tip = yield* ask(remote.client.refs.get(flags.repo, { ref: source }));
|
|
35
|
+
const added = yield* ask(Effect.suspend(() => {
|
|
39
36
|
const input = {
|
|
40
37
|
target,
|
|
41
38
|
source,
|
|
42
39
|
head: tip.oid,
|
|
43
|
-
key: Option.getOrElse(flags.key, () => shortTarget(source))
|
|
44
|
-
signal
|
|
40
|
+
key: Option.getOrElse(flags.key, () => shortTarget(source))
|
|
45
41
|
};
|
|
46
42
|
if (Option.isSome(flags.priority)) input.priority = flags.priority.value;
|
|
47
43
|
if (flags.jump) input.jump = true;
|
|
48
44
|
return remote.client.queue.add(flags.repo, input);
|
|
49
|
-
});
|
|
45
|
+
}));
|
|
50
46
|
const entry = added.entry.id;
|
|
51
47
|
yield* changed(added, entry, {
|
|
52
48
|
done: `${added.repeat ? "Already added" : "Added"} ${printable(shortTarget(source))} to the queue for ${printable(shortTarget(target))} in ${printable(flags.repo)}`,
|
|
@@ -76,7 +72,7 @@ const remove = Command.make("remove", {
|
|
|
76
72
|
entry: idArgument("ENTRY", "entry"),
|
|
77
73
|
host: hostFlag
|
|
78
74
|
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
79
|
-
const done = yield* called(flags.host, (client
|
|
75
|
+
const done = yield* called(flags.host, (client) => client.queue.remove(flags.entry, {}));
|
|
80
76
|
yield* changed(done.value, flags.entry, { done: `Removed ${printable(flags.entry)} from the queue on ${done.host}` });
|
|
81
77
|
})).pipe(Command.withDescription("Take an entry out of the queue"));
|
|
82
78
|
/** An entry's row, as `queue list` prints it. */
|
|
@@ -104,10 +100,9 @@ const list = Command.make("list", {
|
|
|
104
100
|
"--target",
|
|
105
101
|
shortTarget(target)
|
|
106
102
|
]];
|
|
107
|
-
const read = yield* pagesOf(remote, flags, command, entryLine, (client, page
|
|
103
|
+
const read = yield* pagesOf(remote, flags, command, entryLine, (client, page) => client.queue.list(flags.repo, {
|
|
108
104
|
target,
|
|
109
|
-
page
|
|
110
|
-
signal
|
|
105
|
+
page
|
|
111
106
|
}));
|
|
112
107
|
yield* listed(read, {
|
|
113
108
|
line: entryLine,
|
|
@@ -120,7 +115,7 @@ const show = Command.make("show", {
|
|
|
120
115
|
entry: idArgument("ENTRY", "entry"),
|
|
121
116
|
host: hostFlag
|
|
122
117
|
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
123
|
-
const entry = (yield* called(flags.host, (client
|
|
118
|
+
const entry = (yield* called(flags.host, (client) => client.queue.get(flags.entry, {}))).value;
|
|
124
119
|
if ((yield* CliModes).json) return yield* document(entry);
|
|
125
120
|
const rows = [
|
|
126
121
|
["Entry", printable(entry.id)],
|
|
@@ -165,13 +160,9 @@ const hold = Command.make("hold", {
|
|
|
165
160
|
"--help"
|
|
166
161
|
]]
|
|
167
162
|
});
|
|
168
|
-
const held = yield* called(flags.host, (client
|
|
169
|
-
reason: flags.reason,
|
|
170
|
-
signal
|
|
171
|
-
}) : client.queue.hold(what.repo, {
|
|
163
|
+
const held = yield* called(flags.host, (client) => what.entry !== void 0 ? client.queue.hold(what.entry, { reason: flags.reason }) : client.queue.hold(what.repo, {
|
|
172
164
|
target: branchRef(what.target),
|
|
173
|
-
reason: flags.reason
|
|
174
|
-
signal
|
|
165
|
+
reason: flags.reason
|
|
175
166
|
}));
|
|
176
167
|
const id = held.value.hold.id;
|
|
177
168
|
yield* changed(held.value, id, {
|
|
@@ -193,14 +184,14 @@ const release = Command.make("release", {
|
|
|
193
184
|
hold: idArgument("HOLD", "hold"),
|
|
194
185
|
host: hostFlag
|
|
195
186
|
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
196
|
-
const done = yield* called(flags.host, (client
|
|
187
|
+
const done = yield* called(flags.host, (client) => client.queue.release(flags.hold, {}));
|
|
197
188
|
yield* changed(done.value, flags.hold, { done: `Released ${printable(flags.hold)} on ${done.host}` });
|
|
198
189
|
})).pipe(Command.withDescription("Release a hold"));
|
|
199
190
|
const retry = Command.make("retry", {
|
|
200
191
|
candidate: idArgument("CANDIDATE", "candidate"),
|
|
201
192
|
host: hostFlag
|
|
202
193
|
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
203
|
-
const done = yield* called(flags.host, (client
|
|
194
|
+
const done = yield* called(flags.host, (client) => client.queue.retry(flags.candidate, {}));
|
|
204
195
|
yield* changed(done.value, done.value.candidate, { done: `Closed ${printable(done.value.candidate)} to try its entries again, on ${done.host}` });
|
|
205
196
|
})).pipe(Command.withDescription("Close a candidate and try its entries again"));
|
|
206
197
|
const queueCommand = Command.make("queue").pipe(Command.withDescription("A repo's merge queue (experimental)"), Command.withSubcommands([
|
package/dist/cli/repos.mjs
CHANGED
|
@@ -5,8 +5,7 @@ import * as Effect from "effect/Effect";
|
|
|
5
5
|
import * as Option from "effect/Option";
|
|
6
6
|
import * as Command from "effect/cli/Command";
|
|
7
7
|
import * as Flag from "effect/cli/Flag";
|
|
8
|
-
import { jobStates } from "@ref0/git
|
|
9
|
-
import { branchRef } from "@ref0/git";
|
|
8
|
+
import { branchRef, jobStates } from "@ref0/git";
|
|
10
9
|
import * as Record from "effect/Record";
|
|
11
10
|
// src/cli/repos.ts
|
|
12
11
|
/** `repos` and `work`: a host's repos, and a repo's saved work. */
|
|
@@ -16,11 +15,10 @@ const create = Command.make("create", {
|
|
|
16
15
|
public: Flag.Boolean("public").pipe(Flag.withDescription("Let anyone read it"), Flag.withDefault(false)),
|
|
17
16
|
defaultBranch: Flag.String("default-branch").pipe(Flag.withDescription("Its default branch, the host's default when it's left out"), Flag.withMetavar("BRANCH"), Flag.optional)
|
|
18
17
|
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
19
|
-
const made = yield* called(flags.host, (client
|
|
18
|
+
const made = yield* called(flags.host, (client) => {
|
|
20
19
|
const input = {
|
|
21
20
|
name: flags.repo,
|
|
22
|
-
public: flags.public
|
|
23
|
-
signal
|
|
21
|
+
public: flags.public
|
|
24
22
|
};
|
|
25
23
|
if (Option.isSome(flags.defaultBranch)) input.defaultBranch = branchRef(flags.defaultBranch.value);
|
|
26
24
|
return client.repos.create(input);
|
|
@@ -67,11 +65,10 @@ const list = Command.make("list", {
|
|
|
67
65
|
...prefix === void 0 ? [] : ["--prefix", prefix],
|
|
68
66
|
...flags.order === "name" ? [] : ["--order", flags.order]
|
|
69
67
|
];
|
|
70
|
-
const read = yield* pagesOf(flags.host, flags, command, printable, (client, page
|
|
68
|
+
const read = yield* pagesOf(flags.host, flags, command, printable, (client, page) => {
|
|
71
69
|
const input = {
|
|
72
70
|
page,
|
|
73
|
-
order: repoOrders[flags.order]
|
|
74
|
-
signal
|
|
71
|
+
order: repoOrders[flags.order]
|
|
75
72
|
};
|
|
76
73
|
if (prefix !== void 0) input.prefix = prefix;
|
|
77
74
|
return client.repos.list(input);
|
|
@@ -87,7 +84,7 @@ const show = Command.make("show", {
|
|
|
87
84
|
repo: repoArgument,
|
|
88
85
|
host: hostFlag
|
|
89
86
|
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
90
|
-
const shown = yield* called(flags.host, (client
|
|
87
|
+
const shown = yield* called(flags.host, (client) => client.repos.get(flags.repo, {}));
|
|
91
88
|
const info = shown.value;
|
|
92
89
|
if ((yield* CliModes).json) return yield* document(info);
|
|
93
90
|
const rows = [
|
|
@@ -104,7 +101,7 @@ const remove = Command.make("delete", {
|
|
|
104
101
|
repo: repoArgument,
|
|
105
102
|
host: hostFlag
|
|
106
103
|
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
107
|
-
const done = yield* called(flags.host, (client
|
|
104
|
+
const done = yield* called(flags.host, (client) => client.repos.delete(flags.repo, {}));
|
|
108
105
|
yield* changed(done.value, flags.repo, { done: `Deleted repo ${printable(flags.repo)} on ${done.host}` });
|
|
109
106
|
})).pipe(Command.withDescription("Delete a repo, its refs and its objects"));
|
|
110
107
|
const jobState = Flag.Literals("state", jobStates).pipe(Flag.withDescription("Only work in this state"), Flag.optional);
|
|
@@ -129,11 +126,8 @@ const workList = Command.make("list", {
|
|
|
129
126
|
"--host",
|
|
130
127
|
host
|
|
131
128
|
], ...state === void 0 ? [] : ["--state", state]];
|
|
132
|
-
const read = yield* pagesOf(flags.host, flags, command, jobLine, (client, page
|
|
133
|
-
const input = {
|
|
134
|
-
page,
|
|
135
|
-
signal
|
|
136
|
-
};
|
|
129
|
+
const read = yield* pagesOf(flags.host, flags, command, jobLine, (client, page) => {
|
|
130
|
+
const input = { page };
|
|
137
131
|
if (state !== void 0) input.state = state;
|
|
138
132
|
return client.work.list(flags.repo, input);
|
|
139
133
|
});
|
|
@@ -156,10 +150,7 @@ const workWrite = (verb, description) => Command.make(verb, jobFlags, Effect.fnU
|
|
|
156
150
|
name: flags.name,
|
|
157
151
|
key: flags.key
|
|
158
152
|
};
|
|
159
|
-
const done = yield* called(flags.host, (client
|
|
160
|
-
...job,
|
|
161
|
-
signal
|
|
162
|
-
}));
|
|
153
|
+
const done = yield* called(flags.host, (client) => client.work[verb](flags.repo, { ...job }));
|
|
163
154
|
yield* changed({
|
|
164
155
|
repo: flags.repo,
|
|
165
156
|
...job
|