@sous-io/sous 0.2.18 → 0.2.19
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/docs/markdown/_sidebar.md +1 -0
- package/docs/markdown/commands.md +28 -0
- package/docs/markdown/repositories-authoring.md +7 -1
- package/docs/markdown/repositories-contributing.md +145 -0
- package/package.json +1 -1
- package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
- package/src/commands/repo/contribute.ts +604 -0
- package/src/lib/repos/contribute.ts +452 -0
- package/src/lib/repos/release/changelog.ts +20 -7
- package/src/lib/repos/release/git-state.ts +16 -0
- package/src/lib/repos/release/submit-service.ts +1 -1
- package/src/utils/formatting.ts +27 -1
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { BaseCommand } from "../../base-command.js";
|
|
3
|
+
import { ConfigError } from "../../lib/errors.js";
|
|
4
|
+
import { nonInteractiveError } from "../../lib/interactive.js";
|
|
5
|
+
import {
|
|
6
|
+
SousScope,
|
|
7
|
+
findReference,
|
|
8
|
+
pickReference,
|
|
9
|
+
referenceReposFromIndexes,
|
|
10
|
+
type ReferenceRepo,
|
|
11
|
+
} from "../../lib/refs/index.js";
|
|
12
|
+
import {
|
|
13
|
+
assessPendingWork,
|
|
14
|
+
assessProposal,
|
|
15
|
+
commandLine,
|
|
16
|
+
pendingWork,
|
|
17
|
+
startStep,
|
|
18
|
+
submitStep,
|
|
19
|
+
unlinkStep,
|
|
20
|
+
type ContributionStep,
|
|
21
|
+
type FinishFlags,
|
|
22
|
+
type LocatorFlags,
|
|
23
|
+
type PendingVerdict,
|
|
24
|
+
type PendingWork,
|
|
25
|
+
} from "../../lib/repos/contribute.js";
|
|
26
|
+
import { currentBranch, isGitCheckout } from "../../lib/repos/git-clone.js";
|
|
27
|
+
import { readGlobalLinks, readProjectLinks } from "../../lib/repos/links.js";
|
|
28
|
+
import type { RepoLink } from "../../lib/repos/formats/links-map.js";
|
|
29
|
+
import { submitRepo } from "../../lib/repos/release/submit-service.js";
|
|
30
|
+
import { subscriptionServiceFor } from "../../lib/repos/subscription-service.js";
|
|
31
|
+
import { isExitSignal } from "../../utils/command-errors.js";
|
|
32
|
+
import { confirmationFlag } from "../../utils/flags.js";
|
|
33
|
+
import {
|
|
34
|
+
BULLET,
|
|
35
|
+
blankLine,
|
|
36
|
+
dryRunNotice,
|
|
37
|
+
footer,
|
|
38
|
+
heading,
|
|
39
|
+
log,
|
|
40
|
+
note,
|
|
41
|
+
paragraph,
|
|
42
|
+
section,
|
|
43
|
+
showCommandVars,
|
|
44
|
+
showVariables,
|
|
45
|
+
subheading,
|
|
46
|
+
withoutHeader,
|
|
47
|
+
} from "../../utils/formatting.js";
|
|
48
|
+
import { askYesNo } from "../../utils/prompts.js";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* `sous repo contribute` starts a contribution to a recipe repository in one
|
|
52
|
+
* command, and `--finish` ends it.
|
|
53
|
+
*
|
|
54
|
+
* `sous repo link` is a general tool (authoring, running a teammate's branch, a
|
|
55
|
+
* local fork, debugging), and contributing is one particular lifecycle built
|
|
56
|
+
* from it: start on a fresh branch of an up-to-date checkout, edit, propose,
|
|
57
|
+
* revise, and go back to the published versions once the change ships. This
|
|
58
|
+
* command is that lifecycle's entry point. It CHAINS the existing commands and
|
|
59
|
+
* adds no behavior they lack:
|
|
60
|
+
*
|
|
61
|
+
* - Start runs `sous repo link <repo> --latest` on a new branch.
|
|
62
|
+
* - Finish looks at what the branch holds that no proposal carries yet, asks
|
|
63
|
+
* whether to submit it (`sous repo submit`), then runs `sous repo unlink
|
|
64
|
+
* <repo> --update`.
|
|
65
|
+
*
|
|
66
|
+
* Each step runs the real command in this same process, with the flags this
|
|
67
|
+
* command was given passed through, so a step behaves exactly as it does when
|
|
68
|
+
* it is typed on its own; the step prints as it runs, and a failure lists the
|
|
69
|
+
* steps that had already completed. The reference may name a repository, or a
|
|
70
|
+
* namespace or recipe, in which case the repository that publishes it is used.
|
|
71
|
+
*/
|
|
72
|
+
export default class RepoContribute extends BaseCommand {
|
|
73
|
+
static description =
|
|
74
|
+
"Start a contribution to a recipe repository on a fresh branch, or finish one with --finish";
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The other spelling of the topic, plus the short spelling of the command.
|
|
78
|
+
* Both hidden spellings live where the other hidden alternates do, so they are
|
|
79
|
+
* typable everywhere without ever reaching a listing.
|
|
80
|
+
*/
|
|
81
|
+
static aliases = ["repos:contribute"];
|
|
82
|
+
|
|
83
|
+
static hiddenAliases = ["repo:contrib", "repos:contrib"];
|
|
84
|
+
|
|
85
|
+
static examples = [
|
|
86
|
+
"<%= config.bin %> repo contribute sous-recipes",
|
|
87
|
+
"<%= config.bin %> repo contribute workflow/task-files",
|
|
88
|
+
"<%= config.bin %> repo contribute sous-recipes --create-branch fix-a-typo",
|
|
89
|
+
'<%= config.bin %> repo contribute sous-recipes --finish --title "Fix a typo" --body "Fixes it."',
|
|
90
|
+
"<%= config.bin %> repo contribute sous-recipes --finish --no-submit --remove",
|
|
91
|
+
"<%= config.bin %> repo contribute sous-recipes --finish --dry-run",
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
static args = {
|
|
95
|
+
ref: Args.string({
|
|
96
|
+
description:
|
|
97
|
+
"The repository to contribute to, or a namespace or recipe it publishes",
|
|
98
|
+
required: true,
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
static flags = {
|
|
103
|
+
...BaseCommand.baseFlags,
|
|
104
|
+
// No default, so `dependsOn: ["finish"]` below can tell whether it was given.
|
|
105
|
+
finish: Flags.boolean({
|
|
106
|
+
description:
|
|
107
|
+
"Finish the contribution: submit what no proposal carries yet, then unlink and update the pins",
|
|
108
|
+
}),
|
|
109
|
+
branch: Flags.string({
|
|
110
|
+
description:
|
|
111
|
+
"The existing branch to work on when starting, or to submit from when finishing",
|
|
112
|
+
helpValue: "<name>",
|
|
113
|
+
exclusive: ["create-branch", "generate-branch"],
|
|
114
|
+
}),
|
|
115
|
+
"create-branch": Flags.string({
|
|
116
|
+
description: "Start the contribution on a new branch with this name",
|
|
117
|
+
helpValue: "<name>",
|
|
118
|
+
exclusive: ["branch", "generate-branch", "finish"],
|
|
119
|
+
}),
|
|
120
|
+
"generate-branch": Flags.boolean({
|
|
121
|
+
description:
|
|
122
|
+
"Start the contribution on a new branch named sous/edit-<date>-<time>, which is what happens when no branch is named",
|
|
123
|
+
exclusive: ["branch", "create-branch", "finish"],
|
|
124
|
+
}),
|
|
125
|
+
from: Flags.string({
|
|
126
|
+
description:
|
|
127
|
+
"Start the new branch from this branch instead of the repository's default branch",
|
|
128
|
+
helpValue: "<branch>",
|
|
129
|
+
exclusive: ["branch", "finish"],
|
|
130
|
+
}),
|
|
131
|
+
global: Flags.boolean({
|
|
132
|
+
description:
|
|
133
|
+
"Work with the machine-wide link, sharing one checkout, rather than this project's link",
|
|
134
|
+
default: false,
|
|
135
|
+
}),
|
|
136
|
+
submit: Flags.boolean({
|
|
137
|
+
description:
|
|
138
|
+
"Submit what no proposal carries yet without asking, or with --no-submit, finish without submitting it",
|
|
139
|
+
allowNo: true,
|
|
140
|
+
dependsOn: ["finish"],
|
|
141
|
+
}),
|
|
142
|
+
title: Flags.string({
|
|
143
|
+
description: "The proposal's title; required for a new proposal, and replaces an open one's",
|
|
144
|
+
dependsOn: ["finish"],
|
|
145
|
+
}),
|
|
146
|
+
body: Flags.string({
|
|
147
|
+
description:
|
|
148
|
+
"The proposal's description; required for a new proposal, and replaces an open one's",
|
|
149
|
+
dependsOn: ["finish"],
|
|
150
|
+
}),
|
|
151
|
+
draft: Flags.boolean({
|
|
152
|
+
description: "Open a new proposal as a draft",
|
|
153
|
+
dependsOn: ["finish"],
|
|
154
|
+
}),
|
|
155
|
+
commit: Flags.boolean({
|
|
156
|
+
description: "Commit uncommitted changes for you when submitting, after listing them and asking once",
|
|
157
|
+
dependsOn: ["finish"],
|
|
158
|
+
}),
|
|
159
|
+
remove: Flags.boolean({
|
|
160
|
+
description: "Delete the checkout as well when unlinking, when sous cloned it",
|
|
161
|
+
dependsOn: ["finish"],
|
|
162
|
+
}),
|
|
163
|
+
yes: confirmationFlag(),
|
|
164
|
+
"accept-first": Flags.boolean({
|
|
165
|
+
description: "When the reference matches several things, take the first one listed",
|
|
166
|
+
default: false,
|
|
167
|
+
}),
|
|
168
|
+
"dry-run": Flags.boolean({
|
|
169
|
+
description: "Print each step this would run without running any of them",
|
|
170
|
+
default: false,
|
|
171
|
+
}),
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
async run(): Promise<void> {
|
|
175
|
+
const { args, flags } = await this.parse(RepoContribute);
|
|
176
|
+
const finishing = flags.finish === true;
|
|
177
|
+
const dryRun = flags["dry-run"];
|
|
178
|
+
|
|
179
|
+
showCommandVars({
|
|
180
|
+
Project: this.projectLabel,
|
|
181
|
+
Reference: args.ref,
|
|
182
|
+
Mode: finishing ? "Finish a contribution" : "Start a contribution",
|
|
183
|
+
Scope: flags.global ? "this machine" : "this project",
|
|
184
|
+
"Dry Run": dryRun,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
blankLine();
|
|
188
|
+
const repo = await this.resolveRepository(args.ref, flags["accept-first"]);
|
|
189
|
+
|
|
190
|
+
// Every step discovers the project again, so it is pointed at the same one.
|
|
191
|
+
const configFlag = flags.config ?? flags["sous-config"];
|
|
192
|
+
const locator: LocatorFlags = {
|
|
193
|
+
...(configFlag === undefined ? {} : { config: configFlag }),
|
|
194
|
+
...(flags["sous-dir"] === undefined ? {} : { "sous-dir": flags["sous-dir"] }),
|
|
195
|
+
...(flags["sous-confd"] === undefined ? {} : { "sous-confd": flags["sous-confd"] }),
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
if (finishing) {
|
|
199
|
+
await this.finish(repo, {
|
|
200
|
+
...(flags.title === undefined ? {} : { title: flags.title }),
|
|
201
|
+
...(flags.body === undefined ? {} : { body: flags.body }),
|
|
202
|
+
...(flags.branch === undefined ? {} : { branch: flags.branch }),
|
|
203
|
+
draft: flags.draft === true,
|
|
204
|
+
commit: flags.commit === true,
|
|
205
|
+
remove: flags.remove === true,
|
|
206
|
+
global: flags.global,
|
|
207
|
+
yes: flags.yes,
|
|
208
|
+
}, flags.submit, locator, dryRun);
|
|
209
|
+
} else {
|
|
210
|
+
await this.start(
|
|
211
|
+
repo,
|
|
212
|
+
startStep(
|
|
213
|
+
repo,
|
|
214
|
+
{
|
|
215
|
+
...(flags.branch === undefined ? {} : { branch: flags.branch }),
|
|
216
|
+
...(flags["create-branch"] === undefined
|
|
217
|
+
? {}
|
|
218
|
+
: { createBranch: flags["create-branch"] }),
|
|
219
|
+
generateBranch: flags["generate-branch"] === true,
|
|
220
|
+
...(flags.from === undefined ? {} : { from: flags.from }),
|
|
221
|
+
global: flags.global,
|
|
222
|
+
yes: flags.yes,
|
|
223
|
+
},
|
|
224
|
+
locator
|
|
225
|
+
),
|
|
226
|
+
flags.global,
|
|
227
|
+
dryRun
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
footer();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Starts a contribution: one step, the link.
|
|
236
|
+
*
|
|
237
|
+
* @param repo - The repository's short name.
|
|
238
|
+
* @param step - The link step.
|
|
239
|
+
* @param isGlobal - Whether the link is the machine-wide one.
|
|
240
|
+
* @param dryRun - When true, the step is printed and not run.
|
|
241
|
+
*/
|
|
242
|
+
private async start(
|
|
243
|
+
repo: string,
|
|
244
|
+
step: ContributionStep,
|
|
245
|
+
isGlobal: boolean,
|
|
246
|
+
dryRun: boolean
|
|
247
|
+
): Promise<void> {
|
|
248
|
+
section("Starting a contribution");
|
|
249
|
+
this.printPlan([step]);
|
|
250
|
+
|
|
251
|
+
if (dryRun) {
|
|
252
|
+
blankLine();
|
|
253
|
+
dryRunNotice("no step was run");
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const completed: string[] = [];
|
|
258
|
+
await this.runStep(step, completed);
|
|
259
|
+
|
|
260
|
+
section("The contribution");
|
|
261
|
+
const link = this.linkMap(isGlobal).links[repo];
|
|
262
|
+
const branch =
|
|
263
|
+
link !== undefined && isGitCheckout(link.path) ? currentBranch(link.path) : undefined;
|
|
264
|
+
showVariables({
|
|
265
|
+
Repository: repo,
|
|
266
|
+
...(link === undefined ? {} : { Checkout: link.path }),
|
|
267
|
+
...(branch === undefined ? {} : { Branch: branch }),
|
|
268
|
+
});
|
|
269
|
+
blankLine();
|
|
270
|
+
paragraph(
|
|
271
|
+
`Builds read '${repo}' from this checkout until the contribution is finished, so an ` +
|
|
272
|
+
`edit made there shows up in this project's next build.`
|
|
273
|
+
);
|
|
274
|
+
this.printCompleted(completed);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Finishes a contribution: works out whether the branch holds anything no
|
|
279
|
+
* proposal carries yet, submits it when the contributor says so, then
|
|
280
|
+
* unlinks the repository and updates its pins.
|
|
281
|
+
*
|
|
282
|
+
* @param repo - The repository's short name.
|
|
283
|
+
* @param flags - The finish flags, passed through.
|
|
284
|
+
* @param submitFlag - `--submit` (true), `--no-submit` (false), or neither.
|
|
285
|
+
* @param locator - The config-locating flags, passed through.
|
|
286
|
+
* @param dryRun - When true, the steps are printed and none is run.
|
|
287
|
+
*/
|
|
288
|
+
private async finish(
|
|
289
|
+
repo: string,
|
|
290
|
+
flags: FinishFlags,
|
|
291
|
+
submitFlag: boolean | undefined,
|
|
292
|
+
locator: LocatorFlags,
|
|
293
|
+
dryRun: boolean
|
|
294
|
+
): Promise<void> {
|
|
295
|
+
const isGlobal = flags.global === true;
|
|
296
|
+
const link = this.requireLink(repo, isGlobal);
|
|
297
|
+
|
|
298
|
+
section("Finishing a contribution");
|
|
299
|
+
showVariables({ Repository: repo, Checkout: link.path });
|
|
300
|
+
|
|
301
|
+
const completed: string[] = [];
|
|
302
|
+
|
|
303
|
+
subheading("Looking for work no proposal carries yet");
|
|
304
|
+
blankLine();
|
|
305
|
+
const work = pendingWork(link.path, flags.branch);
|
|
306
|
+
this.printPendingWork(work);
|
|
307
|
+
|
|
308
|
+
let verdict = assessPendingWork(work);
|
|
309
|
+
if (verdict.kind === "lookup" && !dryRun) {
|
|
310
|
+
paragraph(verdict.reason);
|
|
311
|
+
blankLine();
|
|
312
|
+
verdict = await this.lookUpProposal(link.path, work.branch!);
|
|
313
|
+
blankLine();
|
|
314
|
+
}
|
|
315
|
+
paragraph(verdict.reason);
|
|
316
|
+
completed.push("Looked for work no proposal carries yet");
|
|
317
|
+
|
|
318
|
+
const unlink = unlinkStep(repo, flags, locator);
|
|
319
|
+
const submit = submitStep(repo, flags);
|
|
320
|
+
|
|
321
|
+
if (dryRun) {
|
|
322
|
+
blankLine();
|
|
323
|
+
if (verdict.kind === "nothing") {
|
|
324
|
+
dryRunNotice("would skip submitting, since there is nothing to submit");
|
|
325
|
+
blankLine();
|
|
326
|
+
this.printPlan([unlink]);
|
|
327
|
+
} else {
|
|
328
|
+
if (verdict.kind === "lookup") {
|
|
329
|
+
dryRunNotice(
|
|
330
|
+
"would look the branch's proposal up, and treat the branch as having work to " +
|
|
331
|
+
"submit when none is open"
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
dryRunNotice(this.describeSubmitDecision(submitFlag, flags.yes === true));
|
|
335
|
+
blankLine();
|
|
336
|
+
this.printPlan(submitFlag === false ? [unlink] : [submit, unlink]);
|
|
337
|
+
}
|
|
338
|
+
blankLine();
|
|
339
|
+
dryRunNotice("no step was run");
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const steps: ContributionStep[] = [];
|
|
344
|
+
if (verdict.kind !== "nothing" && (await this.shouldSubmit(submitFlag, flags.yes === true))) {
|
|
345
|
+
steps.push(submit);
|
|
346
|
+
} else if (verdict.kind !== "nothing") {
|
|
347
|
+
blankLine();
|
|
348
|
+
paragraph("It is not submitted; the checkout keeps it.");
|
|
349
|
+
}
|
|
350
|
+
steps.push(unlink);
|
|
351
|
+
|
|
352
|
+
blankLine();
|
|
353
|
+
this.printPlan(steps);
|
|
354
|
+
for (const step of steps) await this.runStep(step, completed);
|
|
355
|
+
|
|
356
|
+
this.printCompleted(completed);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// --- Resolving the reference ------------------------------------------------------------------
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* The repository a reference names: the repository itself, or the one that
|
|
363
|
+
* publishes a namespace or recipe. Resolved through the shared reference
|
|
364
|
+
* module over every repository this project trusts; a repository whose index
|
|
365
|
+
* has never been fetched can still be named, just not searched inside.
|
|
366
|
+
*
|
|
367
|
+
* @param ref - The reference as it was written.
|
|
368
|
+
* @param acceptFirst - The `--accept-first` flag.
|
|
369
|
+
*/
|
|
370
|
+
private async resolveRepository(ref: string, acceptFirst: boolean): Promise<string> {
|
|
371
|
+
const service = subscriptionServiceFor({
|
|
372
|
+
configContext: this.configContext,
|
|
373
|
+
settings: this.settings,
|
|
374
|
+
shellEnv: this.shellEnv,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
const trusted = service.currentRepos();
|
|
378
|
+
const repos: ReferenceRepo[] = Object.keys(trusted).map((name) => {
|
|
379
|
+
const url = trusted[name]?.url;
|
|
380
|
+
const index = service.cachedIndex(name);
|
|
381
|
+
if (index === undefined) {
|
|
382
|
+
return { name, ...(url === undefined ? {} : { url }), namespaces: [], recipes: [] };
|
|
383
|
+
}
|
|
384
|
+
return referenceReposFromIndexes([name], new Map([[name, index]]), { [name]: url })[0]!;
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
const matches = findReference(
|
|
388
|
+
ref,
|
|
389
|
+
[SousScope.Repository, SousScope.Namespace, SousScope.Recipe],
|
|
390
|
+
{ repos }
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
const chosen = await pickReference(matches, {
|
|
394
|
+
search: ref,
|
|
395
|
+
interactive: this.interactive,
|
|
396
|
+
acceptFirst,
|
|
397
|
+
prompt: `Which '${ref}' do you want to contribute to?`,
|
|
398
|
+
details: [
|
|
399
|
+
" No trusted repository, namespace or recipe has that name.",
|
|
400
|
+
repos.length === 0
|
|
401
|
+
? " This project trusts no repositories."
|
|
402
|
+
: ` This project trusts: ${repos.map((entry) => entry.name).join(", ")}.`,
|
|
403
|
+
],
|
|
404
|
+
});
|
|
405
|
+
return chosen.repo ?? chosen.key;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// --- The link ---------------------------------------------------------------------------------
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* The links map a scope reads.
|
|
412
|
+
*
|
|
413
|
+
* @param isGlobal - Whether it is the machine-wide map.
|
|
414
|
+
*/
|
|
415
|
+
private linkMap(isGlobal: boolean) {
|
|
416
|
+
return isGlobal ? readGlobalLinks() : readProjectLinks(this.configContext.sousDir);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* The link a contribution being finished runs on, or a ConfigError saying it
|
|
421
|
+
* is not linked in the scope asked about (and where it is linked instead,
|
|
422
|
+
* when it is linked in the other one).
|
|
423
|
+
*
|
|
424
|
+
* @param repo - The repository's short name.
|
|
425
|
+
* @param isGlobal - Whether the machine-wide link was asked about.
|
|
426
|
+
*/
|
|
427
|
+
private requireLink(repo: string, isGlobal: boolean): RepoLink {
|
|
428
|
+
const link = this.linkMap(isGlobal).links[repo];
|
|
429
|
+
if (link !== undefined) return link;
|
|
430
|
+
|
|
431
|
+
const other = this.linkMap(!isGlobal).links[repo];
|
|
432
|
+
const searched = isGlobal ? "the machine-wide links map" : "this project's links map";
|
|
433
|
+
throw new ConfigError(
|
|
434
|
+
`'${repo}' is not linked in ${searched}, so there is no contribution to finish.\n` +
|
|
435
|
+
(other === undefined
|
|
436
|
+
? ` Nothing was changed.`
|
|
437
|
+
: ` It is linked in the ${isGlobal ? "project" : "machine-wide"} map, at ` +
|
|
438
|
+
`${other.path}; run the same command ${isGlobal ? "without" : "with"} --global ` +
|
|
439
|
+
`to finish that one.`)
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// --- Deciding whether to submit ---------------------------------------------------------------
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Looks the branch's proposal up, to judge a branch whose every commit was
|
|
447
|
+
* pushed. A lookup that fails leaves the question open, which counts as work
|
|
448
|
+
* to submit: the contributor is asked, and sous says why it could not tell.
|
|
449
|
+
*
|
|
450
|
+
* @param directory - The checkout.
|
|
451
|
+
* @param branch - The branch.
|
|
452
|
+
*/
|
|
453
|
+
private async lookUpProposal(directory: string, branch: string): Promise<PendingVerdict> {
|
|
454
|
+
try {
|
|
455
|
+
const result = await submitRepo({
|
|
456
|
+
rootDir: directory,
|
|
457
|
+
branch,
|
|
458
|
+
statusOnly: true,
|
|
459
|
+
onStep: (message) => log(` ${message}`),
|
|
460
|
+
onNotice: (message) => note(message),
|
|
461
|
+
});
|
|
462
|
+
return assessProposal(branch, result.previous, result.proposalNoun);
|
|
463
|
+
} catch (error) {
|
|
464
|
+
const reason = (error instanceof Error ? error.message : String(error)).split("\n")[0]!;
|
|
465
|
+
return {
|
|
466
|
+
kind: "pending",
|
|
467
|
+
reason:
|
|
468
|
+
`Every commit on the branch '${branch}' was pushed, but sous could not look its ` +
|
|
469
|
+
`proposal up, so it cannot tell whether one is open. ${reason.trim()}`,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Whether to submit the work found: `--no-submit` says no, `--submit` or the
|
|
476
|
+
* confirmation flag say yes, and otherwise the contributor is asked. A run
|
|
477
|
+
* that cannot ask fails, naming the flags that answer the question.
|
|
478
|
+
*
|
|
479
|
+
* @param submitFlag - `--submit` (true), `--no-submit` (false), or neither.
|
|
480
|
+
* @param yes - The confirmation flag.
|
|
481
|
+
*/
|
|
482
|
+
private async shouldSubmit(submitFlag: boolean | undefined, yes: boolean): Promise<boolean> {
|
|
483
|
+
if (submitFlag !== undefined) return submitFlag;
|
|
484
|
+
if (yes) return true;
|
|
485
|
+
|
|
486
|
+
if (!this.interactive) {
|
|
487
|
+
throw nonInteractiveError({
|
|
488
|
+
prompt: "whether to submit the work above before finishing",
|
|
489
|
+
remedy:
|
|
490
|
+
"pass '--submit' (or '--yes') to submit it, or '--no-submit' to finish without " +
|
|
491
|
+
"submitting it.",
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
return askYesNo("Submit it before finishing?", true);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* What a dry run says about the submit question.
|
|
499
|
+
*
|
|
500
|
+
* @param submitFlag - `--submit` (true), `--no-submit` (false), or neither.
|
|
501
|
+
* @param yes - The confirmation flag.
|
|
502
|
+
*/
|
|
503
|
+
private describeSubmitDecision(submitFlag: boolean | undefined, yes: boolean): string {
|
|
504
|
+
if (submitFlag === false) return "would not submit it, because --no-submit was passed";
|
|
505
|
+
if (submitFlag === true) return "would submit it without asking, because --submit was passed";
|
|
506
|
+
if (yes) return "would submit it without asking, because --yes was passed";
|
|
507
|
+
return "would ask whether to submit it";
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// --- Running the steps ------------------------------------------------------------------------
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Runs one step: the real command, in this process, without a second banner.
|
|
514
|
+
* The command reports its own failure; this adds which steps had completed
|
|
515
|
+
* before it, then ends the run with the command's exit code.
|
|
516
|
+
*
|
|
517
|
+
* @param step - The step to run.
|
|
518
|
+
* @param completed - The steps completed so far; this one is added when it succeeds.
|
|
519
|
+
*/
|
|
520
|
+
private async runStep(step: ContributionStep, completed: string[]): Promise<void> {
|
|
521
|
+
heading(step.running);
|
|
522
|
+
note(commandLine(step), { indent: 2 });
|
|
523
|
+
|
|
524
|
+
try {
|
|
525
|
+
await withoutHeader(() => this.config.runCommand(step.command, step.argv));
|
|
526
|
+
} catch (error) {
|
|
527
|
+
if (isExitSignal(error)) {
|
|
528
|
+
// The command has already said what went wrong.
|
|
529
|
+
this.printStopped(step, completed);
|
|
530
|
+
throw error;
|
|
531
|
+
}
|
|
532
|
+
throw new ConfigError(
|
|
533
|
+
`${step.running}: this step failed.\n\n` +
|
|
534
|
+
` ${error instanceof Error ? error.message : String(error)}\n\n` +
|
|
535
|
+
` What had already been done:\n` +
|
|
536
|
+
(completed.length === 0
|
|
537
|
+
? " nothing"
|
|
538
|
+
: completed.map((entry) => ` ${entry}`).join("\n"))
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
completed.push(step.done);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* The steps about to run, as the command lines that run them.
|
|
547
|
+
*
|
|
548
|
+
* @param steps - The steps.
|
|
549
|
+
*/
|
|
550
|
+
private printPlan(steps: ContributionStep[]): void {
|
|
551
|
+
paragraph(steps.length === 1 ? "This runs one step:" : `This runs ${steps.length} steps:`);
|
|
552
|
+
blankLine();
|
|
553
|
+
for (const step of steps) {
|
|
554
|
+
paragraph(`${BULLET} ${commandLine(step)}`, { indent: 4, hangingIndent: 2 });
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* What the branch holds, as a key and value list.
|
|
560
|
+
*
|
|
561
|
+
* @param work - What `pendingWork` found.
|
|
562
|
+
*/
|
|
563
|
+
private printPendingWork(work: PendingWork): void {
|
|
564
|
+
const base = work.baseBranch === undefined ? "upstream" : `origin/${work.baseBranch}`;
|
|
565
|
+
showVariables({
|
|
566
|
+
Branch: work.branch ?? "(none; HEAD is detached)",
|
|
567
|
+
"Uncommitted changes": work.uncommitted.length,
|
|
568
|
+
[`Commits ${base} lacks`]: work.ahead.length,
|
|
569
|
+
"Commits not pushed": work.unpushed.length,
|
|
570
|
+
"Pushed to": work.pushedCopies.length === 0 ? "nowhere yet" : work.pushedCopies.join(", "),
|
|
571
|
+
});
|
|
572
|
+
blankLine();
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* The steps that completed, after the run finished.
|
|
577
|
+
*
|
|
578
|
+
* @param completed - The steps, in order.
|
|
579
|
+
*/
|
|
580
|
+
private printCompleted(completed: string[]): void {
|
|
581
|
+
section("What this run did");
|
|
582
|
+
for (const entry of completed) paragraph(`${BULLET} ${entry}`, { indent: 4, hangingIndent: 2 });
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* After a step failed: which step it was, and which had completed before it.
|
|
587
|
+
*
|
|
588
|
+
* @param step - The step that failed.
|
|
589
|
+
* @param completed - The steps completed before it.
|
|
590
|
+
*/
|
|
591
|
+
private printStopped(step: ContributionStep, completed: string[]): void {
|
|
592
|
+
section("The contribution stopped");
|
|
593
|
+
showVariables({ "Failed step": step.running });
|
|
594
|
+
blankLine();
|
|
595
|
+
if (completed.length === 0) {
|
|
596
|
+
paragraph("No step had completed before it, and no later step ran.");
|
|
597
|
+
} else {
|
|
598
|
+
paragraph("These steps had completed before it, and no later step ran:");
|
|
599
|
+
blankLine();
|
|
600
|
+
for (const entry of completed) paragraph(`${BULLET} ${entry}`, { indent: 4, hangingIndent: 2 });
|
|
601
|
+
}
|
|
602
|
+
footer();
|
|
603
|
+
}
|
|
604
|
+
}
|