repown 0.3.0 → 0.5.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/CHANGELOG.md +109 -1
- package/README.md +11 -3
- package/dist/cli.js +4 -4
- package/dist/commands/accounts.js +19 -13
- package/dist/commands/doctor.js +7 -5
- package/dist/commands/fix.js +5 -5
- package/dist/commands/guard.js +7 -5
- package/dist/commands/off.js +4 -4
- package/dist/commands/reauthor.js +64 -0
- package/dist/commands/scan.js +7 -6
- package/dist/commands/setup.js +7 -4
- package/dist/commands/start.js +6 -6
- package/dist/commands/status.js +66 -22
- package/dist/commands/use.js +14 -14
- package/dist/core/blockers.js +133 -0
- package/dist/core/config-snapshot.js +97 -0
- package/dist/core/credential/gcm.js +2 -2
- package/dist/core/credential/gh.js +12 -5
- package/dist/core/credential/repair.js +1 -1
- package/dist/core/git.js +145 -12
- package/dist/core/guard/check.js +48 -8
- package/dist/core/guard/hook.js +1 -1
- package/dist/core/hosts/github.js +11 -5
- package/dist/core/hosts/index.js +21 -3
- package/dist/core/identity.js +1 -1
- package/dist/core/inspect.js +6 -6
- package/dist/core/push-destination.js +82 -0
- package/dist/core/push-state.js +109 -0
- package/dist/core/reauthor.js +145 -0
- package/dist/core/registry.js +1 -1
- package/dist/core/unpushed.js +112 -43
- package/dist/program.js +10 -9
- package/dist/ui/args.js +3 -3
- package/dist/ui/command.js +1 -1
- package/dist/ui/dispatch.js +6 -6
- package/dist/ui/format.js +39 -0
- package/dist/ui/help.js +2 -2
- package/dist/ui/prompt.js +1 -1
- package/dist/wizard/clack.js +56 -21
- package/dist/wizard/engine.js +7 -4
- package/dist/wizard/home-context.js +23 -10
- package/dist/wizard/home-flow.js +33 -11
- package/dist/wizard/home-run.js +85 -44
- package/dist/wizard/home-text.js +14 -3
- package/dist/wizard/plain.js +2 -2
- package/dist/wizard/review-text.js +36 -14
- package/dist/wizard/setup-changes.js +11 -7
- package/dist/wizard/setup-context.js +31 -20
- package/dist/wizard/setup-flow.js +265 -56
- package/dist/wizard/setup-run.js +108 -40
- package/npm-shrinkwrap.json +378 -17
- package/package.json +3 -3
package/dist/wizard/setup-run.js
CHANGED
|
@@ -4,23 +4,29 @@
|
|
|
4
4
|
// path, not a wizard's copy of it.
|
|
5
5
|
//
|
|
6
6
|
// Nothing is written before the commands run. Cancelling exits 130, declining 1.
|
|
7
|
-
import { ghAdvice } from
|
|
8
|
-
import { handingOver } from
|
|
9
|
-
import { ok, err } from
|
|
10
|
-
import { inspectAuth } from
|
|
11
|
-
import { flagBool, flagString, gitFor, parseArgs } from
|
|
12
|
-
import { specFor } from
|
|
13
|
-
import * as out from
|
|
14
|
-
import { useColour } from
|
|
15
|
-
import useCommand, { NEXT_GUARD } from
|
|
16
|
-
import fixCommand from
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
7
|
+
import { ghAdvice } from '../commands/status.js';
|
|
8
|
+
import { handingOver } from '../core/exec.js';
|
|
9
|
+
import { ok, err } from '../core/result.js';
|
|
10
|
+
import { inspectAuth } from '../core/inspect.js';
|
|
11
|
+
import { flagBool, flagString, gitFor, parseArgs } from '../ui/args.js';
|
|
12
|
+
import { specFor } from '../ui/command.js';
|
|
13
|
+
import * as out from '../ui/format.js';
|
|
14
|
+
import { useColour } from '../ui/format.js';
|
|
15
|
+
import useCommand, { NEXT_GUARD } from '../commands/use.js';
|
|
16
|
+
import fixCommand from '../commands/fix.js';
|
|
17
|
+
import reauthorCommand from '../commands/reauthor.js';
|
|
18
|
+
import guardGroup from '../commands/guard.js';
|
|
19
|
+
import accountsGroup from '../commands/accounts.js';
|
|
20
|
+
import { wizard, refusedGiven } from './engine.js';
|
|
21
|
+
import { setupFlow, planCommands, formatCommand, gitStepOf, keptFlags, briefOf, missingFlags, printable, dropFixPrefix, NEW_ACCOUNT, accountOf, pinUnchanged, ghNoted } from './setup-flow.js';
|
|
22
|
+
import { cloneChangeLines, machineChangeLines, readCloneSnapshot } from './setup-changes.js';
|
|
23
|
+
import { readContext, readRegistry } from './setup-context.js';
|
|
24
|
+
import { plainPrompter } from './plain.js';
|
|
25
|
+
import { COMMAND_MARK } from './review-text.js';
|
|
26
|
+
import { blockers } from '../core/blockers.js';
|
|
27
|
+
import { readPushFacts } from '../core/push-state.js';
|
|
28
|
+
import { guardState, hookLocation } from '../core/guard/hook.js';
|
|
29
|
+
import { readUnpushed } from '../core/unpushed.js';
|
|
24
30
|
const CANCELLED = 130;
|
|
25
31
|
export async function runSetup(args, deps) {
|
|
26
32
|
const registry = await readRegistry();
|
|
@@ -117,8 +123,8 @@ function modeOf(args, answers) {
|
|
|
117
123
|
answers['mode'] = 'recommended';
|
|
118
124
|
return ok(answers);
|
|
119
125
|
}
|
|
120
|
-
const CONFIRM_FLAGS = ['gh', 'guard', 'fix'];
|
|
121
|
-
const CONFIRM_DEFAULTS = ['gh', 'allowOwner', 'guard', 'fix', 'upstream'];
|
|
126
|
+
const CONFIRM_FLAGS = ['gh', 'guard', 'fix', 'repoint', 'fetch', 'reauthor'];
|
|
127
|
+
const CONFIRM_DEFAULTS = ['gh', 'allowOwner', 'guard', 'fix', 'upstream', 'repoint', 'fetch', 'reauthor'];
|
|
122
128
|
/** A passed flag is Yes. With --no-input, a confirm that was not passed is No, not Recommended's Yes. */
|
|
123
129
|
function applyConfirms(args, answers) {
|
|
124
130
|
for (const key of CONFIRM_FLAGS)
|
|
@@ -143,7 +149,7 @@ function usage(message) {
|
|
|
143
149
|
function needsTerminal(given, recorded) {
|
|
144
150
|
out.fail('setup', 'needs a terminal to ask its questions.');
|
|
145
151
|
out.detail('without one, give the answers as flags and add --no-input:');
|
|
146
|
-
out.detail(' repown setup <account> [--name "..." --email "..."] [--gh] [--allow-owner <owner>] [--guard] [--auto-upstream] [--fix] --no-input');
|
|
152
|
+
out.detail(' repown setup <account> [--name "..." --email "..."] [--gh] [--allow-owner <owner>] [--guard] [--auto-upstream] [--fix] [--repoint] [--fetch] [--reauthor] --no-input');
|
|
147
153
|
const missing = missingFlags(given, recorded);
|
|
148
154
|
if (missing.length > 0)
|
|
149
155
|
out.detail('still needed: ' + missing.join(', '));
|
|
@@ -169,7 +175,10 @@ function checkAgainst(given, ctx, allowOwner) {
|
|
|
169
175
|
out.detail('--fix: gh is not the credential helper for this clone, so there is nothing to undo');
|
|
170
176
|
answers['fix'] = false;
|
|
171
177
|
}
|
|
172
|
-
|
|
178
|
+
const kept = keptFlags(answers, ctx);
|
|
179
|
+
for (const note of kept.notes)
|
|
180
|
+
out.detail(note);
|
|
181
|
+
return ok(kept.answers);
|
|
173
182
|
}
|
|
174
183
|
// ------------------------------------------------------------------- the runs
|
|
175
184
|
async function runUnattended(answers, ctx, git, readAuth) {
|
|
@@ -231,7 +240,7 @@ export async function choosePrompter() {
|
|
|
231
240
|
if (!useColour(process.stderr) || process.env['TERM'] === 'dumb')
|
|
232
241
|
return plainPrompter(streams);
|
|
233
242
|
try {
|
|
234
|
-
return (await import(
|
|
243
|
+
return (await import('./clack.js')).clackPrompter(streams);
|
|
235
244
|
}
|
|
236
245
|
catch (cause) {
|
|
237
246
|
out.detail('plain prompts: the richer prompter could not load (' + (cause instanceof Error ? cause.message : String(cause)) + ')');
|
|
@@ -239,7 +248,8 @@ export async function choosePrompter() {
|
|
|
239
248
|
}
|
|
240
249
|
}
|
|
241
250
|
function runState(git, readAuth, ctx) {
|
|
242
|
-
|
|
251
|
+
const repointed = ctx.push.repoint ? [ctx.push.repoint.key] : [];
|
|
252
|
+
return { git, readAuth, watchedKeys: [...ctx.credentialKeys, ...repointed] };
|
|
243
253
|
}
|
|
244
254
|
function reported(answers, ctx, repeatGh) {
|
|
245
255
|
return { account: accountOf(answers), pinnedAlready: pinUnchanged(answers, ctx), repeatGh };
|
|
@@ -252,7 +262,7 @@ function reported(answers, ctx, repeatGh) {
|
|
|
252
262
|
* The clone is read before the first step and again after, including a stop or a failure.
|
|
253
263
|
*/
|
|
254
264
|
async function execute(plan, state) {
|
|
255
|
-
const before = await readCloneSnapshot(state.git, state.
|
|
265
|
+
const before = await readCloneSnapshot(state.git, state.watchedKeys);
|
|
256
266
|
const ran = await walk(plan, state.git, state.confirm);
|
|
257
267
|
await reportRun(before, ran, state);
|
|
258
268
|
return ran.code ?? 0;
|
|
@@ -287,7 +297,7 @@ async function offer(plan, index, planned, confirm) {
|
|
|
287
297
|
process.stderr.write('\n');
|
|
288
298
|
out.detail('step ' + (index + 1) + ' of ' + plan.length + ': ' + printable(planned.what));
|
|
289
299
|
if (!confirm) {
|
|
290
|
-
out.detail(
|
|
300
|
+
out.detail(out.accent(process.stderr, COMMAND_MARK + formatCommand(planned.argv)));
|
|
291
301
|
return 'yes';
|
|
292
302
|
}
|
|
293
303
|
return confirm(planned);
|
|
@@ -315,30 +325,51 @@ function halt(remaining, code, why) {
|
|
|
315
325
|
if (remaining.length > 0)
|
|
316
326
|
out.detail('not run:');
|
|
317
327
|
for (const planned of remaining)
|
|
318
|
-
out.detail(' ' + formatCommand(planned.argv));
|
|
328
|
+
out.detail(' ' + out.accent(process.stderr, formatCommand(planned.argv)));
|
|
319
329
|
return code;
|
|
320
330
|
}
|
|
321
331
|
/** On stderr, like the step lines: stdout carries only what the commands themselves print. */
|
|
322
332
|
async function reportRun(before, ran, state) {
|
|
323
333
|
if (ran.code === null)
|
|
324
|
-
announce(ran.done, ran.skipped, state);
|
|
334
|
+
await announce(ran.done, ran.skipped, state);
|
|
325
335
|
await printClone(before, state);
|
|
326
336
|
const auth = wantsAuth(ran, state) ? await state.readAuth(state.git) : null;
|
|
327
337
|
printMachine(ran.done, auth);
|
|
328
338
|
if (ran.code === null)
|
|
329
339
|
closeRun(auth, state);
|
|
330
340
|
}
|
|
331
|
-
function announce(done, skipped,
|
|
341
|
+
async function announce(done, skipped, state) {
|
|
332
342
|
process.stderr.write('\n');
|
|
333
343
|
const pinned = done.find((planned) => planned.argv[0] === 'use')?.argv.at(-1);
|
|
334
|
-
const account = pinned ?? (
|
|
344
|
+
const account = pinned ?? (state.pinnedAlready ? state.account : null);
|
|
335
345
|
if (account)
|
|
336
|
-
|
|
346
|
+
closing(account, await blockersNow(state.git, account));
|
|
337
347
|
for (const planned of skipped)
|
|
338
348
|
out.detail('skipped: ' + printable(planned.what));
|
|
339
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* `done` only with nothing left in the way of the next push; otherwise the first, then each one
|
|
352
|
+
* (ADR-026). What blocks nothing (the guard is off) still gets its lines, under `done`.
|
|
353
|
+
*/
|
|
354
|
+
function closing(account, found) {
|
|
355
|
+
const blocking = found.filter((blocker) => blocker.blocks);
|
|
356
|
+
const more = blocking.length > 1 ? ' (and ' + (blocking.length - 1) + ' more below)' : '';
|
|
357
|
+
const [first] = blocking;
|
|
358
|
+
out.detail(first ? out.marked('warn', process.stderr, 'set up for ' + printable(account) + '; the next push will fail: ' + printable(first.summary) + more)
|
|
359
|
+
: out.marked('ok', process.stderr, 'done: this clone is set up for ' + printable(account)));
|
|
360
|
+
// A mark pushes the closing words two columns right; the blockers stay two deeper still.
|
|
361
|
+
const indent = useColour(process.stderr) ? ' ' : ' ';
|
|
362
|
+
for (const line of found.flatMap((blocker) => blocker.lines))
|
|
363
|
+
out.detail(indent + printable(line));
|
|
364
|
+
}
|
|
365
|
+
/** Re-read after the run: a step may have fixed what the review showed, or not. */
|
|
366
|
+
async function blockersNow(git, account) {
|
|
367
|
+
const email = await git.getConfig('user.email', 'local') ?? '';
|
|
368
|
+
const [facts, guard, hook] = await Promise.all([readPushFacts(git, await readUnpushed(git)), guardState(git), hookLocation(git)]);
|
|
369
|
+
return blockers(facts, { email, account, autoUpstream: false, guarded: guard !== 'off' || hook?.redirected === true });
|
|
370
|
+
}
|
|
340
371
|
async function printClone(before, state) {
|
|
341
|
-
const lines = cloneChangeLines(before, await readCloneSnapshot(state.git, state.
|
|
372
|
+
const lines = cloneChangeLines(before, await readCloneSnapshot(state.git, state.watchedKeys));
|
|
342
373
|
if (lines.length === 0) {
|
|
343
374
|
out.detail('nothing changed in this clone');
|
|
344
375
|
return;
|
|
@@ -420,7 +451,12 @@ async function withoutLine(hidden, run) {
|
|
|
420
451
|
async function runOne(argv, git) {
|
|
421
452
|
if (argv[0] === 'git')
|
|
422
453
|
return gitLine(argv, git);
|
|
423
|
-
const
|
|
454
|
+
const found = commandFor(argv);
|
|
455
|
+
if (!found) {
|
|
456
|
+
out.fail('setup', 'could not run ' + formatCommand(argv) + ': not a step setup plans');
|
|
457
|
+
return 2;
|
|
458
|
+
}
|
|
459
|
+
const [command, rest] = found;
|
|
424
460
|
const parsed = parseArgs(rest, specFor(command));
|
|
425
461
|
if (!parsed.ok) {
|
|
426
462
|
out.fail('setup', 'could not run ' + formatCommand(argv) + ': ' + parsed.error);
|
|
@@ -428,21 +464,53 @@ async function runOne(argv, git) {
|
|
|
428
464
|
}
|
|
429
465
|
return command.run(parsed.value);
|
|
430
466
|
}
|
|
431
|
-
/** The Command a planned argv names, and the arguments after its name. */
|
|
467
|
+
/** The Command a planned argv names, and the arguments after its name; null for anything else. */
|
|
432
468
|
function commandFor(argv) {
|
|
433
469
|
if (argv[0] === 'use')
|
|
434
470
|
return [useCommand, argv.slice(1)];
|
|
435
471
|
if (argv[0] === 'fix')
|
|
436
472
|
return [fixCommand, argv.slice(1)];
|
|
437
|
-
if (argv[0] === '
|
|
473
|
+
if (argv[0] === 'reauthor')
|
|
474
|
+
return [reauthorCommand, argv.slice(1)];
|
|
475
|
+
if (argv[0] === 'guard' && argv[1] === 'on')
|
|
438
476
|
return [guardGroup.actions['on'], argv.slice(2)];
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
477
|
+
if (argv[0] === 'accounts' && argv[1] === 'add')
|
|
478
|
+
return [accountsGroup.actions['add'], argv.slice(2)];
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
/** A planned git line, each by its own case. None shells out past the Git wrapper. */
|
|
482
|
+
async function gitLine(argv, git) {
|
|
483
|
+
const step = gitStepOf(argv);
|
|
484
|
+
if (step === 'upstream')
|
|
444
485
|
return setAutoUpstream(git);
|
|
445
|
-
|
|
486
|
+
if (step === 'allowOwner')
|
|
487
|
+
return allowOwner(argv.at(-1), git);
|
|
488
|
+
if (step === 'repoint')
|
|
489
|
+
return repoint(argv.at(-2), argv.at(-1), git);
|
|
490
|
+
if (step === 'fetch')
|
|
491
|
+
return fetchFirst(argv.at(-1), git);
|
|
492
|
+
out.fail('setup', 'could not run ' + formatCommand(argv) + ': not a step setup plans');
|
|
493
|
+
return 2;
|
|
494
|
+
}
|
|
495
|
+
/** The key's old value is a URL that can hold a token: it is never printed. */
|
|
496
|
+
async function repoint(key, remote, git) {
|
|
497
|
+
if (!(await git.setConfig(key, remote, 'local'))) {
|
|
498
|
+
out.fail('repoint', 'could not write ' + printable(key));
|
|
499
|
+
return 1;
|
|
500
|
+
}
|
|
501
|
+
out.pass('repoint', printable(key) + ' now names ' + printable(remote) + ': pushes go through it');
|
|
502
|
+
return 0;
|
|
503
|
+
}
|
|
504
|
+
/** Prompts off, like reauthor's. A failure is a warning: the rest of the plan still runs. */
|
|
505
|
+
async function fetchFirst(remote, git) {
|
|
506
|
+
const fetched = await git.fetchQuietly(remote);
|
|
507
|
+
if (fetched.ok) {
|
|
508
|
+
out.pass('fetch', printable(remote) + ' fetched: repown can now tell which commits it already has');
|
|
509
|
+
return 0;
|
|
510
|
+
}
|
|
511
|
+
out.warn('fetch', 'could not fetch ' + printable(remote) + ' (' + printable(fetched.error) + ')');
|
|
512
|
+
out.detail('so repown still can\'t tell which of these commits ' + printable(remote) + ' already has');
|
|
513
|
+
return 0;
|
|
446
514
|
}
|
|
447
515
|
/** push.autoSetupRemote, in this clone only, and only when it does not already say true. */
|
|
448
516
|
async function setAutoUpstream(git) {
|