@release-please-oss/release-please 0.0.0 → 17.11.3

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 (310) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +280 -0
  3. package/build/src/bin/release-please.d.ts +22 -0
  4. package/build/src/bin/release-please.js +727 -0
  5. package/build/src/bootstrapper.d.ts +18 -0
  6. package/build/src/bootstrapper.js +64 -0
  7. package/build/src/changelog-notes/default.d.ts +15 -0
  8. package/build/src/changelog-notes/default.js +96 -0
  9. package/build/src/changelog-notes/github.d.ts +8 -0
  10. package/build/src/changelog-notes/github.js +29 -0
  11. package/build/src/changelog-notes.d.ts +22 -0
  12. package/build/src/changelog-notes.js +40 -0
  13. package/build/src/commit.d.ts +33 -0
  14. package/build/src/commit.js +422 -0
  15. package/build/src/errors/index.d.ts +36 -0
  16. package/build/src/errors/index.js +77 -0
  17. package/build/src/factories/changelog-notes-factory.d.ts +16 -0
  18. package/build/src/factories/changelog-notes-factory.js +44 -0
  19. package/build/src/factories/plugin-factory.d.ts +23 -0
  20. package/build/src/factories/plugin-factory.js +94 -0
  21. package/build/src/factories/versioning-strategy-factory.d.ts +16 -0
  22. package/build/src/factories/versioning-strategy-factory.js +52 -0
  23. package/build/src/factory.d.ts +18 -0
  24. package/build/src/factory.js +161 -0
  25. package/build/src/github-api.d.ts +260 -0
  26. package/build/src/github-api.js +714 -0
  27. package/build/src/github.d.ts +306 -0
  28. package/build/src/github.js +769 -0
  29. package/build/src/index.d.ts +17 -0
  30. package/build/src/index.js +41 -0
  31. package/build/src/local-github.d.ts +270 -0
  32. package/build/src/local-github.js +756 -0
  33. package/build/src/manifest.d.ts +370 -0
  34. package/build/src/manifest.js +1142 -0
  35. package/build/src/plugin.d.ts +37 -0
  36. package/build/src/plugin.js +57 -0
  37. package/build/src/plugins/cargo-workspace.d.ts +58 -0
  38. package/build/src/plugins/cargo-workspace.js +339 -0
  39. package/build/src/plugins/group-priority.d.ts +29 -0
  40. package/build/src/plugins/group-priority.js +82 -0
  41. package/build/src/plugins/linked-versions.d.ts +36 -0
  42. package/build/src/plugins/linked-versions.js +137 -0
  43. package/build/src/plugins/maven-workspace.d.ts +81 -0
  44. package/build/src/plugins/maven-workspace.js +431 -0
  45. package/build/src/plugins/merge.d.ts +27 -0
  46. package/build/src/plugins/merge.js +99 -0
  47. package/build/src/plugins/node-workspace.d.ts +50 -0
  48. package/build/src/plugins/node-workspace.js +352 -0
  49. package/build/src/plugins/sentence-case.d.ts +19 -0
  50. package/build/src/plugins/sentence-case.js +80 -0
  51. package/build/src/plugins/workspace.d.ts +173 -0
  52. package/build/src/plugins/workspace.js +308 -0
  53. package/build/src/pull-request.d.ts +11 -0
  54. package/build/src/pull-request.js +16 -0
  55. package/build/src/release-pull-request.d.ts +14 -0
  56. package/build/src/release-pull-request.js +16 -0
  57. package/build/src/release.d.ts +7 -0
  58. package/build/src/release.js +16 -0
  59. package/build/src/repository.d.ts +5 -0
  60. package/build/src/repository.js +16 -0
  61. package/build/src/scm.d.ts +80 -0
  62. package/build/src/scm.js +16 -0
  63. package/build/src/strategies/base.d.ts +162 -0
  64. package/build/src/strategies/base.js +494 -0
  65. package/build/src/strategies/bazel.d.ts +7 -0
  66. package/build/src/strategies/bazel.js +49 -0
  67. package/build/src/strategies/dart.d.ts +8 -0
  68. package/build/src/strategies/dart.js +73 -0
  69. package/build/src/strategies/dotnet-yoshi.d.ts +13 -0
  70. package/build/src/strategies/dotnet-yoshi.js +109 -0
  71. package/build/src/strategies/elixir.d.ts +5 -0
  72. package/build/src/strategies/elixir.js +46 -0
  73. package/build/src/strategies/expo.d.ts +15 -0
  74. package/build/src/strategies/expo.js +51 -0
  75. package/build/src/strategies/go-librarian.d.ts +11 -0
  76. package/build/src/strategies/go-librarian.js +84 -0
  77. package/build/src/strategies/go-yoshi.d.ts +14 -0
  78. package/build/src/strategies/go-yoshi.js +168 -0
  79. package/build/src/strategies/go.d.ts +7 -0
  80. package/build/src/strategies/go.js +53 -0
  81. package/build/src/strategies/helm.d.ts +8 -0
  82. package/build/src/strategies/helm.js +73 -0
  83. package/build/src/strategies/java-yoshi-mono-repo.d.ts +22 -0
  84. package/build/src/strategies/java-yoshi-mono-repo.js +308 -0
  85. package/build/src/strategies/java-yoshi.d.ts +20 -0
  86. package/build/src/strategies/java-yoshi.js +210 -0
  87. package/build/src/strategies/java.d.ts +28 -0
  88. package/build/src/strategies/java.js +176 -0
  89. package/build/src/strategies/krm-blueprint.d.ts +7 -0
  90. package/build/src/strategies/krm-blueprint.js +65 -0
  91. package/build/src/strategies/maven.d.ts +9 -0
  92. package/build/src/strategies/maven.js +56 -0
  93. package/build/src/strategies/node-librarian.d.ts +10 -0
  94. package/build/src/strategies/node-librarian.js +121 -0
  95. package/build/src/strategies/node.d.ts +10 -0
  96. package/build/src/strategies/node.js +111 -0
  97. package/build/src/strategies/ocaml.d.ts +5 -0
  98. package/build/src/strategies/ocaml.js +86 -0
  99. package/build/src/strategies/php-librarian.d.ts +6 -0
  100. package/build/src/strategies/php-librarian.js +35 -0
  101. package/build/src/strategies/php-yoshi.d.ts +13 -0
  102. package/build/src/strategies/php-yoshi.js +255 -0
  103. package/build/src/strategies/php.d.ts +6 -0
  104. package/build/src/strategies/php.js +76 -0
  105. package/build/src/strategies/python-librarian.d.ts +6 -0
  106. package/build/src/strategies/python-librarian.js +35 -0
  107. package/build/src/strategies/python.d.ts +11 -0
  108. package/build/src/strategies/python.js +175 -0
  109. package/build/src/strategies/r.d.ts +8 -0
  110. package/build/src/strategies/r.js +67 -0
  111. package/build/src/strategies/ruby-librarian.d.ts +6 -0
  112. package/build/src/strategies/ruby-librarian.js +35 -0
  113. package/build/src/strategies/ruby-yoshi.d.ts +13 -0
  114. package/build/src/strategies/ruby-yoshi.js +97 -0
  115. package/build/src/strategies/ruby.d.ts +9 -0
  116. package/build/src/strategies/ruby.js +71 -0
  117. package/build/src/strategies/rust.d.ts +17 -0
  118. package/build/src/strategies/rust.js +149 -0
  119. package/build/src/strategies/sfdx.d.ts +9 -0
  120. package/build/src/strategies/sfdx.js +67 -0
  121. package/build/src/strategies/simple.d.ts +7 -0
  122. package/build/src/strategies/simple.js +51 -0
  123. package/build/src/strategies/terraform-module.d.ts +7 -0
  124. package/build/src/strategies/terraform-module.js +90 -0
  125. package/build/src/strategy.d.ts +68 -0
  126. package/build/src/strategy.js +16 -0
  127. package/build/src/update.d.ts +24 -0
  128. package/build/src/update.js +16 -0
  129. package/build/src/updaters/base-xml.d.ts +19 -0
  130. package/build/src/updaters/base-xml.js +43 -0
  131. package/build/src/updaters/bazel/module-bazel.d.ts +7 -0
  132. package/build/src/updaters/bazel/module-bazel.js +33 -0
  133. package/build/src/updaters/changelog-json.d.ts +29 -0
  134. package/build/src/updaters/changelog-json.js +100 -0
  135. package/build/src/updaters/changelog.d.ts +13 -0
  136. package/build/src/updaters/changelog.js +55 -0
  137. package/build/src/updaters/composite.d.ts +20 -0
  138. package/build/src/updaters/composite.js +65 -0
  139. package/build/src/updaters/dart/pubspec-yaml.d.ts +13 -0
  140. package/build/src/updaters/dart/pubspec-yaml.js +50 -0
  141. package/build/src/updaters/default.d.ts +21 -0
  142. package/build/src/updaters/default.js +36 -0
  143. package/build/src/updaters/dotnet/apis.d.ts +18 -0
  144. package/build/src/updaters/dotnet/apis.js +45 -0
  145. package/build/src/updaters/dotnet/csproj.d.ts +12 -0
  146. package/build/src/updaters/dotnet/csproj.js +33 -0
  147. package/build/src/updaters/elixir/elixir-mix-exs.d.ts +13 -0
  148. package/build/src/updaters/elixir/elixir-mix-exs.js +42 -0
  149. package/build/src/updaters/expo/app-json.d.ts +31 -0
  150. package/build/src/updaters/expo/app-json.js +67 -0
  151. package/build/src/updaters/generic-json.d.ts +14 -0
  152. package/build/src/updaters/generic-json.js +54 -0
  153. package/build/src/updaters/generic-toml.d.ts +21 -0
  154. package/build/src/updaters/generic-toml.js +66 -0
  155. package/build/src/updaters/generic-xml.d.ts +8 -0
  156. package/build/src/updaters/generic-xml.js +38 -0
  157. package/build/src/updaters/generic-yaml.d.ts +23 -0
  158. package/build/src/updaters/generic-yaml.js +85 -0
  159. package/build/src/updaters/generic.d.ts +54 -0
  160. package/build/src/updaters/generic.js +187 -0
  161. package/build/src/updaters/go/version-go.d.ts +4 -0
  162. package/build/src/updaters/go/version-go.js +24 -0
  163. package/build/src/updaters/helm/chart-yaml.d.ts +13 -0
  164. package/build/src/updaters/helm/chart-yaml.js +41 -0
  165. package/build/src/updaters/java/java-released.d.ts +28 -0
  166. package/build/src/updaters/java/java-released.js +59 -0
  167. package/build/src/updaters/java/java-update.d.ts +21 -0
  168. package/build/src/updaters/java/java-update.js +80 -0
  169. package/build/src/updaters/java/pom-xml.d.ts +29 -0
  170. package/build/src/updaters/java/pom-xml.js +135 -0
  171. package/build/src/updaters/java/versions-manifest.d.ts +19 -0
  172. package/build/src/updaters/java/versions-manifest.js +71 -0
  173. package/build/src/updaters/krm/krm-blueprint-version.d.ts +13 -0
  174. package/build/src/updaters/krm/krm-blueprint-version.js +46 -0
  175. package/build/src/updaters/librarian-yaml.d.ts +45 -0
  176. package/build/src/updaters/librarian-yaml.js +149 -0
  177. package/build/src/updaters/node/package-json.d.ts +46 -0
  178. package/build/src/updaters/node/package-json.js +106 -0
  179. package/build/src/updaters/node/package-lock-json.d.ts +14 -0
  180. package/build/src/updaters/node/package-lock-json.js +83 -0
  181. package/build/src/updaters/node/samples-package-json.d.ts +24 -0
  182. package/build/src/updaters/node/samples-package-json.js +49 -0
  183. package/build/src/updaters/ocaml/dune-project.d.ts +13 -0
  184. package/build/src/updaters/ocaml/dune-project.js +37 -0
  185. package/build/src/updaters/ocaml/esy-json.d.ts +13 -0
  186. package/build/src/updaters/ocaml/esy-json.js +37 -0
  187. package/build/src/updaters/ocaml/opam.d.ts +13 -0
  188. package/build/src/updaters/ocaml/opam.js +37 -0
  189. package/build/src/updaters/php/php-client-version.d.ts +12 -0
  190. package/build/src/updaters/php/php-client-version.js +32 -0
  191. package/build/src/updaters/php/root-composer-update-packages.d.ts +13 -0
  192. package/build/src/updaters/php/root-composer-update-packages.js +60 -0
  193. package/build/src/updaters/python/pyproject-toml.d.ts +29 -0
  194. package/build/src/updaters/python/pyproject-toml.js +53 -0
  195. package/build/src/updaters/python/python-file-with-version.d.ts +12 -0
  196. package/build/src/updaters/python/python-file-with-version.js +32 -0
  197. package/build/src/updaters/python/setup-cfg.d.ts +12 -0
  198. package/build/src/updaters/python/setup-cfg.js +32 -0
  199. package/build/src/updaters/python/setup-py.d.ts +12 -0
  200. package/build/src/updaters/python/setup-py.js +32 -0
  201. package/build/src/updaters/r/description.d.ts +12 -0
  202. package/build/src/updaters/r/description.js +32 -0
  203. package/build/src/updaters/r/news.d.ts +12 -0
  204. package/build/src/updaters/r/news.js +49 -0
  205. package/build/src/updaters/raw-content.d.ts +19 -0
  206. package/build/src/updaters/raw-content.js +39 -0
  207. package/build/src/updaters/release-please-config.d.ts +8 -0
  208. package/build/src/updaters/release-please-config.js +80 -0
  209. package/build/src/updaters/release-please-manifest.d.ts +4 -0
  210. package/build/src/updaters/release-please-manifest.js +34 -0
  211. package/build/src/updaters/ruby/common.d.ts +17 -0
  212. package/build/src/updaters/ruby/common.js +46 -0
  213. package/build/src/updaters/ruby/gemfile-lock.d.ts +24 -0
  214. package/build/src/updaters/ruby/gemfile-lock.js +53 -0
  215. package/build/src/updaters/ruby/version-rb.d.ts +12 -0
  216. package/build/src/updaters/ruby/version-rb.js +34 -0
  217. package/build/src/updaters/rust/cargo-lock.d.ts +16 -0
  218. package/build/src/updaters/rust/cargo-lock.js +64 -0
  219. package/build/src/updaters/rust/cargo-toml.d.ts +13 -0
  220. package/build/src/updaters/rust/cargo-toml.js +89 -0
  221. package/build/src/updaters/rust/common.d.ts +54 -0
  222. package/build/src/updaters/rust/common.js +35 -0
  223. package/build/src/updaters/sfdx/sfdx-project-json.d.ts +21 -0
  224. package/build/src/updaters/sfdx/sfdx-project-json.js +41 -0
  225. package/build/src/updaters/terraform/metadata-version.d.ts +13 -0
  226. package/build/src/updaters/terraform/metadata-version.js +37 -0
  227. package/build/src/updaters/terraform/module-version.d.ts +13 -0
  228. package/build/src/updaters/terraform/module-version.js +37 -0
  229. package/build/src/updaters/terraform/readme.d.ts +12 -0
  230. package/build/src/updaters/terraform/readme.js +32 -0
  231. package/build/src/util/branch-name.d.ts +20 -0
  232. package/build/src/util/branch-name.js +225 -0
  233. package/build/src/util/code-suggester/default-options-handler.d.ts +10 -0
  234. package/build/src/util/code-suggester/default-options-handler.js +45 -0
  235. package/build/src/util/code-suggester/errors.d.ts +4 -0
  236. package/build/src/util/code-suggester/errors.js +24 -0
  237. package/build/src/util/code-suggester/github/branch.d.ts +45 -0
  238. package/build/src/util/code-suggester/github/branch.js +118 -0
  239. package/build/src/util/code-suggester/github/commit-and-push.d.ts +51 -0
  240. package/build/src/util/code-suggester/github/commit-and-push.js +141 -0
  241. package/build/src/util/code-suggester/github/create-commit.d.ts +20 -0
  242. package/build/src/util/code-suggester/github/create-commit.js +60 -0
  243. package/build/src/util/code-suggester/github/fork.d.ts +15 -0
  244. package/build/src/util/code-suggester/github/fork.js +48 -0
  245. package/build/src/util/code-suggester/github/labels.d.ts +14 -0
  246. package/build/src/util/code-suggester/github/labels.js +42 -0
  247. package/build/src/util/code-suggester/github/open-pull-request.d.ts +16 -0
  248. package/build/src/util/code-suggester/github/open-pull-request.js +56 -0
  249. package/build/src/util/code-suggester/index.d.ts +28 -0
  250. package/build/src/util/code-suggester/index.js +110 -0
  251. package/build/src/util/code-suggester/logger.d.ts +4 -0
  252. package/build/src/util/code-suggester/logger.js +37 -0
  253. package/build/src/util/code-suggester/types.d.ts +109 -0
  254. package/build/src/util/code-suggester/types.js +30 -0
  255. package/build/src/util/coerce-option.d.ts +1 -0
  256. package/build/src/util/coerce-option.js +40 -0
  257. package/build/src/util/commit-exclude.d.ts +10 -0
  258. package/build/src/util/commit-exclude.js +49 -0
  259. package/build/src/util/commit-split.d.ts +26 -0
  260. package/build/src/util/commit-split.js +100 -0
  261. package/build/src/util/commit-utils.d.ts +1 -0
  262. package/build/src/util/commit-utils.js +34 -0
  263. package/build/src/util/filter-commits.d.ts +12 -0
  264. package/build/src/util/filter-commits.js +59 -0
  265. package/build/src/util/indent-commit.d.ts +2 -0
  266. package/build/src/util/indent-commit.js +39 -0
  267. package/build/src/util/json-stringify.d.ts +1 -0
  268. package/build/src/util/json-stringify.js +22 -0
  269. package/build/src/util/logger.d.ts +24 -0
  270. package/build/src/util/logger.js +54 -0
  271. package/build/src/util/pull-request-body.d.ts +25 -0
  272. package/build/src/util/pull-request-body.js +147 -0
  273. package/build/src/util/pull-request-overflow-handler.d.ts +54 -0
  274. package/build/src/util/pull-request-overflow-handler.js +78 -0
  275. package/build/src/util/pull-request-title.d.ts +22 -0
  276. package/build/src/util/pull-request-title.js +146 -0
  277. package/build/src/util/signoff-commit-message.d.ts +1 -0
  278. package/build/src/util/signoff-commit-message.js +35 -0
  279. package/build/src/util/tag-name.d.ts +10 -0
  280. package/build/src/util/tag-name.js +42 -0
  281. package/build/src/util/toml-edit.d.ts +16 -0
  282. package/build/src/util/toml-edit.js +126 -0
  283. package/build/src/version.d.ts +35 -0
  284. package/build/src/version.js +74 -0
  285. package/build/src/versioning-strategies/always-bump-major.d.ts +10 -0
  286. package/build/src/versioning-strategies/always-bump-major.js +28 -0
  287. package/build/src/versioning-strategies/always-bump-minor.d.ts +10 -0
  288. package/build/src/versioning-strategies/always-bump-minor.js +28 -0
  289. package/build/src/versioning-strategies/always-bump-patch.d.ts +11 -0
  290. package/build/src/versioning-strategies/always-bump-patch.js +29 -0
  291. package/build/src/versioning-strategies/default.d.ts +48 -0
  292. package/build/src/versioning-strategies/default.js +102 -0
  293. package/build/src/versioning-strategies/dependency-manifest.d.ts +15 -0
  294. package/build/src/versioning-strategies/dependency-manifest.js +103 -0
  295. package/build/src/versioning-strategies/java-add-snapshot.d.ts +13 -0
  296. package/build/src/versioning-strategies/java-add-snapshot.js +54 -0
  297. package/build/src/versioning-strategies/java-snapshot.d.ts +13 -0
  298. package/build/src/versioning-strategies/java-snapshot.js +70 -0
  299. package/build/src/versioning-strategies/prerelease.d.ts +20 -0
  300. package/build/src/versioning-strategies/prerelease.js +163 -0
  301. package/build/src/versioning-strategies/service-pack.d.ts +12 -0
  302. package/build/src/versioning-strategies/service-pack.js +47 -0
  303. package/build/src/versioning-strategy.d.ts +90 -0
  304. package/build/src/versioning-strategy.js +82 -0
  305. package/package.json +113 -4
  306. package/schemas/config.json +513 -0
  307. package/schemas/manifest.json +9 -0
  308. package/templates/commit.hbs +2 -0
  309. package/templates/header.hbs +9 -0
  310. package/templates/template.hbs +19 -0
@@ -0,0 +1,756 @@
1
+ "use strict";
2
+ // Copyright 2026 Google LLC
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.LocalGitHub = void 0;
17
+ const fs = require("fs");
18
+ const path = require("path");
19
+ const os = require("os");
20
+ const child_process = require("child_process");
21
+ const util = require("util");
22
+ const readline = require("readline");
23
+ const code_suggester_1 = require("./util/code-suggester");
24
+ const execFile = util.promisify(child_process.execFile);
25
+ const mkdtemp = fs.promises.mkdtemp;
26
+ const errors_1 = require("./errors");
27
+ const manifest_1 = require("./manifest");
28
+ const git_file_utils_1 = require("@google-automations/git-file-utils");
29
+ const composite_1 = require("./updaters/composite");
30
+ const github_api_1 = require("./github-api");
31
+ const logger_1 = require("./util/logger");
32
+ /**
33
+ * LocalGitHub implements the Scm interface using a local git clone
34
+ * where possible, and falling back to the GitHub API for other operations.
35
+ */
36
+ class LocalGitHub {
37
+ constructor(repository, gitHubApi, cloneDir, options) {
38
+ var _a;
39
+ this.repository = repository;
40
+ this.gitHubApi = gitHubApi;
41
+ this.cloneDir = cloneDir;
42
+ this.logger = (_a = options === null || options === void 0 ? void 0 : options.logger) !== null && _a !== void 0 ? _a : logger_1.logger;
43
+ }
44
+ static async create(options) {
45
+ var _a;
46
+ const gitHubApi = await github_api_1.GitHubApi.create(options);
47
+ const logger = (_a = options.logger) !== null && _a !== void 0 ? _a : logger_1.logger;
48
+ let repoDir;
49
+ if (options.localRepoPath) {
50
+ repoDir = options.localRepoPath;
51
+ let isGitRepo = false;
52
+ try {
53
+ await execFile('git', ['rev-parse', '--is-inside-work-tree'], {
54
+ cwd: repoDir,
55
+ });
56
+ isGitRepo = true;
57
+ }
58
+ catch (err) {
59
+ isGitRepo = false;
60
+ }
61
+ if (!isGitRepo) {
62
+ logger.info(`Path ${repoDir} is not a git clone. Cloning repository...`);
63
+ const url = `https://github.com/${gitHubApi.repository.owner}/${gitHubApi.repository.repo}.git`;
64
+ const args = ['clone', '--', url, repoDir];
65
+ if (options.cloneDepth) {
66
+ args.splice(1, 0, '--depth', options.cloneDepth.toString());
67
+ }
68
+ logger.debug(`Executing: git ${args.join(' ')}`);
69
+ await execFile('git', args);
70
+ }
71
+ else {
72
+ logger.info(`Using existing local repository at ${repoDir}...`);
73
+ }
74
+ const branch = gitHubApi.repository.defaultBranch;
75
+ const fetchArgs = ['fetch', 'origin'];
76
+ if (options.cloneDepth) {
77
+ fetchArgs.push('--depth', options.cloneDepth.toString());
78
+ }
79
+ logger.debug(`Executing: git ${fetchArgs.join(' ')}`);
80
+ await execFile('git', fetchArgs, { cwd: repoDir });
81
+ logger.debug(`Executing: git checkout ${branch}`);
82
+ await execFile('git', ['checkout', branch], { cwd: repoDir });
83
+ logger.debug(`Executing: git reset --hard origin/${branch}`);
84
+ await execFile('git', ['reset', '--hard', `origin/${branch}`], {
85
+ cwd: repoDir,
86
+ });
87
+ }
88
+ else {
89
+ const tempDir = await mkdtemp(path.join(os.tmpdir(), 'release-please-'));
90
+ logger.info(`Cloning repository to ${tempDir}...`);
91
+ const url = `https://github.com/${gitHubApi.repository.owner}/${gitHubApi.repository.repo}.git`;
92
+ const args = ['clone', '--', url, tempDir];
93
+ if (options.cloneDepth) {
94
+ args.splice(1, 0, '--depth', options.cloneDepth.toString());
95
+ }
96
+ logger.debug(`Executing: git ${args.join(' ')}`);
97
+ await execFile('git', args);
98
+ repoDir = tempDir;
99
+ }
100
+ return new LocalGitHub(gitHubApi.repository, gitHubApi, repoDir, {
101
+ logger: options.logger,
102
+ });
103
+ }
104
+ /**
105
+ * Fetch the contents of a file from the configured branch
106
+ *
107
+ * @param {string} path The path to the file in the repository
108
+ * @returns {GitHubFileContents}
109
+ * @throws {GitHubAPIError} on other API errors
110
+ */
111
+ async getFileContents(path) {
112
+ return await this.getFileContentsOnBranch(path, this.repository.defaultBranch);
113
+ }
114
+ async execGitStream(args, callback) {
115
+ return new Promise((resolve, reject) => {
116
+ const child = child_process.spawn('git', args, { cwd: this.cloneDir });
117
+ let stderr = '';
118
+ child.stderr.on('data', data => {
119
+ stderr += data;
120
+ });
121
+ const rl = readline.createInterface({
122
+ input: child.stdout,
123
+ crlfDelay: Infinity,
124
+ });
125
+ rl.on('line', callback);
126
+ child.on('close', code => {
127
+ if (code !== 0) {
128
+ reject(new Error(`Command failed ${code}: ${stderr}`));
129
+ }
130
+ else {
131
+ resolve();
132
+ }
133
+ });
134
+ });
135
+ }
136
+ async ensureRef(ref) {
137
+ try {
138
+ await execFile('git', ['rev-parse', '--verify', ref], {
139
+ cwd: this.cloneDir,
140
+ });
141
+ return ref;
142
+ }
143
+ catch (err) {
144
+ this.logger.debug(`Ref ${ref} not found locally, trying to fetch from origin...`);
145
+ try {
146
+ await execFile('git', ['fetch', 'origin', '--', ref], {
147
+ cwd: this.cloneDir,
148
+ });
149
+ return 'FETCH_HEAD';
150
+ }
151
+ catch (fetchErr) {
152
+ throw err; // Throw original error if fetch fails
153
+ }
154
+ }
155
+ }
156
+ /**
157
+ * Fetch the contents of a file
158
+ *
159
+ * @param {string} path The path to the file in the repository
160
+ * @param {string} branch The branch to fetch from
161
+ * @returns {GitHubFileContents}
162
+ * @throws {FileNotFoundError} if the file cannot be found
163
+ * @throws {GitHubAPIError} on other API errors
164
+ */
165
+ async getFileContentsOnBranch(path, branch) {
166
+ this.logger.debug(`Fetching file contents for file ${path} on branch ${branch}`);
167
+ const ref = await this.ensureRef(branch);
168
+ const lsTreeResult = await execFile('git', ['ls-tree', ref, path], {
169
+ cwd: this.cloneDir,
170
+ });
171
+ if (!lsTreeResult.stdout.trim()) {
172
+ throw new errors_1.FileNotFoundError(path);
173
+ }
174
+ const [info] = lsTreeResult.stdout.split('\t');
175
+ const [mode, , sha] = info.split(' ');
176
+ const { stdout } = await execFile('git', ['show', `${ref}:${path}`], {
177
+ cwd: this.cloneDir,
178
+ maxBuffer: 100 * 1024 * 1024,
179
+ });
180
+ return {
181
+ content: Buffer.from(stdout).toString('base64'),
182
+ parsedContent: stdout,
183
+ sha,
184
+ mode,
185
+ };
186
+ }
187
+ async getFileJson(path, branch) {
188
+ const content = await this.getFileContentsOnBranch(path, branch);
189
+ return JSON.parse(content.parsedContent);
190
+ }
191
+ /**
192
+ * Returns a list of paths to all files with a given name.
193
+ *
194
+ * If a prefix is specified, only return paths that match
195
+ * the provided prefix.
196
+ *
197
+ * @param filename The name of the file to find
198
+ * @param prefix Optional path prefix used to filter results
199
+ * @returns {string[]} List of file paths
200
+ * @throws {GitHubAPIError} on an API error
201
+ */
202
+ async findFilesByFilename(filename, prefix) {
203
+ return this.findFilesByFilenameAndRef(filename, this.repository.defaultBranch, prefix);
204
+ }
205
+ /**
206
+ * Returns a list of paths to all files with a given name.
207
+ *
208
+ * If a prefix is specified, only return paths that match
209
+ * the provided prefix.
210
+ *
211
+ * @param filename The name of the file to find
212
+ * @param ref Git reference to search files in
213
+ * @param prefix Optional path prefix used to filter results
214
+ * @throws {GitHubAPIError} on an API error
215
+ */
216
+ async findFilesByFilenameAndRef(filename, ref, prefix) {
217
+ this.logger.debug(`Looking in local clone for file ${filename} with ref ${ref} and prefix '${prefix}'`);
218
+ let normalizedPrefix = prefix
219
+ ? prefix.replace(/^[/\\]/, '').replace(/[/\\]$/, '')
220
+ : '';
221
+ if (normalizedPrefix === manifest_1.ROOT_PROJECT_PATH) {
222
+ normalizedPrefix = '';
223
+ }
224
+ const treePath = normalizedPrefix ? `${normalizedPrefix}/` : '.';
225
+ const resolvedRef = await this.ensureRef(ref);
226
+ this.logger.trace(`Executing stream: git ls-tree -r --name-only ${resolvedRef} ${treePath}`);
227
+ const matchedPaths = [];
228
+ await this.execGitStream(['ls-tree', '-r', '--name-only', resolvedRef, treePath], line => {
229
+ const trimmed = line.trim();
230
+ if (trimmed && path.posix.basename(trimmed) === filename) {
231
+ matchedPaths.push(trimmed);
232
+ }
233
+ });
234
+ if (normalizedPrefix) {
235
+ return matchedPaths
236
+ .map(p => {
237
+ if (p === normalizedPrefix)
238
+ return '';
239
+ if (p.startsWith(`${normalizedPrefix}/`)) {
240
+ return p.slice(normalizedPrefix.length + 1);
241
+ }
242
+ return p;
243
+ })
244
+ .filter(p => p !== '');
245
+ }
246
+ return matchedPaths;
247
+ }
248
+ /**
249
+ * Returns a list of paths to all files matching a glob pattern.
250
+ *
251
+ * If a prefix is specified, only return paths that match
252
+ * the provided prefix.
253
+ *
254
+ * @param glob The glob to match
255
+ * @param prefix Optional path prefix used to filter results
256
+ * @returns {string[]} List of file paths
257
+ * @throws {GitHubAPIError} on an API error
258
+ */
259
+ async findFilesByGlob(glob, prefix) {
260
+ return this.findFilesByGlobAndRef(glob, this.repository.defaultBranch, prefix);
261
+ }
262
+ /**
263
+ * Returns a list of paths to all files matching a glob pattern.
264
+ *
265
+ * If a prefix is specified, only return paths that match
266
+ * the provided prefix.
267
+ *
268
+ * @param glob The glob to match
269
+ * @param ref Git reference to search files in
270
+ * @param prefix Optional path prefix used to filter results
271
+ * @throws {GitHubAPIError} on an API error
272
+ */
273
+ async findFilesByGlobAndRef(glob, ref, prefix) {
274
+ this.logger.debug(`Looking in local clone for file matching glob ${glob} with ref ${ref} and prefix '${prefix}'`);
275
+ let normalizedPrefix = prefix
276
+ ? prefix.replace(/^[/\\]/, '').replace(/[/\\]$/, '')
277
+ : '';
278
+ if (normalizedPrefix === manifest_1.ROOT_PROJECT_PATH) {
279
+ normalizedPrefix = '';
280
+ }
281
+ const treePath = normalizedPrefix ? `${normalizedPrefix}/` : '.';
282
+ const resolvedRef = await this.ensureRef(ref);
283
+ const files = [];
284
+ const dirs = new Set();
285
+ await this.execGitStream(['ls-tree', '-r', '--name-only', resolvedRef, treePath], line => {
286
+ const trimmed = line.trim();
287
+ if (trimmed) {
288
+ files.push(trimmed);
289
+ let dir = path.posix.dirname(trimmed);
290
+ while (dir !== '.' && dir !== '/') {
291
+ dirs.add(dir);
292
+ dir = path.posix.dirname(dir);
293
+ }
294
+ }
295
+ });
296
+ const allPaths = [...files, ...dirs];
297
+ // Make paths relative to prefix if provided
298
+ let relativePaths = allPaths;
299
+ if (normalizedPrefix) {
300
+ relativePaths = allPaths
301
+ .map(p => {
302
+ if (p === normalizedPrefix)
303
+ return '';
304
+ if (p.startsWith(`${normalizedPrefix}/`)) {
305
+ return p.slice(normalizedPrefix.length + 1);
306
+ }
307
+ return p;
308
+ })
309
+ .filter(p => p !== '');
310
+ }
311
+ const regex = globToRegex(glob);
312
+ return relativePaths.filter(p => regex.test(p));
313
+ }
314
+ /**
315
+ * Returns a list of paths to all files with a given file
316
+ * extension.
317
+ *
318
+ * If a prefix is specified, only return paths that match
319
+ * the provided prefix.
320
+ *
321
+ * @param extension The file extension used to filter results.
322
+ * Example: `js`, `java`
323
+ * @param prefix Optional path prefix used to filter results
324
+ * @returns {string[]} List of file paths
325
+ * @throws {GitHubAPIError} on an API error
326
+ */
327
+ async findFilesByExtension(extension, prefix) {
328
+ return this.findFilesByExtensionAndRef(extension, this.repository.defaultBranch, prefix);
329
+ }
330
+ /**
331
+ * Returns a list of paths to all files with a given file
332
+ * extension.
333
+ *
334
+ * If a prefix is specified, only return paths that match
335
+ * the provided prefix.
336
+ *
337
+ * @param extension The file extension used to filter results.
338
+ * Example: `js`, `java`
339
+ * @param ref Git reference to search files in
340
+ * @param prefix Optional path prefix used to filter results
341
+ * @returns {string[]} List of file paths
342
+ * @throws {GitHubAPIError} on an API error
343
+ */
344
+ async findFilesByExtensionAndRef(extension, ref, prefix) {
345
+ this.logger.debug(`Looking in local clone for file matching extension ${extension} with ref ${ref} and prefix '${prefix}'`);
346
+ let normalizedPrefix = prefix
347
+ ? prefix.replace(/^[/\\]/, '').replace(/[/\\]$/, '')
348
+ : '';
349
+ if (normalizedPrefix === manifest_1.ROOT_PROJECT_PATH) {
350
+ normalizedPrefix = '';
351
+ }
352
+ const treePath = normalizedPrefix ? `${normalizedPrefix}/` : '.';
353
+ const resolvedRef = await this.ensureRef(ref);
354
+ const matchedPaths = [];
355
+ await this.execGitStream(['ls-tree', '-r', '--name-only', resolvedRef, treePath], line => {
356
+ const trimmed = line.trim();
357
+ if (trimmed && trimmed.endsWith(`.${extension}`)) {
358
+ matchedPaths.push(trimmed);
359
+ }
360
+ });
361
+ if (normalizedPrefix) {
362
+ return matchedPaths
363
+ .map(p => {
364
+ if (p === normalizedPrefix)
365
+ return '';
366
+ if (p.startsWith(`${normalizedPrefix}/`)) {
367
+ return p.slice(normalizedPrefix.length + 1);
368
+ }
369
+ return p;
370
+ })
371
+ .filter(p => p !== '');
372
+ }
373
+ return matchedPaths;
374
+ }
375
+ /**
376
+ * Returns the list of commits to the default branch after the provided filter
377
+ * query has been satified.
378
+ *
379
+ * @param {string} targetBranch Target branch of commit
380
+ * @param {CommitFilter} filter Callback function that returns whether a
381
+ * commit/pull request matches certain criteria
382
+ * @param {CommitIteratorOptions} options Query options
383
+ * @param {number} options.maxResults Limit the number of results searched.
384
+ * Defaults to unlimited.
385
+ * @param {boolean} options.backfillFiles If set, use the REST API for
386
+ * fetching the list of touched files in this commit. Defaults to `false`.
387
+ * @returns {Commit[]} List of commits to current branch
388
+ * @throws {GitHubAPIError} on an API error
389
+ */
390
+ async commitsSince(targetBranch, filter, options) {
391
+ const commits = [];
392
+ const generator = this.mergeCommitIterator(targetBranch, options);
393
+ for await (const commit of generator) {
394
+ if (filter(commit)) {
395
+ break;
396
+ }
397
+ commits.push(commit);
398
+ }
399
+ return commits;
400
+ }
401
+ /**
402
+ * Iterate through commit history with a max number of results scanned.
403
+ *
404
+ * @param {string} targetBranch target branch of commit
405
+ * @param {CommitIteratorOptions} options Query options
406
+ * @param {number} options.maxResults Limit the number of results searched.
407
+ * Defaults to unlimited.
408
+ * @param {boolean} options.backfillFiles If set, use the REST API for
409
+ * fetching the list of touched files in this commit. Defaults to `false`.
410
+ * @yields {Commit}
411
+ * @throws {GitHubAPIError} on an API error
412
+ */
413
+ async *mergeCommitIterator(targetBranch, options) {
414
+ var _a;
415
+ this.logger.debug(`Looking in local clone for commits on branch ${targetBranch}`);
416
+ const backfillFiles = (_a = options === null || options === void 0 ? void 0 : options.backfillFiles) !== null && _a !== void 0 ? _a : true;
417
+ let format = '---COMMIT_START---%n%H%n%B';
418
+ if (backfillFiles) {
419
+ format += '%n---FILES_START---';
420
+ }
421
+ const ref = await this.ensureRef(targetBranch);
422
+ const args = ['log', ref, `--pretty=format:${format}`];
423
+ if (backfillFiles) {
424
+ args.push('--name-only');
425
+ }
426
+ if (options === null || options === void 0 ? void 0 : options.maxResults) {
427
+ args.push('-n', options.maxResults.toString());
428
+ }
429
+ const { stdout } = await execFile('git', args, {
430
+ cwd: this.cloneDir,
431
+ maxBuffer: 100 * 1024 * 1024,
432
+ });
433
+ const blocks = stdout.split('---COMMIT_START---\n');
434
+ for (const block of blocks) {
435
+ if (!block.trim())
436
+ continue;
437
+ let commitInfo = block;
438
+ let files = [];
439
+ if (backfillFiles) {
440
+ const parts = block.split('\n---FILES_START---\n');
441
+ commitInfo = parts[0];
442
+ if (parts[1]) {
443
+ files = parts[1]
444
+ .split('\n')
445
+ .map((f) => f.trim())
446
+ .filter((f) => f);
447
+ }
448
+ }
449
+ const lines = commitInfo.split('\n');
450
+ const sha = lines[0].trim();
451
+ const message = lines.slice(1).join('\n').trim();
452
+ if (!sha)
453
+ continue;
454
+ const commit = {
455
+ sha,
456
+ message,
457
+ files: backfillFiles ? files : undefined,
458
+ };
459
+ const subject = lines[1] ? lines[1].trim() : '';
460
+ let prNumber;
461
+ let headBranchName = '';
462
+ const squashMatch = subject.match(/\s\(#(\d+)\)$/);
463
+ const mergeMatch = subject.match(/^Merge pull request #(\d+) from (.*)$/);
464
+ if (squashMatch) {
465
+ prNumber = parseInt(squashMatch[1], 10);
466
+ }
467
+ else if (mergeMatch) {
468
+ prNumber = parseInt(mergeMatch[1], 10);
469
+ headBranchName = mergeMatch[2].trim();
470
+ }
471
+ if (prNumber) {
472
+ commit.pullRequest = {
473
+ sha,
474
+ number: prNumber,
475
+ title: subject.replace(/\s\(#(\d+)\)$/, ''),
476
+ body: message,
477
+ labels: [],
478
+ files: backfillFiles ? files : [],
479
+ baseBranchName: targetBranch,
480
+ headBranchName,
481
+ };
482
+ }
483
+ yield commit;
484
+ }
485
+ }
486
+ /**
487
+ * Iterate through merged pull requests with a max number of results scanned.
488
+ *
489
+ * @param {string} targetBranch The base branch of the pull request
490
+ * @param {string} status The status of the pull request
491
+ * @param {number} maxResults Limit the number of results searched. Defaults to
492
+ * unlimited.
493
+ * @param {boolean} includeFiles Whether to fetch the list of files included in
494
+ * the pull request. Defaults to `true`.
495
+ * @yields {PullRequest}
496
+ * @throws {GitHubAPIError} on an API error
497
+ */
498
+ async *pullRequestIterator(targetBranch, status, maxResults, includeFiles) {
499
+ yield* this.gitHubApi.pullRequestIterator(targetBranch, status, maxResults, includeFiles);
500
+ }
501
+ /**
502
+ * Iterate through releases with a max number of results scanned.
503
+ *
504
+ * @param {ReleaseIteratorOptions} options Query options
505
+ * @param {number} options.maxResults Limit the number of results searched.
506
+ * Defaults to unlimited.
507
+ * @yields {GitHubRelease}
508
+ * @throws {GitHubAPIError} on an API error
509
+ */
510
+ async *releaseIterator(options) {
511
+ yield* this.gitHubApi.releaseIterator(options);
512
+ }
513
+ /**
514
+ * Iterate through tags with a max number of results scanned.
515
+ *
516
+ * @param {TagIteratorOptions} options Query options
517
+ * @param {number} options.maxResults Limit the number of results searched.
518
+ * Defaults to unlimited.
519
+ * @yields {GitHubTag}
520
+ * @throws {GitHubAPIError} on an API error
521
+ */
522
+ async *tagIterator(options) {
523
+ const { stdout } = await execFile('git', [
524
+ 'for-each-ref',
525
+ '--sort=-version:refname',
526
+ 'refs/tags',
527
+ '--format=%(refname:short)|%(objectname)|%(*objectname)',
528
+ ], { cwd: this.cloneDir });
529
+ const maxResults = (options === null || options === void 0 ? void 0 : options.maxResults) || Number.MAX_SAFE_INTEGER;
530
+ let results = 0;
531
+ for (const line of stdout.split('\n')) {
532
+ if (!line)
533
+ continue;
534
+ const [name, objectSha, commitSha] = line.split('|');
535
+ const sha = commitSha || objectSha;
536
+ if (sha) {
537
+ yield { name, sha };
538
+ results++;
539
+ if (results >= maxResults)
540
+ break;
541
+ }
542
+ }
543
+ }
544
+ /**
545
+ * Open a pull request
546
+ *
547
+ * @param {PullRequest} pullRequest Pull request data to update
548
+ * @param {string} targetBranch The base branch of the pull request
549
+ * @param {string} message The commit message for the commit
550
+ * @param {Update[]} updates The files to update
551
+ * @param {CreatePullRequestOptions} options The pull request options
552
+ * @throws {GitHubAPIError} on an API error
553
+ */
554
+ async createPullRequest(pullRequest, targetBranch, message, updates, options) {
555
+ const changes = await this.buildChangeSet(updates, targetBranch);
556
+ const prNumber = await (0, code_suggester_1.createPullRequest)(this.gitHubApi.octokit, changes, {
557
+ upstreamOwner: this.repository.owner,
558
+ upstreamRepo: this.repository.repo,
559
+ title: pullRequest.title,
560
+ branch: pullRequest.headBranchName,
561
+ description: pullRequest.body,
562
+ primary: targetBranch,
563
+ force: true,
564
+ fork: !!(options === null || options === void 0 ? void 0 : options.fork),
565
+ message,
566
+ logger: this.logger,
567
+ draft: !!(options === null || options === void 0 ? void 0 : options.draft),
568
+ labels: pullRequest.labels,
569
+ });
570
+ if (prNumber === 0) {
571
+ this.logger.warn('no code changes detected, skipping pull request creation');
572
+ return {
573
+ headBranchName: pullRequest.headBranchName,
574
+ baseBranchName: targetBranch,
575
+ number: 0,
576
+ title: pullRequest.title,
577
+ body: pullRequest.body,
578
+ labels: pullRequest.labels,
579
+ files: [],
580
+ };
581
+ }
582
+ return await this.getPullRequest(prNumber);
583
+ }
584
+ /**
585
+ * Update a pull request's title and body.
586
+ * @param {number} number The pull request number
587
+ * @param {ReleasePullRequest} releasePullRequest Pull request data to update
588
+ * @param {string} targetBranch The target branch of the pull request
589
+ * @param {string} options.signoffUser Optional. Commit signoff message
590
+ * @param {boolean} options.fork Optional. Whether to open the pull request from
591
+ * a fork or not. Defaults to `false`
592
+ * @param {PullRequestOverflowHandler} options.pullRequestOverflowHandler Optional.
593
+ * Handles extra large pull request body messages.
594
+ */
595
+ async updatePullRequest(number, pullRequest, targetBranch, options) {
596
+ const changes = await this.buildChangeSet(pullRequest.updates, targetBranch);
597
+ const message = pullRequest.title.toString();
598
+ const title = pullRequest.title.toString();
599
+ const body = ((options === null || options === void 0 ? void 0 : options.pullRequestOverflowHandler)
600
+ ? await options.pullRequestOverflowHandler.handleOverflow(pullRequest)
601
+ : pullRequest.body)
602
+ .toString()
603
+ .slice(0, github_api_1.MAX_ISSUE_BODY_SIZE);
604
+ const prNumber = await (0, code_suggester_1.createPullRequest)(this.gitHubApi.octokit, changes, {
605
+ upstreamOwner: this.repository.owner,
606
+ upstreamRepo: this.repository.repo,
607
+ title,
608
+ branch: pullRequest.headRefName,
609
+ description: body,
610
+ primary: targetBranch,
611
+ force: true,
612
+ fork: (options === null || options === void 0 ? void 0 : options.fork) === false ? false : true,
613
+ message,
614
+ logger: this.logger,
615
+ draft: pullRequest.draft,
616
+ });
617
+ if (prNumber !== number) {
618
+ this.logger.warn(`updated code for ${prNumber}, but update requested for ${number}`);
619
+ }
620
+ return this.gitHubApi.updatePullRequest(number, title, body);
621
+ }
622
+ async getPullRequest(number) {
623
+ return await this.gitHubApi.getPullRequest(number);
624
+ }
625
+ /**
626
+ * Create a GitHub release
627
+ *
628
+ * @param {Release} release Release parameters
629
+ * @param {ReleaseOptions} options Release option parameters
630
+ * @throws {DuplicateReleaseError} if the release tag already exists
631
+ * @throws {GitHubAPIError} on other API errors
632
+ */
633
+ async createRelease(release, options) {
634
+ return await this.gitHubApi.createRelease(release, options);
635
+ }
636
+ /**
637
+ * Makes a comment on a issue/pull request.
638
+ *
639
+ * @param {string} comment - The body of the comment to post.
640
+ * @param {number} number - The issue or pull request number.
641
+ * @throws {GitHubAPIError} on an API error
642
+ */
643
+ async commentOnIssue(comment, number) {
644
+ return await this.gitHubApi.commentOnIssue(comment, number);
645
+ }
646
+ /**
647
+ * Removes labels from an issue/pull request.
648
+ *
649
+ * @param {string[]} labels The labels to remove.
650
+ * @param {number} number The issue/pull request number.
651
+ */
652
+ async removeIssueLabels(labels, number) {
653
+ return await this.gitHubApi.removeIssueLabels(labels, number);
654
+ }
655
+ /**
656
+ * Adds label to an issue/pull request.
657
+ *
658
+ * @param {string[]} labels The labels to add.
659
+ * @param {number} number The issue/pull request number.
660
+ */
661
+ async addIssueLabels(labels, number) {
662
+ return await this.gitHubApi.addIssueLabels(labels, number);
663
+ }
664
+ /**
665
+ * Generate release notes from GitHub at tag
666
+ * @param {string} tagName Name of new release tag
667
+ * @param {string} targetCommitish Target commitish for new tag
668
+ * @param {string} previousTag Optional. Name of previous tag to analyze commits since
669
+ */
670
+ async generateReleaseNotes(tagName, targetCommitish, previousTag) {
671
+ return await this.gitHubApi.generateReleaseNotes(tagName, targetCommitish, previousTag);
672
+ }
673
+ /**
674
+ * Create a single file on a new branch based on an existing
675
+ * branch. This will force-push to that branch.
676
+ * @param {string} filename Filename with path in the repository
677
+ * @param {string} contents Contents of the file
678
+ * @param {string} newBranchName Name of the new branch
679
+ * @param {string} baseBranchName Name of the base branch (where
680
+ * new branch is forked from)
681
+ * @returns {string} HTML URL of the new file
682
+ */
683
+ async createFileOnNewBranch(filename, contents, newBranchName, baseBranchName) {
684
+ return await this.gitHubApi.createFileOnNewBranch(filename, contents, newBranchName, baseBranchName);
685
+ }
686
+ /**
687
+ * Given a set of proposed updates, build a changeset to suggest.
688
+ *
689
+ * @param {Update[]} updates The proposed updates
690
+ * @param {string} defaultBranch The target branch
691
+ * @return {Changes} The changeset to suggest.
692
+ * @throws {GitHubAPIError} on an API error
693
+ */
694
+ async buildChangeSet(updates, defaultBranch) {
695
+ const mergedUpdates = (0, composite_1.mergeUpdates)(updates);
696
+ const changes = new Map();
697
+ for (const update of mergedUpdates) {
698
+ let content;
699
+ try {
700
+ content = await this.getFileContentsOnBranch(update.path, defaultBranch);
701
+ }
702
+ catch (err) {
703
+ if (!(err instanceof errors_1.FileNotFoundError))
704
+ throw err;
705
+ if (!update.createIfMissing) {
706
+ console.warn(`file ${update.path} did not exist`);
707
+ continue;
708
+ }
709
+ }
710
+ const newContents = update.updater.updateContent(content ? content.parsedContent : undefined);
711
+ if (newContents) {
712
+ changes.set(update.path, {
713
+ content: newContents,
714
+ originalContent: content ? content.parsedContent : null,
715
+ mode: content ? content.mode : git_file_utils_1.DEFAULT_FILE_MODE,
716
+ });
717
+ }
718
+ }
719
+ return changes;
720
+ }
721
+ }
722
+ exports.LocalGitHub = LocalGitHub;
723
+ function globToRegex(glob) {
724
+ let reg = '';
725
+ let i = 0;
726
+ while (i < glob.length) {
727
+ const c = glob[i];
728
+ if (c === '*') {
729
+ if (i + 1 < glob.length && glob[i + 1] === '*') {
730
+ if (i + 2 < glob.length && glob[i + 2] === '/') {
731
+ reg += '(?:.*\\/)?';
732
+ i += 2;
733
+ }
734
+ else {
735
+ reg += '.*';
736
+ i++;
737
+ }
738
+ }
739
+ else {
740
+ reg += '[^/]*';
741
+ }
742
+ }
743
+ else if (c === '?') {
744
+ reg += '[^/]';
745
+ }
746
+ else if (['.', '+', '^', '$', '{', '}', '(', ')', '|', '[', ']', '\\'].includes(c)) {
747
+ reg += '\\' + c;
748
+ }
749
+ else {
750
+ reg += c;
751
+ }
752
+ i++;
753
+ }
754
+ return new RegExp(`^${reg}$`);
755
+ }
756
+ //# sourceMappingURL=local-github.js.map