@sous-io/sous 0.2.36 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +14 -256
  2. package/dist/bin.js +11 -0
  3. package/dist/sous.js +1093 -0
  4. package/docs/markdown/README.md +5 -4
  5. package/docs/markdown/_sidebar.md +21 -1
  6. package/docs/markdown/commands.md +294 -431
  7. package/docs/markdown/config-discovery.md +25 -14
  8. package/docs/markdown/config-inspection.md +53 -31
  9. package/docs/markdown/config-layers.md +168 -66
  10. package/docs/markdown/config-variables.md +44 -11
  11. package/docs/markdown/configuration.md +104 -17
  12. package/docs/markdown/design-principles.md +4 -1
  13. package/docs/markdown/repositories-authoring.md +30 -0
  14. package/docs/markdown/repositories-consuming.md +72 -14
  15. package/docs/markdown/repositories-file-formats.md +31 -13
  16. package/docs/markdown/repositories-providers.md +48 -57
  17. package/docs/markdown/repositories-quickstart.md +3 -2
  18. package/docs/markdown/repositories-troubleshooting.md +27 -1
  19. package/docs/markdown/repositories-variables.md +6 -1
  20. package/docs/markdown/repositories.md +18 -8
  21. package/package.json +48 -107
  22. package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +4 -6
  23. package/recipes/core/sous-skills/skills/about-liquid-templates/references/liquid-filters.tpl.md +2 -0
  24. package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +10 -9
  25. package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +35 -14
  26. package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +51 -20
  27. package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
  28. package/sous.config.schema.json +351 -132
  29. package/bin/run.js +0 -51
  30. package/src/base-command.ts +0 -457
  31. package/src/commands/build.ts +0 -181
  32. package/src/commands/clear.ts +0 -79
  33. package/src/commands/compile.ts +0 -155
  34. package/src/commands/config/get.ts +0 -110
  35. package/src/commands/config/show.ts +0 -32
  36. package/src/commands/config/validate.ts +0 -53
  37. package/src/commands/help.ts +0 -46
  38. package/src/commands/init.ts +0 -289
  39. package/src/commands/launch.ts +0 -139
  40. package/src/commands/lock/rebuild.ts +0 -239
  41. package/src/commands/lock/show.ts +0 -115
  42. package/src/commands/namespace/list.ts +0 -138
  43. package/src/commands/namespace/show.ts +0 -130
  44. package/src/commands/prune.ts +0 -43
  45. package/src/commands/recipe/list.ts +0 -112
  46. package/src/commands/recipe/show.ts +0 -439
  47. package/src/commands/repo/add.ts +0 -145
  48. package/src/commands/repo/contribute.ts +0 -604
  49. package/src/commands/repo/gc.ts +0 -173
  50. package/src/commands/repo/init.ts +0 -136
  51. package/src/commands/repo/link.ts +0 -899
  52. package/src/commands/repo/list.ts +0 -236
  53. package/src/commands/repo/release.ts +0 -685
  54. package/src/commands/repo/remove.ts +0 -194
  55. package/src/commands/repo/search.ts +0 -243
  56. package/src/commands/repo/submit.ts +0 -341
  57. package/src/commands/repo/unlink.ts +0 -461
  58. package/src/commands/subscription/add.ts +0 -286
  59. package/src/commands/subscription/list.ts +0 -208
  60. package/src/commands/subscription/remove.ts +0 -182
  61. package/src/commands/subscription/update.ts +0 -216
  62. package/src/commands/update.ts +0 -178
  63. package/src/commands/vars/ask.ts +0 -417
  64. package/src/commands/vars/index.ts +0 -79
  65. package/src/commands/vars/list.ts +0 -67
  66. package/src/commands/vars/show.ts +0 -77
  67. package/src/config-command.ts +0 -30
  68. package/src/lib/build-preparation.ts +0 -128
  69. package/src/lib/build-service.ts +0 -580
  70. package/src/lib/config-discovery.ts +0 -378
  71. package/src/lib/config-inspect.ts +0 -145
  72. package/src/lib/config-kernel.mjs +0 -379
  73. package/src/lib/config-schema.ts +0 -401
  74. package/src/lib/env-file.ts +0 -328
  75. package/src/lib/env-local.ts +0 -212
  76. package/src/lib/errors.ts +0 -32
  77. package/src/lib/glob-pattern.ts +0 -24
  78. package/src/lib/include-resolver.ts +0 -523
  79. package/src/lib/interactive.ts +0 -165
  80. package/src/lib/markdown-compiler.ts +0 -947
  81. package/src/lib/package-info.ts +0 -25
  82. package/src/lib/pid-service.ts +0 -99
  83. package/src/lib/project-install.d.mts +0 -44
  84. package/src/lib/project-install.mjs +0 -234
  85. package/src/lib/project-scaffold/index.ts +0 -332
  86. package/src/lib/project-scaffold/templates.ts +0 -240
  87. package/src/lib/repos/catalog-display.ts +0 -215
  88. package/src/lib/repos/catalog-inputs.ts +0 -288
  89. package/src/lib/repos/catalog.ts +0 -842
  90. package/src/lib/repos/contribute.ts +0 -452
  91. package/src/lib/repos/core-recipe.ts +0 -105
  92. package/src/lib/repos/declarations.ts +0 -187
  93. package/src/lib/repos/defaults.ts +0 -175
  94. package/src/lib/repos/formats/common.ts +0 -440
  95. package/src/lib/repos/formats/index-file.ts +0 -253
  96. package/src/lib/repos/formats/links-map.ts +0 -98
  97. package/src/lib/repos/formats/lockfile.ts +0 -169
  98. package/src/lib/repos/formats/patterns.ts +0 -57
  99. package/src/lib/repos/formats/recipe-manifest.ts +0 -205
  100. package/src/lib/repos/formats/repo-manifest.ts +0 -97
  101. package/src/lib/repos/formats/store-entry.ts +0 -84
  102. package/src/lib/repos/formats/variable-definition.ts +0 -268
  103. package/src/lib/repos/freshness.ts +0 -264
  104. package/src/lib/repos/git-clone.ts +0 -850
  105. package/src/lib/repos/identity.ts +0 -89
  106. package/src/lib/repos/index.ts +0 -57
  107. package/src/lib/repos/links.ts +0 -356
  108. package/src/lib/repos/load-manifest.ts +0 -237
  109. package/src/lib/repos/lock-service.ts +0 -454
  110. package/src/lib/repos/locked-namespace-resolver.ts +0 -232
  111. package/src/lib/repos/locked-recipe-lookup.ts +0 -123
  112. package/src/lib/repos/locked-recipes.ts +0 -254
  113. package/src/lib/repos/managed-layer.ts +0 -422
  114. package/src/lib/repos/memories-hash-name.ts +0 -33
  115. package/src/lib/repos/namespace-resolver.ts +0 -527
  116. package/src/lib/repos/providers/base.ts +0 -268
  117. package/src/lib/repos/providers/git.ts +0 -237
  118. package/src/lib/repos/providers/github.ts +0 -589
  119. package/src/lib/repos/providers/gitlab.ts +0 -332
  120. package/src/lib/repos/providers/http.ts +0 -128
  121. package/src/lib/repos/providers/index-cache.ts +0 -421
  122. package/src/lib/repos/providers/index.ts +0 -106
  123. package/src/lib/repos/providers/local.ts +0 -391
  124. package/src/lib/repos/providers/provider.ts +0 -615
  125. package/src/lib/repos/recipe-config-layers.ts +0 -316
  126. package/src/lib/repos/recipe-key-matcher.ts +0 -62
  127. package/src/lib/repos/recipe-memories.ts +0 -178
  128. package/src/lib/repos/recipe-targets.ts +0 -236
  129. package/src/lib/repos/ref-search.ts +0 -46
  130. package/src/lib/repos/release/bump.ts +0 -161
  131. package/src/lib/repos/release/changelog.ts +0 -461
  132. package/src/lib/repos/release/git-state.ts +0 -460
  133. package/src/lib/repos/release/index-builder.ts +0 -1108
  134. package/src/lib/repos/release/index.ts +0 -19
  135. package/src/lib/repos/release/plan.ts +0 -521
  136. package/src/lib/repos/release/settle.ts +0 -154
  137. package/src/lib/repos/release/submissions.ts +0 -214
  138. package/src/lib/repos/release/submit-checkout.ts +0 -290
  139. package/src/lib/repos/release/submit-questions.ts +0 -153
  140. package/src/lib/repos/release/submit-service.ts +0 -898
  141. package/src/lib/repos/release/tags.ts +0 -239
  142. package/src/lib/repos/release/validate.ts +0 -463
  143. package/src/lib/repos/resolver.ts +0 -1028
  144. package/src/lib/repos/scaffold/index.ts +0 -245
  145. package/src/lib/repos/scaffold/templates.ts +0 -517
  146. package/src/lib/repos/seed.ts +0 -473
  147. package/src/lib/repos/store/contract.ts +0 -64
  148. package/src/lib/repos/store/hash.ts +0 -191
  149. package/src/lib/repos/store/recipe-store.ts +0 -599
  150. package/src/lib/repos/store/settings.ts +0 -58
  151. package/src/lib/repos/subscription-service.ts +0 -3859
  152. package/src/lib/repos/trust.ts +0 -447
  153. package/src/lib/repos/update-plan.ts +0 -235
  154. package/src/lib/self-update/index.ts +0 -14
  155. package/src/lib/self-update/installs.ts +0 -412
  156. package/src/lib/self-update/managers.ts +0 -126
  157. package/src/lib/self-update/plan.ts +0 -315
  158. package/src/lib/self-update/registry.ts +0 -99
  159. package/src/lib/self-update/run.ts +0 -506
  160. package/src/lib/self-update/versions.ts +0 -243
  161. package/src/lib/settings.ts +0 -1105
  162. package/src/lib/sous-home.ts +0 -104
  163. package/src/lib/state.ts +0 -167
  164. package/src/lib/vars/answers.ts +0 -192
  165. package/src/lib/vars/ask.ts +0 -1152
  166. package/src/lib/vars/definition-source.ts +0 -261
  167. package/src/lib/vars/display.ts +0 -231
  168. package/src/lib/vars/index.ts +0 -20
  169. package/src/lib/vars/ladder.ts +0 -282
  170. package/src/lib/vars/mappings.ts +0 -260
  171. package/src/lib/vars/names.ts +0 -94
  172. package/src/lib/vars/preanswers.ts +0 -395
  173. package/src/lib/vars/question-plan.ts +0 -241
  174. package/src/lib/vars/report.ts +0 -228
  175. package/src/lib/vars/safe-regex.ts +0 -235
  176. package/src/lib/vars/secrets.ts +0 -131
  177. package/src/lib/vars/validate.ts +0 -312
  178. package/src/lib/version-report.ts +0 -90
  179. package/src/lib/watch-loop.ts +0 -148
  180. package/src/lib/watch-service.ts +0 -116
  181. package/src/services/ref-resolver/container.ts +0 -107
  182. package/src/services/ref-resolver/dependency.ts +0 -60
  183. package/src/services/ref-resolver/format.ts +0 -197
  184. package/src/services/ref-resolver/glob.ts +0 -115
  185. package/src/services/ref-resolver/hash-names.ts +0 -155
  186. package/src/services/ref-resolver/index.ts +0 -55
  187. package/src/services/ref-resolver/injectable.ts +0 -36
  188. package/src/services/ref-resolver/location.ts +0 -62
  189. package/src/services/ref-resolver/lookups/cached-index-lookup.ts +0 -53
  190. package/src/services/ref-resolver/lookups/catalog-lookup.ts +0 -23
  191. package/src/services/ref-resolver/lookups/catalog-matcher.ts +0 -261
  192. package/src/services/ref-resolver/lookups/chained-lookup.ts +0 -27
  193. package/src/services/ref-resolver/lookups/env-var-lookup.ts +0 -65
  194. package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +0 -150
  195. package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +0 -62
  196. package/src/services/ref-resolver/lookups/ref-lookup.ts +0 -54
  197. package/src/services/ref-resolver/lookups/variable-lookup.ts +0 -123
  198. package/src/services/ref-resolver/named-refs.ts +0 -144
  199. package/src/services/ref-resolver/parser/env-var-splitter.ts +0 -27
  200. package/src/services/ref-resolver/parser/location-splitter.ts +0 -239
  201. package/src/services/ref-resolver/parser/name-path-splitter.ts +0 -200
  202. package/src/services/ref-resolver/parser/partial-ref.ts +0 -84
  203. package/src/services/ref-resolver/parser/query-splitter.ts +0 -61
  204. package/src/services/ref-resolver/parser/range-splitter.ts +0 -52
  205. package/src/services/ref-resolver/parser/ref-parser.ts +0 -115
  206. package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +0 -51
  207. package/src/services/ref-resolver/parts.ts +0 -115
  208. package/src/services/ref-resolver/pruners/command-line-pruner.ts +0 -47
  209. package/src/services/ref-resolver/pruners/include-pruner.ts +0 -66
  210. package/src/services/ref-resolver/pruners/manifest-pruner.ts +0 -130
  211. package/src/services/ref-resolver/pruners/ref-pruner.ts +0 -135
  212. package/src/services/ref-resolver/pruners/rule-helpers.ts +0 -44
  213. package/src/services/ref-resolver/pruners/stored-key-pruner.ts +0 -136
  214. package/src/services/ref-resolver/ref-helpers.ts +0 -62
  215. package/src/services/ref-resolver/ref-picker-service.ts +0 -204
  216. package/src/services/ref-resolver/ref-report.ts +0 -84
  217. package/src/services/ref-resolver/ref-resolve-arguments.ts +0 -47
  218. package/src/services/ref-resolver/ref-resolve-result.ts +0 -36
  219. package/src/services/ref-resolver/ref-resolver-service.ts +0 -323
  220. package/src/services/ref-resolver/source.ts +0 -48
  221. package/src/services/ref-resolver/tokens.ts +0 -25
  222. package/src/services/ref-resolver/types.ts +0 -155
  223. package/src/templating/filters/bullet-list.ts +0 -9
  224. package/src/templating/filters/index.ts +0 -8
  225. package/src/templating/init-liquid-engine.ts +0 -139
  226. package/src/templating/lib/glob-files.ts +0 -74
  227. package/src/templating/lib/import-export.ts +0 -32
  228. package/src/templating/lib/secret-scope.ts +0 -41
  229. package/src/templating/lib/tag-args.ts +0 -19
  230. package/src/templating/tags/exportScalarVarsJs.ts +0 -46
  231. package/src/templating/tags/getFiles.ts +0 -89
  232. package/src/templating/tags/index.ts +0 -14
  233. package/src/templating/tags/listFiles.ts +0 -54
  234. package/src/templating/tags/showVars.ts +0 -28
  235. package/src/utils/choice-prompt.ts +0 -143
  236. package/src/utils/command-errors.ts +0 -186
  237. package/src/utils/command-help.ts +0 -45
  238. package/src/utils/confirm-prompt.ts +0 -110
  239. package/src/utils/flags.ts +0 -177
  240. package/src/utils/formatting.ts +0 -849
  241. package/src/utils/prompts.ts +0 -53
  242. package/src/utils/sous-directory.ts +0 -245
  243. package/src/utils/table.ts +0 -603
  244. package/src/utils/value-prompt.ts +0 -119
@@ -1,604 +0,0 @@
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
- CatalogLookup,
7
- RefPickArguments,
8
- RefResolveArguments,
9
- repoOf,
10
- sharedRefPicker,
11
- sharedRefResolver,
12
- type CatalogRepo,
13
- } from "../../services/ref-resolver/index.js";
14
- import {
15
- assessPendingWork,
16
- assessProposal,
17
- commandLine,
18
- pendingWork,
19
- startStep,
20
- submitStep,
21
- unlinkStep,
22
- type ContributionStep,
23
- type FinishFlags,
24
- type LocatorFlags,
25
- type PendingVerdict,
26
- type PendingWork,
27
- } from "../../lib/repos/contribute.js";
28
- import { currentBranch, isGitCheckout } from "../../lib/repos/git-clone.js";
29
- import { readGlobalLinks, readProjectLinks } from "../../lib/repos/links.js";
30
- import type { RepoLink } from "../../lib/repos/formats/links-map.js";
31
- import { submitRepo } from "../../lib/repos/release/submit-service.js";
32
- import { subscriptionServiceFor } from "../../lib/repos/subscription-service.js";
33
- import { isExitSignal } from "../../utils/command-errors.js";
34
- import { confirmationFlag } from "../../utils/flags.js";
35
- import {
36
- BULLET,
37
- blankLine,
38
- dryRunNotice,
39
- footer,
40
- heading,
41
- log,
42
- note,
43
- paragraph,
44
- section,
45
- showCommandVars,
46
- showVariables,
47
- subheading,
48
- withoutHeader,
49
- } from "../../utils/formatting.js";
50
- import { askYesNo } from "../../utils/prompts.js";
51
-
52
- /**
53
- * `sous repo contribute` starts a contribution to a recipe repository in one
54
- * command, and `--finish` ends it.
55
- *
56
- * `sous repo link` is a general tool (authoring, running a teammate's branch, a
57
- * local fork, debugging), and contributing is one particular lifecycle built
58
- * from it: start on a fresh branch of an up-to-date checkout, edit, propose,
59
- * revise, and go back to the published versions once the change ships. This
60
- * command is that lifecycle's entry point. It CHAINS the existing commands and
61
- * adds no behavior they lack:
62
- *
63
- * - Start runs `sous repo link <repo> --latest` on a new branch.
64
- * - Finish looks at what the branch holds that no proposal carries yet, asks
65
- * whether to submit it (`sous repo submit`), then runs `sous repo unlink
66
- * <repo> --update`.
67
- *
68
- * Each step runs the real command in this same process, with the flags this
69
- * command was given passed through, so a step behaves exactly as it does when
70
- * it is typed on its own; the step prints as it runs, and a failure lists the
71
- * steps that had already completed. The reference may name a repository, or a
72
- * namespace or recipe, in which case the repository that publishes it is used.
73
- */
74
- export default class RepoContribute extends BaseCommand {
75
- static description =
76
- "Start a contribution to a recipe repository on a fresh branch, or finish one with --finish";
77
-
78
- /**
79
- * The other spelling of the topic, plus the short spelling of the command.
80
- * Both hidden spellings live where the other hidden alternates do, so they are
81
- * typable everywhere without ever reaching a listing.
82
- */
83
- static aliases = ["repos:contribute"];
84
-
85
- static hiddenAliases = ["repo:contrib", "repos:contrib"];
86
-
87
- static examples = [
88
- "<%= config.bin %> repo contribute sous-recipes",
89
- "<%= config.bin %> repo contribute workflow/task-files",
90
- "<%= config.bin %> repo contribute sous-recipes --create-branch fix-a-typo",
91
- '<%= config.bin %> repo contribute sous-recipes --finish --title "Fix a typo" --body "Fixes it."',
92
- "<%= config.bin %> repo contribute sous-recipes --finish --no-submit --remove",
93
- "<%= config.bin %> repo contribute sous-recipes --finish --dry-run",
94
- ];
95
-
96
- static args = {
97
- ref: Args.string({
98
- description:
99
- "The repository to contribute to, or a namespace or recipe it publishes",
100
- required: true,
101
- }),
102
- };
103
-
104
- static flags = {
105
- ...BaseCommand.baseFlags,
106
- // No default, so `dependsOn: ["finish"]` below can tell whether it was given.
107
- finish: Flags.boolean({
108
- description:
109
- "Finish the contribution: submit what no proposal carries yet, then unlink and update the pins",
110
- }),
111
- branch: Flags.string({
112
- description:
113
- "The existing branch to work on when starting, or to submit from when finishing",
114
- helpValue: "<name>",
115
- exclusive: ["create-branch", "generate-branch"],
116
- }),
117
- "create-branch": Flags.string({
118
- description: "Start the contribution on a new branch with this name",
119
- helpValue: "<name>",
120
- exclusive: ["branch", "generate-branch", "finish"],
121
- }),
122
- "generate-branch": Flags.boolean({
123
- description:
124
- "Start the contribution on a new branch named sous/edit-<date>-<time>, which is what happens when no branch is named",
125
- exclusive: ["branch", "create-branch", "finish"],
126
- }),
127
- from: Flags.string({
128
- description:
129
- "Start the new branch from this branch instead of the repository's default branch",
130
- helpValue: "<branch>",
131
- exclusive: ["branch", "finish"],
132
- }),
133
- global: Flags.boolean({
134
- description:
135
- "Work with the machine-wide link, sharing one checkout, rather than this project's link",
136
- default: false,
137
- }),
138
- submit: Flags.boolean({
139
- description:
140
- "Submit what no proposal carries yet without asking, or with --no-submit, finish without submitting it",
141
- allowNo: true,
142
- dependsOn: ["finish"],
143
- }),
144
- title: Flags.string({
145
- description: "The proposal's title; required for a new proposal, and replaces an open one's",
146
- dependsOn: ["finish"],
147
- }),
148
- body: Flags.string({
149
- description:
150
- "The proposal's description; required for a new proposal, and replaces an open one's",
151
- dependsOn: ["finish"],
152
- }),
153
- draft: Flags.boolean({
154
- description: "Open a new proposal as a draft",
155
- dependsOn: ["finish"],
156
- }),
157
- commit: Flags.boolean({
158
- description: "Commit uncommitted changes for you when submitting, after listing them and asking once",
159
- dependsOn: ["finish"],
160
- }),
161
- remove: Flags.boolean({
162
- description: "Delete the checkout as well when unlinking, when sous cloned it",
163
- dependsOn: ["finish"],
164
- }),
165
- yes: confirmationFlag(),
166
- "accept-first": Flags.boolean({
167
- description: "When the reference matches several things, take the first one listed",
168
- default: false,
169
- }),
170
- "dry-run": Flags.boolean({
171
- description: "Print each step this would run without running any of them",
172
- default: false,
173
- }),
174
- };
175
-
176
- async run(): Promise<void> {
177
- const { args, flags } = await this.parse(RepoContribute);
178
- const finishing = flags.finish === true;
179
- const dryRun = flags["dry-run"];
180
-
181
- showCommandVars({
182
- Project: this.projectLabel,
183
- Reference: args.ref,
184
- Mode: finishing ? "Finish a contribution" : "Start a contribution",
185
- Scope: flags.global ? "this machine" : "this project",
186
- "Dry Run": dryRun,
187
- });
188
-
189
- blankLine();
190
- const repo = await this.resolveRepository(args.ref, flags["accept-first"]);
191
-
192
- // Every step discovers the project again, so it is pointed at the same one.
193
- const configFlag = flags.config ?? flags["sous-config"];
194
- const locator: LocatorFlags = {
195
- ...(configFlag === undefined ? {} : { config: configFlag }),
196
- ...(flags["sous-dir"] === undefined ? {} : { "sous-dir": flags["sous-dir"] }),
197
- ...(flags["sous-confd"] === undefined ? {} : { "sous-confd": flags["sous-confd"] }),
198
- };
199
-
200
- if (finishing) {
201
- await this.finish(repo, {
202
- ...(flags.title === undefined ? {} : { title: flags.title }),
203
- ...(flags.body === undefined ? {} : { body: flags.body }),
204
- ...(flags.branch === undefined ? {} : { branch: flags.branch }),
205
- draft: flags.draft === true,
206
- commit: flags.commit === true,
207
- remove: flags.remove === true,
208
- global: flags.global,
209
- yes: flags.yes,
210
- }, flags.submit, locator, dryRun);
211
- } else {
212
- await this.start(
213
- repo,
214
- startStep(
215
- repo,
216
- {
217
- ...(flags.branch === undefined ? {} : { branch: flags.branch }),
218
- ...(flags["create-branch"] === undefined
219
- ? {}
220
- : { createBranch: flags["create-branch"] }),
221
- generateBranch: flags["generate-branch"] === true,
222
- ...(flags.from === undefined ? {} : { from: flags.from }),
223
- global: flags.global,
224
- yes: flags.yes,
225
- },
226
- locator
227
- ),
228
- flags.global,
229
- dryRun
230
- );
231
- }
232
-
233
- footer();
234
- }
235
-
236
- /**
237
- * Starts a contribution: one step, the link.
238
- *
239
- * @param repo - The repository's short name.
240
- * @param step - The link step.
241
- * @param isGlobal - Whether the link is the machine-wide one.
242
- * @param dryRun - When true, the step is printed and not run.
243
- */
244
- private async start(
245
- repo: string,
246
- step: ContributionStep,
247
- isGlobal: boolean,
248
- dryRun: boolean
249
- ): Promise<void> {
250
- section("Starting a contribution");
251
- this.printPlan([step]);
252
-
253
- if (dryRun) {
254
- blankLine();
255
- dryRunNotice("no step was run");
256
- return;
257
- }
258
-
259
- const completed: string[] = [];
260
- await this.runStep(step, completed);
261
-
262
- section("The contribution");
263
- const link = this.linkMap(isGlobal).links[repo];
264
- const branch =
265
- link !== undefined && isGitCheckout(link.path) ? currentBranch(link.path) : undefined;
266
- showVariables({
267
- Repository: repo,
268
- ...(link === undefined ? {} : { Checkout: link.path }),
269
- ...(branch === undefined ? {} : { Branch: branch }),
270
- });
271
- blankLine();
272
- paragraph(
273
- `Builds read '${repo}' from this checkout until the contribution is finished, so an ` +
274
- `edit made there shows up in this project's next build.`
275
- );
276
- this.printCompleted(completed);
277
- }
278
-
279
- /**
280
- * Finishes a contribution: works out whether the branch holds anything no
281
- * proposal carries yet, submits it when the contributor says so, then
282
- * unlinks the repository and updates its pins.
283
- *
284
- * @param repo - The repository's short name.
285
- * @param flags - The finish flags, passed through.
286
- * @param submitFlag - `--submit` (true), `--no-submit` (false), or neither.
287
- * @param locator - The config-locating flags, passed through.
288
- * @param dryRun - When true, the steps are printed and none is run.
289
- */
290
- private async finish(
291
- repo: string,
292
- flags: FinishFlags,
293
- submitFlag: boolean | undefined,
294
- locator: LocatorFlags,
295
- dryRun: boolean
296
- ): Promise<void> {
297
- const isGlobal = flags.global === true;
298
- const link = this.requireLink(repo, isGlobal);
299
-
300
- section("Finishing a contribution");
301
- showVariables({ Repository: repo, Checkout: link.path });
302
-
303
- const completed: string[] = [];
304
-
305
- subheading("Looking for work no proposal carries yet");
306
- blankLine();
307
- const work = pendingWork(link.path, flags.branch);
308
- this.printPendingWork(work);
309
-
310
- let verdict = assessPendingWork(work);
311
- if (verdict.kind === "lookup" && !dryRun) {
312
- paragraph(verdict.reason);
313
- blankLine();
314
- verdict = await this.lookUpProposal(link.path, work.branch!);
315
- blankLine();
316
- }
317
- paragraph(verdict.reason);
318
- completed.push("Looked for work no proposal carries yet");
319
-
320
- const unlink = unlinkStep(repo, flags, locator);
321
- const submit = submitStep(repo, flags);
322
-
323
- if (dryRun) {
324
- blankLine();
325
- if (verdict.kind === "nothing") {
326
- dryRunNotice("would skip submitting, since there is nothing to submit");
327
- blankLine();
328
- this.printPlan([unlink]);
329
- } else {
330
- if (verdict.kind === "lookup") {
331
- dryRunNotice(
332
- "would look the branch's proposal up, and treat the branch as having work to " +
333
- "submit when none is open"
334
- );
335
- }
336
- dryRunNotice(this.describeSubmitDecision(submitFlag, flags.yes === true));
337
- blankLine();
338
- this.printPlan(submitFlag === false ? [unlink] : [submit, unlink]);
339
- }
340
- blankLine();
341
- dryRunNotice("no step was run");
342
- return;
343
- }
344
-
345
- const steps: ContributionStep[] = [];
346
- if (verdict.kind !== "nothing" && (await this.shouldSubmit(submitFlag, flags.yes === true))) {
347
- steps.push(submit);
348
- } else if (verdict.kind !== "nothing") {
349
- blankLine();
350
- paragraph("It is not submitted; the checkout keeps it.");
351
- }
352
- steps.push(unlink);
353
-
354
- blankLine();
355
- this.printPlan(steps);
356
- for (const step of steps) await this.runStep(step, completed);
357
-
358
- this.printCompleted(completed);
359
- }
360
-
361
- // --- Resolving the reference ------------------------------------------------------------------
362
-
363
- /**
364
- * The repository a reference names: the repository itself, or the one that
365
- * publishes a namespace or recipe. Resolved through the shared reference
366
- * module over every repository this project trusts; a repository whose index
367
- * has never been fetched can still be named, just not searched inside.
368
- *
369
- * @param ref - The reference as it was written.
370
- * @param acceptFirst - The `--accept-first` flag.
371
- */
372
- private async resolveRepository(ref: string, acceptFirst: boolean): Promise<string> {
373
- const service = subscriptionServiceFor({
374
- configContext: this.configContext,
375
- settings: this.settings,
376
- shellEnv: this.shellEnv,
377
- });
378
-
379
- const repos: CatalogRepo[] = service.cachedReferenceRepos();
380
-
381
- const { refs } = await sharedRefResolver().resolve(
382
- new RefResolveArguments({
383
- input: ref,
384
- lookup: new CatalogLookup(repos),
385
- kinds: ["repo", "namespace", "recipe"],
386
- refusedIsEmpty: true,
387
- })
388
- );
389
-
390
- const chosen = await sharedRefPicker().pick(
391
- refs,
392
- new RefPickArguments({
393
- search: ref,
394
- interactive: this.interactive,
395
- acceptFirst,
396
- prompt: `Which '${ref}' do you want to contribute to?`,
397
- details: [
398
- " No trusted repository, namespace or recipe has that name.",
399
- repos.length === 0
400
- ? " This project trusts no repositories."
401
- : ` This project trusts: ${repos.map((entry) => entry.name).join(", ")}.`,
402
- ],
403
- })
404
- );
405
- return chosen.kind === "repo" ? chosen.name! : repoOf(chosen)!.name!;
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
- }