@sous-io/sous 0.2.37 → 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 -245
  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 -410
  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 -413
  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 -1107
  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,332 +0,0 @@
1
- /**
2
- * The GitLab provider: the read path, and as much of the write path as GitLab
3
- * honestly gives sous.
4
- *
5
- * The read shape is the same as the GitHub provider's: the index file is one raw
6
- * HTTPS GET, and a recipe's subtree comes from git. A token is used when one is
7
- * available, read from GITLAB_TOKEN or asked of the `glab` command line tool
8
- * when that is installed and signed in; a missing `glab` is never an error on
9
- * the read path.
10
- *
11
- * The write path is one merge request opened by `glab mr create`, from a branch
12
- * the contributor can already push. Sous does not fork on GitLab: there is no
13
- * fork-and-track flow here that sous can carry out without guessing, so
14
- * `canPush` answers "cannot tell" rather than inventing a permission, and `fork`
15
- * refuses with the manual route spelled out. Saying so is the point; pretending
16
- * otherwise would strand a contributor halfway through a submission.
17
- *
18
- * Self-hosted instances are supported: any host whose name begins with `gitlab.`
19
- * is recognized automatically, and a repository entry may always name its
20
- * provider outright for a host that gives nothing away.
21
- */
22
-
23
- import { ConfigError } from "../../errors.js";
24
- import { INDEX_FILENAME } from "../formats/common.js";
25
- import { ProviderBase, firstUrlIn } from "./base.js";
26
- import { fetchSubtree, type CommandRunner } from "./git.js";
27
- import { fetchText, type FetchLike } from "./http.js";
28
- import {
29
- buildCanonicalRepo,
30
- invalidRepoUrl,
31
- readingsAfterRepository,
32
- splitRepoUrl,
33
- withoutGitSuffix,
34
- type LocationReading,
35
- type WrittenLocation,
36
- type AuthStatus,
37
- type CanonicalRepo,
38
- type ChangeProposal,
39
- type FetchedIndex,
40
- type ForkedRepo,
41
- type ProposedChange,
42
- type ProviderCli,
43
- type ProviderFeature,
44
- type ProviderOptions,
45
- } from "./provider.js";
46
-
47
- /** The host this provider serves when a URL does not say otherwise. */
48
- export const GITLAB_HOST = "gitlab.com";
49
-
50
- /** The environment variable a GitLab token is read from. */
51
- export const GITLAB_TOKEN_ENV = "GITLAB_TOKEN";
52
-
53
- /**
54
- * Finds a GitLab token: the environment first, then `glab auth token` when the
55
- * `glab` command line tool is installed and signed in. Returns undefined when
56
- * there is none, because public repositories need no token at all.
57
- *
58
- * @param options - Environment and subprocess runner overrides.
59
- */
60
- export async function findGitlabToken(options: {
61
- env?: NodeJS.ProcessEnv;
62
- run?: CommandRunner;
63
- } = {}): Promise<string | undefined> {
64
- return new GitlabProvider().token(options);
65
- }
66
-
67
- /** The GitLab provider. */
68
- export class GitlabProvider extends ProviderBase {
69
- readonly id = "gitlab" as const;
70
-
71
- /**
72
- * Reads the index and recipe subtrees, and proposes a change through
73
- * the GitLab CLI ('glab').
74
- */
75
- readonly features: ProviderFeature[] = ["fetch", "submit"];
76
-
77
- /** The command line tool the write path is built on. */
78
- readonly cli: ProviderCli = {
79
- command: "glab",
80
- label: "the GitLab CLI",
81
- install: "https://gitlab.com/gitlab-org/cli",
82
- };
83
-
84
- /** What GitLab calls a proposal. */
85
- readonly proposalNoun = "merge request";
86
-
87
- /** The host a `gitlab://` locator means when it names none. */
88
- readonly defaultHost = GITLAB_HOST;
89
-
90
- /**
91
- * A GitLab project path nests (`group/subgroup/project`), so where it ends is
92
- * only certain when the location says so: a `-` segment (GitLab's own
93
- * separator, as in `/-/tree/main/...`) or a `.git` suffix ends it. Otherwise
94
- * every split that leaves a project of at least two segments and at most a
95
- * namespace and a recipe after it is a reading, and the caller keeps the one
96
- * an index confirms.
97
- *
98
- * readLocation({ host: "gitlab.com", segments: ["a", "b", "c", "d"] });
99
- * // -> project "a/b" naming "c/d", project "a/b/c" naming "d",
100
- * // and project "a/b/c/d" naming nothing
101
- *
102
- * @param location - The host and the segments after it.
103
- */
104
- readLocation(location: WrittenLocation): LocationReading[] {
105
- const { segments } = location;
106
-
107
- const separator = segments.indexOf("-");
108
- if (separator >= 2) {
109
- return readingsAfterRepository(
110
- this.projectPath(segments.slice(0, separator)),
111
- segments.slice(separator)
112
- );
113
- }
114
-
115
- const suffixed = segments.findIndex((segment) => /\.git$/i.test(segment));
116
- if (suffixed >= 1) {
117
- return readingsAfterRepository(
118
- this.projectPath(segments.slice(0, suffixed + 1)),
119
- segments.slice(suffixed + 1)
120
- );
121
- }
122
-
123
- const readings: LocationReading[] = [];
124
- for (let end = 2; end <= segments.length; end++) {
125
- const rest = segments.slice(end);
126
- if (rest.length > 2) continue;
127
- readings.push({ repoPath: this.projectPath(segments.slice(0, end)), named: rest });
128
- }
129
- return readings;
130
- }
131
-
132
- /**
133
- * The canonical locator always marks where the project path ends with `-`,
134
- * because without it a nested group reads more than one way.
135
- *
136
- * @param host - The project's host.
137
- * @param repoPath - The project's path on that host.
138
- * @param rest - What is named inside it.
139
- */
140
- formatLocator(host: string, repoPath: string, rest: string): string {
141
- const where = host === this.defaultHost ? repoPath : `${host}/${repoPath}`;
142
- return `${this.id}://${where}${rest.length === 0 ? "" : `/-/${rest}`}`;
143
- }
144
-
145
- /** A project path from its segments, with the last one's `.git` gone. */
146
- private projectPath(segments: string[]): string {
147
- const last = segments.length - 1;
148
- return segments.map((segment, index) => (index === last ? withoutGitSuffix(segment) : segment)).join("/");
149
- }
150
-
151
- matches(url: string): boolean {
152
- const parts = splitRepoUrl(url);
153
- if (parts === undefined) return false;
154
- return parts.host === GITLAB_HOST || parts.host.startsWith("gitlab.");
155
- }
156
-
157
- canonicalize(url: string): CanonicalRepo {
158
- const parts = splitRepoUrl(url);
159
- if (parts === undefined) throw invalidRepoUrl(this.id, url);
160
- return buildCanonicalRepo(parts.host, parts.owner, parts.name);
161
- }
162
-
163
- /**
164
- * A GitLab token, from the environment or from `glab`.
165
- *
166
- * @param options - Environment and subprocess runner overrides.
167
- */
168
- async token(options: ProviderOptions = {}): Promise<string | undefined> {
169
- return this.findToken(GITLAB_TOKEN_ENV, ["auth", "token"], options);
170
- }
171
-
172
- /**
173
- * Fetches the repo's index file from the instance's raw file endpoint at the
174
- * repository's default branch.
175
- *
176
- * @param repo - The canonicalized repository.
177
- * @param options - Environment, fetch and subprocess overrides.
178
- */
179
- async fetchIndex(
180
- repo: CanonicalRepo,
181
- options: ProviderOptions = {}
182
- ): Promise<FetchedIndex> {
183
- const token = await this.token(options);
184
- const url = this.indexUrl(repo);
185
- const fetched = await fetchText(url, {
186
- ...(token === undefined ? {} : { token }),
187
- ...(options.fetchImpl === undefined
188
- ? {}
189
- : { fetchImpl: options.fetchImpl as FetchLike }),
190
- ...(options.signal === undefined ? {} : { signal: options.signal }),
191
- label: "repo index",
192
- });
193
-
194
- return fetched.etag === undefined
195
- ? { text: fetched.text, ref: "HEAD" }
196
- : { text: fetched.text, ref: "HEAD", etag: fetched.etag };
197
- }
198
-
199
- /**
200
- * Fetches one recipe folder at one tag. Private repositories work through
201
- * git's own credential helpers, the same way a manual clone would.
202
- *
203
- * @param repo - The canonicalized repository.
204
- * @param recipePath - The recipe folder, relative to the repository root.
205
- * @param tag - The git tag carrying the version.
206
- * @param destDir - Where the recipe's files should end up.
207
- * @param options - Subprocess runner override.
208
- */
209
- async fetchRecipeTree(
210
- repo: CanonicalRepo,
211
- recipePath: string,
212
- tag: string,
213
- destDir: string,
214
- options: ProviderOptions = {}
215
- ): Promise<void> {
216
- await fetchSubtree({
217
- cloneUrl: repo.httpsUrl,
218
- tag,
219
- subPath: recipePath,
220
- destDir,
221
- ...(options.run === undefined ? {} : { run: options.run }),
222
- });
223
- }
224
-
225
- /**
226
- * The raw URL of a repository's index file at its default branch.
227
- *
228
- * @param repo - The canonicalized repository.
229
- */
230
- indexUrl(repo: CanonicalRepo): string {
231
- return `https://${repo.host}/${repo.owner}/${repo.name}/-/raw/HEAD/${INDEX_FILENAME}`;
232
- }
233
-
234
- // --- The write path --------------------------------------------------------
235
-
236
- /**
237
- * Whether `glab` is installed and signed in.
238
- *
239
- * @param options - Subprocess runner and working directory overrides.
240
- */
241
- async authStatus(options: ProviderOptions = {}): Promise<AuthStatus> {
242
- const ok = await this.commandSucceeds(this.cli.command, ["auth", "status"], options);
243
- if (ok) {
244
- return {
245
- ok: true,
246
- detail: `${this.cli.label} ('${this.cli.command}') is installed and signed in.`,
247
- };
248
- }
249
- return {
250
- ok: false,
251
- detail:
252
- `Sous proposes a change through ${this.cli.label} ('${this.cli.command}'), and it is ` +
253
- `either not installed or not signed in.\n` +
254
- ` Install it from ${this.cli.install}, then run '${this.cli.command} auth login'.`,
255
- };
256
- }
257
-
258
- /**
259
- * Always undefined: sous has no cheap, reliable way to ask GitLab whether the
260
- * contributor may push, and guessing would send them down a fork path this
261
- * provider cannot finish.
262
- *
263
- * @param _repo - The canonicalized repository; unused.
264
- * @param _options - Unused, because nothing is run.
265
- */
266
- async canPush(
267
- _repo: CanonicalRepo,
268
- _options: ProviderOptions = {}
269
- ): Promise<boolean | undefined> {
270
- return undefined;
271
- }
272
-
273
- /**
274
- * Refuses, with the manual route. Sous opens a merge request from a branch
275
- * the contributor can already push; forking on their behalf is not something
276
- * this provider does.
277
- *
278
- * @param repo - The canonicalized repository.
279
- */
280
- async fork(repo: CanonicalRepo): Promise<ForkedRepo> {
281
- throw new ConfigError(
282
- `Sous does not fork ${repo.owner}/${repo.name} for you on ${this.cli.label}; it opens a ` +
283
- `${this.proposalNoun} from a branch you can already push.\n` +
284
- ` Fork the project yourself, push your branch to the fork, then open the ` +
285
- `${this.proposalNoun} from there.`
286
- );
287
- }
288
-
289
- /**
290
- * Opens a merge request from the branch in the checkout the command is run
291
- * in, which is why the working directory matters here.
292
- *
293
- * @param _repo - The canonicalized repository; `glab` reads the checkout instead.
294
- * @param proposal - The branch, the text and whether it is a draft.
295
- * @param options - Subprocess runner and working directory overrides.
296
- */
297
- async proposeChange(
298
- _repo: CanonicalRepo,
299
- proposal: ChangeProposal,
300
- options: ProviderOptions = {}
301
- ): Promise<ProposedChange> {
302
- const args = ["mr", "create", "--source-branch", proposal.branch];
303
- if (proposal.base !== undefined) args.push("--target-branch", proposal.base);
304
- args.push(
305
- "--title",
306
- proposal.title,
307
- "--description",
308
- proposal.body,
309
- "--yes"
310
- );
311
- if (proposal.draft) args.push("--draft");
312
-
313
- const result = await this.runCommand(this.cli.command, args, options);
314
- if (result.code !== 0) {
315
- const reported = result.stderr.trim() || result.stdout.trim();
316
- throw new ConfigError(
317
- `'${this.cli.command} mr create' did not succeed, so no proposal was opened.` +
318
- (reported.length === 0 ? "" : `\n ${reported}`)
319
- );
320
- }
321
-
322
- const url = firstUrlIn(result.stdout);
323
- if (url === undefined) {
324
- return {
325
- detail:
326
- `The ${this.proposalNoun} was opened, but '${this.cli.command}' printed no address ` +
327
- `for it.`,
328
- };
329
- }
330
- return { url, detail: `The ${this.proposalNoun} is at ${url}.` };
331
- }
332
- }
@@ -1,128 +0,0 @@
1
- /**
2
- * The tiny HTTPS client the providers use to fetch a repo's index file.
3
- *
4
- * Only one kind of request is ever made: a plain GET of a raw file, optionally
5
- * carrying a bearer token so private repositories work. `fetch` is Node's own
6
- * global, and it is injectable so tests never reach the network.
7
- */
8
-
9
- import { ConfigError } from "../../errors.js";
10
-
11
- /** The shape of `fetch` this module needs; the global satisfies it. */
12
- export type FetchLike = (
13
- url: string,
14
- init?: { headers?: Record<string, string>; signal?: AbortSignal }
15
- ) => Promise<{
16
- ok: boolean;
17
- status: number;
18
- statusText: string;
19
- text: () => Promise<string>;
20
- headers: { get: (name: string) => string | null };
21
- }>;
22
-
23
- /** What a successful raw-file GET returns. */
24
- export type FetchedText = {
25
- /** The file's contents. */
26
- text: string;
27
- /** The entity tag the server sent, when it sent one. */
28
- etag?: string;
29
- };
30
-
31
- /** Options for a raw-file GET. */
32
- export type FetchTextOptions = {
33
- /** A bearer token, when one is available for the host. */
34
- token?: string;
35
- /** The fetch implementation to use. Defaults to the global `fetch`. */
36
- fetchImpl?: FetchLike;
37
- /** What the URL is, named in error messages (for example "repo index"). */
38
- label?: string;
39
- /** Cancels the request, for a caller that will not wait past a deadline. */
40
- signal?: AbortSignal;
41
- /** The `Accept` header to send. Defaults to `application/json`. */
42
- accept?: string;
43
- /**
44
- * The lines that explain a failed status to the reader. Defaults to the
45
- * hints about a sous repository (a missing index, a private repository), so
46
- * a caller fetching anything else names its own.
47
- */
48
- statusHints?: (status: number) => string[];
49
- };
50
-
51
- /**
52
- * What a failed status usually means when the URL names a file in a sous
53
- * repository: the default for `FetchTextOptions.statusHints`.
54
- *
55
- * @param status - The HTTP status the server answered with.
56
- */
57
- function repositoryStatusHints(status: number): string[] {
58
- if (status === 404) {
59
- return [
60
- " Either the repository publishes no sous index yet, or the URL names a " +
61
- "repository that does not exist.",
62
- ];
63
- }
64
- if (status === 401 || status === 403) {
65
- return [
66
- " The repository is private or the request was not authorized. Sous uses a " +
67
- "token from the environment, or from the provider's command line tool when " +
68
- "one is installed and signed in.",
69
- ];
70
- }
71
- return [];
72
- }
73
-
74
- /**
75
- * GETs a URL and returns its body as text. Any non-2xx response, or a transport
76
- * failure, becomes a ConfigError that names the URL and the status, and says
77
- * plainly what the status usually means (for a sous repository, unless the
78
- * caller passes `statusHints`).
79
- *
80
- * @param url - The absolute HTTPS URL to fetch.
81
- * @param options - Bearer token, fetch implementation, error label, `Accept`
82
- * header and status hints.
83
- */
84
- export async function fetchText(
85
- url: string,
86
- options: FetchTextOptions = {}
87
- ): Promise<FetchedText> {
88
- const fetchImpl = options.fetchImpl ?? (globalThis.fetch as unknown as FetchLike);
89
- const label = options.label ?? "file";
90
-
91
- if (typeof fetchImpl !== "function") {
92
- throw new ConfigError(
93
- `Sous cannot fetch the ${label} at ${url}: this Node runtime provides no global fetch.\n` +
94
- ` Sous requires Node 22 or newer.`
95
- );
96
- }
97
-
98
- const headers: Record<string, string> = { Accept: options.accept ?? "application/json" };
99
- if (options.token !== undefined && options.token.length > 0) {
100
- headers["Authorization"] = `Bearer ${options.token}`;
101
- }
102
-
103
- let response: Awaited<ReturnType<FetchLike>>;
104
- try {
105
- response = await fetchImpl(
106
- url,
107
- options.signal === undefined ? { headers } : { headers, signal: options.signal }
108
- );
109
- } catch (error) {
110
- throw new ConfigError(
111
- `Sous could not reach ${url} while fetching the ${label}.\n` +
112
- ` ${(error as Error).message}`
113
- );
114
- }
115
-
116
- if (!response.ok) {
117
- const lines = [
118
- `Sous could not fetch the ${label} from ${url}.`,
119
- ` The server answered ${response.status} ${response.statusText}.`,
120
- ];
121
- lines.push(...(options.statusHints ?? repositoryStatusHints)(response.status));
122
- throw new ConfigError(lines.join("\n"));
123
- }
124
-
125
- const text = await response.text();
126
- const etag = response.headers.get("etag");
127
- return etag === null ? { text } : { text, etag };
128
- }