@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.
- package/LICENSE +202 -0
- package/README.md +280 -0
- package/build/src/bin/release-please.d.ts +22 -0
- package/build/src/bin/release-please.js +727 -0
- package/build/src/bootstrapper.d.ts +18 -0
- package/build/src/bootstrapper.js +64 -0
- package/build/src/changelog-notes/default.d.ts +15 -0
- package/build/src/changelog-notes/default.js +96 -0
- package/build/src/changelog-notes/github.d.ts +8 -0
- package/build/src/changelog-notes/github.js +29 -0
- package/build/src/changelog-notes.d.ts +22 -0
- package/build/src/changelog-notes.js +40 -0
- package/build/src/commit.d.ts +33 -0
- package/build/src/commit.js +422 -0
- package/build/src/errors/index.d.ts +36 -0
- package/build/src/errors/index.js +77 -0
- package/build/src/factories/changelog-notes-factory.d.ts +16 -0
- package/build/src/factories/changelog-notes-factory.js +44 -0
- package/build/src/factories/plugin-factory.d.ts +23 -0
- package/build/src/factories/plugin-factory.js +94 -0
- package/build/src/factories/versioning-strategy-factory.d.ts +16 -0
- package/build/src/factories/versioning-strategy-factory.js +52 -0
- package/build/src/factory.d.ts +18 -0
- package/build/src/factory.js +161 -0
- package/build/src/github-api.d.ts +260 -0
- package/build/src/github-api.js +714 -0
- package/build/src/github.d.ts +306 -0
- package/build/src/github.js +769 -0
- package/build/src/index.d.ts +17 -0
- package/build/src/index.js +41 -0
- package/build/src/local-github.d.ts +270 -0
- package/build/src/local-github.js +756 -0
- package/build/src/manifest.d.ts +370 -0
- package/build/src/manifest.js +1142 -0
- package/build/src/plugin.d.ts +37 -0
- package/build/src/plugin.js +57 -0
- package/build/src/plugins/cargo-workspace.d.ts +58 -0
- package/build/src/plugins/cargo-workspace.js +339 -0
- package/build/src/plugins/group-priority.d.ts +29 -0
- package/build/src/plugins/group-priority.js +82 -0
- package/build/src/plugins/linked-versions.d.ts +36 -0
- package/build/src/plugins/linked-versions.js +137 -0
- package/build/src/plugins/maven-workspace.d.ts +81 -0
- package/build/src/plugins/maven-workspace.js +431 -0
- package/build/src/plugins/merge.d.ts +27 -0
- package/build/src/plugins/merge.js +99 -0
- package/build/src/plugins/node-workspace.d.ts +50 -0
- package/build/src/plugins/node-workspace.js +352 -0
- package/build/src/plugins/sentence-case.d.ts +19 -0
- package/build/src/plugins/sentence-case.js +80 -0
- package/build/src/plugins/workspace.d.ts +173 -0
- package/build/src/plugins/workspace.js +308 -0
- package/build/src/pull-request.d.ts +11 -0
- package/build/src/pull-request.js +16 -0
- package/build/src/release-pull-request.d.ts +14 -0
- package/build/src/release-pull-request.js +16 -0
- package/build/src/release.d.ts +7 -0
- package/build/src/release.js +16 -0
- package/build/src/repository.d.ts +5 -0
- package/build/src/repository.js +16 -0
- package/build/src/scm.d.ts +80 -0
- package/build/src/scm.js +16 -0
- package/build/src/strategies/base.d.ts +162 -0
- package/build/src/strategies/base.js +494 -0
- package/build/src/strategies/bazel.d.ts +7 -0
- package/build/src/strategies/bazel.js +49 -0
- package/build/src/strategies/dart.d.ts +8 -0
- package/build/src/strategies/dart.js +73 -0
- package/build/src/strategies/dotnet-yoshi.d.ts +13 -0
- package/build/src/strategies/dotnet-yoshi.js +109 -0
- package/build/src/strategies/elixir.d.ts +5 -0
- package/build/src/strategies/elixir.js +46 -0
- package/build/src/strategies/expo.d.ts +15 -0
- package/build/src/strategies/expo.js +51 -0
- package/build/src/strategies/go-librarian.d.ts +11 -0
- package/build/src/strategies/go-librarian.js +84 -0
- package/build/src/strategies/go-yoshi.d.ts +14 -0
- package/build/src/strategies/go-yoshi.js +168 -0
- package/build/src/strategies/go.d.ts +7 -0
- package/build/src/strategies/go.js +53 -0
- package/build/src/strategies/helm.d.ts +8 -0
- package/build/src/strategies/helm.js +73 -0
- package/build/src/strategies/java-yoshi-mono-repo.d.ts +22 -0
- package/build/src/strategies/java-yoshi-mono-repo.js +308 -0
- package/build/src/strategies/java-yoshi.d.ts +20 -0
- package/build/src/strategies/java-yoshi.js +210 -0
- package/build/src/strategies/java.d.ts +28 -0
- package/build/src/strategies/java.js +176 -0
- package/build/src/strategies/krm-blueprint.d.ts +7 -0
- package/build/src/strategies/krm-blueprint.js +65 -0
- package/build/src/strategies/maven.d.ts +9 -0
- package/build/src/strategies/maven.js +56 -0
- package/build/src/strategies/node-librarian.d.ts +10 -0
- package/build/src/strategies/node-librarian.js +121 -0
- package/build/src/strategies/node.d.ts +10 -0
- package/build/src/strategies/node.js +111 -0
- package/build/src/strategies/ocaml.d.ts +5 -0
- package/build/src/strategies/ocaml.js +86 -0
- package/build/src/strategies/php-librarian.d.ts +6 -0
- package/build/src/strategies/php-librarian.js +35 -0
- package/build/src/strategies/php-yoshi.d.ts +13 -0
- package/build/src/strategies/php-yoshi.js +255 -0
- package/build/src/strategies/php.d.ts +6 -0
- package/build/src/strategies/php.js +76 -0
- package/build/src/strategies/python-librarian.d.ts +6 -0
- package/build/src/strategies/python-librarian.js +35 -0
- package/build/src/strategies/python.d.ts +11 -0
- package/build/src/strategies/python.js +175 -0
- package/build/src/strategies/r.d.ts +8 -0
- package/build/src/strategies/r.js +67 -0
- package/build/src/strategies/ruby-librarian.d.ts +6 -0
- package/build/src/strategies/ruby-librarian.js +35 -0
- package/build/src/strategies/ruby-yoshi.d.ts +13 -0
- package/build/src/strategies/ruby-yoshi.js +97 -0
- package/build/src/strategies/ruby.d.ts +9 -0
- package/build/src/strategies/ruby.js +71 -0
- package/build/src/strategies/rust.d.ts +17 -0
- package/build/src/strategies/rust.js +149 -0
- package/build/src/strategies/sfdx.d.ts +9 -0
- package/build/src/strategies/sfdx.js +67 -0
- package/build/src/strategies/simple.d.ts +7 -0
- package/build/src/strategies/simple.js +51 -0
- package/build/src/strategies/terraform-module.d.ts +7 -0
- package/build/src/strategies/terraform-module.js +90 -0
- package/build/src/strategy.d.ts +68 -0
- package/build/src/strategy.js +16 -0
- package/build/src/update.d.ts +24 -0
- package/build/src/update.js +16 -0
- package/build/src/updaters/base-xml.d.ts +19 -0
- package/build/src/updaters/base-xml.js +43 -0
- package/build/src/updaters/bazel/module-bazel.d.ts +7 -0
- package/build/src/updaters/bazel/module-bazel.js +33 -0
- package/build/src/updaters/changelog-json.d.ts +29 -0
- package/build/src/updaters/changelog-json.js +100 -0
- package/build/src/updaters/changelog.d.ts +13 -0
- package/build/src/updaters/changelog.js +55 -0
- package/build/src/updaters/composite.d.ts +20 -0
- package/build/src/updaters/composite.js +65 -0
- package/build/src/updaters/dart/pubspec-yaml.d.ts +13 -0
- package/build/src/updaters/dart/pubspec-yaml.js +50 -0
- package/build/src/updaters/default.d.ts +21 -0
- package/build/src/updaters/default.js +36 -0
- package/build/src/updaters/dotnet/apis.d.ts +18 -0
- package/build/src/updaters/dotnet/apis.js +45 -0
- package/build/src/updaters/dotnet/csproj.d.ts +12 -0
- package/build/src/updaters/dotnet/csproj.js +33 -0
- package/build/src/updaters/elixir/elixir-mix-exs.d.ts +13 -0
- package/build/src/updaters/elixir/elixir-mix-exs.js +42 -0
- package/build/src/updaters/expo/app-json.d.ts +31 -0
- package/build/src/updaters/expo/app-json.js +67 -0
- package/build/src/updaters/generic-json.d.ts +14 -0
- package/build/src/updaters/generic-json.js +54 -0
- package/build/src/updaters/generic-toml.d.ts +21 -0
- package/build/src/updaters/generic-toml.js +66 -0
- package/build/src/updaters/generic-xml.d.ts +8 -0
- package/build/src/updaters/generic-xml.js +38 -0
- package/build/src/updaters/generic-yaml.d.ts +23 -0
- package/build/src/updaters/generic-yaml.js +85 -0
- package/build/src/updaters/generic.d.ts +54 -0
- package/build/src/updaters/generic.js +187 -0
- package/build/src/updaters/go/version-go.d.ts +4 -0
- package/build/src/updaters/go/version-go.js +24 -0
- package/build/src/updaters/helm/chart-yaml.d.ts +13 -0
- package/build/src/updaters/helm/chart-yaml.js +41 -0
- package/build/src/updaters/java/java-released.d.ts +28 -0
- package/build/src/updaters/java/java-released.js +59 -0
- package/build/src/updaters/java/java-update.d.ts +21 -0
- package/build/src/updaters/java/java-update.js +80 -0
- package/build/src/updaters/java/pom-xml.d.ts +29 -0
- package/build/src/updaters/java/pom-xml.js +135 -0
- package/build/src/updaters/java/versions-manifest.d.ts +19 -0
- package/build/src/updaters/java/versions-manifest.js +71 -0
- package/build/src/updaters/krm/krm-blueprint-version.d.ts +13 -0
- package/build/src/updaters/krm/krm-blueprint-version.js +46 -0
- package/build/src/updaters/librarian-yaml.d.ts +45 -0
- package/build/src/updaters/librarian-yaml.js +149 -0
- package/build/src/updaters/node/package-json.d.ts +46 -0
- package/build/src/updaters/node/package-json.js +106 -0
- package/build/src/updaters/node/package-lock-json.d.ts +14 -0
- package/build/src/updaters/node/package-lock-json.js +83 -0
- package/build/src/updaters/node/samples-package-json.d.ts +24 -0
- package/build/src/updaters/node/samples-package-json.js +49 -0
- package/build/src/updaters/ocaml/dune-project.d.ts +13 -0
- package/build/src/updaters/ocaml/dune-project.js +37 -0
- package/build/src/updaters/ocaml/esy-json.d.ts +13 -0
- package/build/src/updaters/ocaml/esy-json.js +37 -0
- package/build/src/updaters/ocaml/opam.d.ts +13 -0
- package/build/src/updaters/ocaml/opam.js +37 -0
- package/build/src/updaters/php/php-client-version.d.ts +12 -0
- package/build/src/updaters/php/php-client-version.js +32 -0
- package/build/src/updaters/php/root-composer-update-packages.d.ts +13 -0
- package/build/src/updaters/php/root-composer-update-packages.js +60 -0
- package/build/src/updaters/python/pyproject-toml.d.ts +29 -0
- package/build/src/updaters/python/pyproject-toml.js +53 -0
- package/build/src/updaters/python/python-file-with-version.d.ts +12 -0
- package/build/src/updaters/python/python-file-with-version.js +32 -0
- package/build/src/updaters/python/setup-cfg.d.ts +12 -0
- package/build/src/updaters/python/setup-cfg.js +32 -0
- package/build/src/updaters/python/setup-py.d.ts +12 -0
- package/build/src/updaters/python/setup-py.js +32 -0
- package/build/src/updaters/r/description.d.ts +12 -0
- package/build/src/updaters/r/description.js +32 -0
- package/build/src/updaters/r/news.d.ts +12 -0
- package/build/src/updaters/r/news.js +49 -0
- package/build/src/updaters/raw-content.d.ts +19 -0
- package/build/src/updaters/raw-content.js +39 -0
- package/build/src/updaters/release-please-config.d.ts +8 -0
- package/build/src/updaters/release-please-config.js +80 -0
- package/build/src/updaters/release-please-manifest.d.ts +4 -0
- package/build/src/updaters/release-please-manifest.js +34 -0
- package/build/src/updaters/ruby/common.d.ts +17 -0
- package/build/src/updaters/ruby/common.js +46 -0
- package/build/src/updaters/ruby/gemfile-lock.d.ts +24 -0
- package/build/src/updaters/ruby/gemfile-lock.js +53 -0
- package/build/src/updaters/ruby/version-rb.d.ts +12 -0
- package/build/src/updaters/ruby/version-rb.js +34 -0
- package/build/src/updaters/rust/cargo-lock.d.ts +16 -0
- package/build/src/updaters/rust/cargo-lock.js +64 -0
- package/build/src/updaters/rust/cargo-toml.d.ts +13 -0
- package/build/src/updaters/rust/cargo-toml.js +89 -0
- package/build/src/updaters/rust/common.d.ts +54 -0
- package/build/src/updaters/rust/common.js +35 -0
- package/build/src/updaters/sfdx/sfdx-project-json.d.ts +21 -0
- package/build/src/updaters/sfdx/sfdx-project-json.js +41 -0
- package/build/src/updaters/terraform/metadata-version.d.ts +13 -0
- package/build/src/updaters/terraform/metadata-version.js +37 -0
- package/build/src/updaters/terraform/module-version.d.ts +13 -0
- package/build/src/updaters/terraform/module-version.js +37 -0
- package/build/src/updaters/terraform/readme.d.ts +12 -0
- package/build/src/updaters/terraform/readme.js +32 -0
- package/build/src/util/branch-name.d.ts +20 -0
- package/build/src/util/branch-name.js +225 -0
- package/build/src/util/code-suggester/default-options-handler.d.ts +10 -0
- package/build/src/util/code-suggester/default-options-handler.js +45 -0
- package/build/src/util/code-suggester/errors.d.ts +4 -0
- package/build/src/util/code-suggester/errors.js +24 -0
- package/build/src/util/code-suggester/github/branch.d.ts +45 -0
- package/build/src/util/code-suggester/github/branch.js +118 -0
- package/build/src/util/code-suggester/github/commit-and-push.d.ts +51 -0
- package/build/src/util/code-suggester/github/commit-and-push.js +141 -0
- package/build/src/util/code-suggester/github/create-commit.d.ts +20 -0
- package/build/src/util/code-suggester/github/create-commit.js +60 -0
- package/build/src/util/code-suggester/github/fork.d.ts +15 -0
- package/build/src/util/code-suggester/github/fork.js +48 -0
- package/build/src/util/code-suggester/github/labels.d.ts +14 -0
- package/build/src/util/code-suggester/github/labels.js +42 -0
- package/build/src/util/code-suggester/github/open-pull-request.d.ts +16 -0
- package/build/src/util/code-suggester/github/open-pull-request.js +56 -0
- package/build/src/util/code-suggester/index.d.ts +28 -0
- package/build/src/util/code-suggester/index.js +110 -0
- package/build/src/util/code-suggester/logger.d.ts +4 -0
- package/build/src/util/code-suggester/logger.js +37 -0
- package/build/src/util/code-suggester/types.d.ts +109 -0
- package/build/src/util/code-suggester/types.js +30 -0
- package/build/src/util/coerce-option.d.ts +1 -0
- package/build/src/util/coerce-option.js +40 -0
- package/build/src/util/commit-exclude.d.ts +10 -0
- package/build/src/util/commit-exclude.js +49 -0
- package/build/src/util/commit-split.d.ts +26 -0
- package/build/src/util/commit-split.js +100 -0
- package/build/src/util/commit-utils.d.ts +1 -0
- package/build/src/util/commit-utils.js +34 -0
- package/build/src/util/filter-commits.d.ts +12 -0
- package/build/src/util/filter-commits.js +59 -0
- package/build/src/util/indent-commit.d.ts +2 -0
- package/build/src/util/indent-commit.js +39 -0
- package/build/src/util/json-stringify.d.ts +1 -0
- package/build/src/util/json-stringify.js +22 -0
- package/build/src/util/logger.d.ts +24 -0
- package/build/src/util/logger.js +54 -0
- package/build/src/util/pull-request-body.d.ts +25 -0
- package/build/src/util/pull-request-body.js +147 -0
- package/build/src/util/pull-request-overflow-handler.d.ts +54 -0
- package/build/src/util/pull-request-overflow-handler.js +78 -0
- package/build/src/util/pull-request-title.d.ts +22 -0
- package/build/src/util/pull-request-title.js +146 -0
- package/build/src/util/signoff-commit-message.d.ts +1 -0
- package/build/src/util/signoff-commit-message.js +35 -0
- package/build/src/util/tag-name.d.ts +10 -0
- package/build/src/util/tag-name.js +42 -0
- package/build/src/util/toml-edit.d.ts +16 -0
- package/build/src/util/toml-edit.js +126 -0
- package/build/src/version.d.ts +35 -0
- package/build/src/version.js +74 -0
- package/build/src/versioning-strategies/always-bump-major.d.ts +10 -0
- package/build/src/versioning-strategies/always-bump-major.js +28 -0
- package/build/src/versioning-strategies/always-bump-minor.d.ts +10 -0
- package/build/src/versioning-strategies/always-bump-minor.js +28 -0
- package/build/src/versioning-strategies/always-bump-patch.d.ts +11 -0
- package/build/src/versioning-strategies/always-bump-patch.js +29 -0
- package/build/src/versioning-strategies/default.d.ts +48 -0
- package/build/src/versioning-strategies/default.js +102 -0
- package/build/src/versioning-strategies/dependency-manifest.d.ts +15 -0
- package/build/src/versioning-strategies/dependency-manifest.js +103 -0
- package/build/src/versioning-strategies/java-add-snapshot.d.ts +13 -0
- package/build/src/versioning-strategies/java-add-snapshot.js +54 -0
- package/build/src/versioning-strategies/java-snapshot.d.ts +13 -0
- package/build/src/versioning-strategies/java-snapshot.js +70 -0
- package/build/src/versioning-strategies/prerelease.d.ts +20 -0
- package/build/src/versioning-strategies/prerelease.js +163 -0
- package/build/src/versioning-strategies/service-pack.d.ts +12 -0
- package/build/src/versioning-strategies/service-pack.js +47 -0
- package/build/src/versioning-strategy.d.ts +90 -0
- package/build/src/versioning-strategy.js +82 -0
- package/package.json +113 -4
- package/schemas/config.json +513 -0
- package/schemas/manifest.json +9 -0
- package/templates/commit.hbs +2 -0
- package/templates/header.hbs +9 -0
- package/templates/template.hbs +19 -0
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 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.sleepInMs = exports.GitHub = void 0;
|
|
17
|
+
const request_error_1 = require("@octokit/request-error");
|
|
18
|
+
const code_suggester_1 = require("./util/code-suggester");
|
|
19
|
+
const errors_1 = require("./errors");
|
|
20
|
+
const MAX_ISSUE_BODY_SIZE = 65536;
|
|
21
|
+
const MAX_SLEEP_SECONDS = 20;
|
|
22
|
+
const logger_1 = require("./util/logger");
|
|
23
|
+
const manifest_1 = require("./manifest");
|
|
24
|
+
const github_api_1 = require("./github-api");
|
|
25
|
+
const signoff_commit_message_1 = require("./util/signoff-commit-message");
|
|
26
|
+
const git_file_utils_1 = require("@google-automations/git-file-utils");
|
|
27
|
+
const composite_1 = require("./updaters/composite");
|
|
28
|
+
class GitHub {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
var _a;
|
|
31
|
+
/**
|
|
32
|
+
* Get the list of file paths modified in a given commit.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} sha The commit SHA
|
|
35
|
+
* @returns {string[]} File paths
|
|
36
|
+
* @throws {GitHubAPIError} on an API error
|
|
37
|
+
*/
|
|
38
|
+
this.getCommitFiles = wrapAsync(async (sha) => {
|
|
39
|
+
this.logger.debug(`Backfilling file list for commit: ${sha}`);
|
|
40
|
+
const files = [];
|
|
41
|
+
for await (const resp of this.octokit.paginate.iterator('GET /repos/{owner}/{repo}/commits/{ref}', {
|
|
42
|
+
owner: this.repository.owner,
|
|
43
|
+
repo: this.repository.repo,
|
|
44
|
+
ref: sha,
|
|
45
|
+
})) {
|
|
46
|
+
// Paginate plugin doesn't have types for listing files on a commit
|
|
47
|
+
const data = resp.data;
|
|
48
|
+
for (const f of data.files || []) {
|
|
49
|
+
if (f.filename) {
|
|
50
|
+
files.push(f.filename);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (files.length >= 3000) {
|
|
55
|
+
this.logger.warn(`Found ${files.length} files. This may not include all the files.`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.logger.debug(`Found ${files.length} files`);
|
|
59
|
+
}
|
|
60
|
+
return files;
|
|
61
|
+
});
|
|
62
|
+
this.graphqlRequest = wrapAsync(async (opts, options) => {
|
|
63
|
+
var _a;
|
|
64
|
+
let maxRetries = (_a = options === null || options === void 0 ? void 0 : options.maxRetries) !== null && _a !== void 0 ? _a : 5;
|
|
65
|
+
let seconds = 1;
|
|
66
|
+
while (maxRetries >= 0) {
|
|
67
|
+
try {
|
|
68
|
+
const response = await this.graphql(opts);
|
|
69
|
+
if (response) {
|
|
70
|
+
return response;
|
|
71
|
+
}
|
|
72
|
+
this.logger.trace('no GraphQL response, retrying');
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
if (err.status !== 502) {
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
if (maxRetries === 0) {
|
|
79
|
+
this.logger.warn('ran out of retries and response is required');
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
this.logger.info(`received 502 error, ${maxRetries} attempts remaining`);
|
|
83
|
+
if (typeof opts.num === 'number') {
|
|
84
|
+
if (maxRetries === 1) {
|
|
85
|
+
this.logger.info('last retry, forcing batch size to 1');
|
|
86
|
+
opts.num = 1;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const nextNum = Math.floor(opts.num / 2);
|
|
90
|
+
if (nextNum >= 1) {
|
|
91
|
+
this.logger.info(`halving batch size from ${opts.num} to ${nextNum}`);
|
|
92
|
+
opts.num = nextNum;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
maxRetries -= 1;
|
|
98
|
+
if (maxRetries >= 0) {
|
|
99
|
+
this.logger.trace(`sleeping ${seconds} seconds`);
|
|
100
|
+
await (0, exports.sleepInMs)(1000 * seconds);
|
|
101
|
+
seconds = Math.min(seconds * 2, MAX_SLEEP_SECONDS);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
this.logger.trace('ran out of retries');
|
|
105
|
+
return undefined;
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* Returns a list of paths to all files with a given name.
|
|
109
|
+
*
|
|
110
|
+
* If a prefix is specified, only return paths that match
|
|
111
|
+
* the provided prefix.
|
|
112
|
+
*
|
|
113
|
+
* @param filename The name of the file to find
|
|
114
|
+
* @param ref Git reference to search files in
|
|
115
|
+
* @param prefix Optional path prefix used to filter results
|
|
116
|
+
* @throws {GitHubAPIError} on an API error
|
|
117
|
+
*/
|
|
118
|
+
this.findFilesByFilenameAndRef = wrapAsync(async (filename, ref, prefix) => {
|
|
119
|
+
if (prefix) {
|
|
120
|
+
prefix = normalizePrefix(prefix);
|
|
121
|
+
}
|
|
122
|
+
this.logger.debug(`finding files by filename: ${filename}, ref: ${ref}, prefix: ${prefix}`);
|
|
123
|
+
return await this.fileCache.findFilesByFilename(filename, ref, prefix);
|
|
124
|
+
});
|
|
125
|
+
/**
|
|
126
|
+
* Returns a list of paths to all files matching a glob pattern.
|
|
127
|
+
*
|
|
128
|
+
* If a prefix is specified, only return paths that match
|
|
129
|
+
* the provided prefix.
|
|
130
|
+
*
|
|
131
|
+
* @param glob The glob to match
|
|
132
|
+
* @param ref Git reference to search files in
|
|
133
|
+
* @param prefix Optional path prefix used to filter results
|
|
134
|
+
* @throws {GitHubAPIError} on an API error
|
|
135
|
+
*/
|
|
136
|
+
this.findFilesByGlobAndRef = wrapAsync(async (glob, ref, prefix) => {
|
|
137
|
+
if (prefix) {
|
|
138
|
+
prefix = normalizePrefix(prefix);
|
|
139
|
+
}
|
|
140
|
+
this.logger.debug(`finding files by glob: ${glob}, ref: ${ref}, prefix: ${prefix}`);
|
|
141
|
+
return await this.fileCache.findFilesByGlob(glob, ref, prefix);
|
|
142
|
+
});
|
|
143
|
+
/**
|
|
144
|
+
* Returns a list of paths to all files with a given file
|
|
145
|
+
* extension.
|
|
146
|
+
*
|
|
147
|
+
* If a prefix is specified, only return paths that match
|
|
148
|
+
* the provided prefix.
|
|
149
|
+
*
|
|
150
|
+
* @param extension The file extension used to filter results.
|
|
151
|
+
* Example: `js`, `java`
|
|
152
|
+
* @param ref Git reference to search files in
|
|
153
|
+
* @param prefix Optional path prefix used to filter results
|
|
154
|
+
* @returns {string[]} List of file paths
|
|
155
|
+
* @throws {GitHubAPIError} on an API error
|
|
156
|
+
*/
|
|
157
|
+
this.findFilesByExtensionAndRef = wrapAsync(async (extension, ref, prefix) => {
|
|
158
|
+
if (prefix) {
|
|
159
|
+
prefix = normalizePrefix(prefix);
|
|
160
|
+
}
|
|
161
|
+
return this.fileCache.findFilesByExtension(extension, ref, prefix);
|
|
162
|
+
});
|
|
163
|
+
this.repository = options.repository;
|
|
164
|
+
this.octokit = options.octokitAPIs.octokit;
|
|
165
|
+
this.graphql = options.octokitAPIs.graphql;
|
|
166
|
+
this.fileCache = new git_file_utils_1.RepositoryFileCache(this.octokit, this.repository);
|
|
167
|
+
this.logger = (_a = options.logger) !== null && _a !== void 0 ? _a : logger_1.logger;
|
|
168
|
+
this.gitHubApi = new github_api_1.GitHubApi({
|
|
169
|
+
repository: this.repository,
|
|
170
|
+
octokitAPIs: options.octokitAPIs,
|
|
171
|
+
logger: this.logger,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
getGitHubApi() {
|
|
175
|
+
return this.gitHubApi;
|
|
176
|
+
}
|
|
177
|
+
static async create(options) {
|
|
178
|
+
const gitHubApi = await github_api_1.GitHubApi.create(options);
|
|
179
|
+
return new GitHub({
|
|
180
|
+
repository: gitHubApi.repository,
|
|
181
|
+
octokitAPIs: gitHubApi.octokitAPIs,
|
|
182
|
+
logger: options.logger,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Returns the list of commits to the default branch after the provided filter
|
|
187
|
+
* query has been satified.
|
|
188
|
+
*
|
|
189
|
+
* @param {string} targetBranch Target branch of commit
|
|
190
|
+
* @param {CommitFilter} filter Callback function that returns whether a
|
|
191
|
+
* commit/pull request matches certain criteria
|
|
192
|
+
* @param {CommitIteratorOptions} options Query options
|
|
193
|
+
* @param {number} options.maxResults Limit the number of results searched.
|
|
194
|
+
* Defaults to unlimited.
|
|
195
|
+
* @param {boolean} options.backfillFiles If set, use the REST API for
|
|
196
|
+
* fetching the list of touched files in this commit. Defaults to `false`.
|
|
197
|
+
* @returns {Commit[]} List of commits to current branch
|
|
198
|
+
* @throws {GitHubAPIError} on an API error
|
|
199
|
+
*/
|
|
200
|
+
async commitsSince(targetBranch, filter, options = {}) {
|
|
201
|
+
const commits = [];
|
|
202
|
+
const generator = this.mergeCommitIterator(targetBranch, options);
|
|
203
|
+
for await (const commit of generator) {
|
|
204
|
+
if (filter(commit)) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
commits.push(commit);
|
|
208
|
+
}
|
|
209
|
+
return commits;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Iterate through commit history with a max number of results scanned.
|
|
213
|
+
*
|
|
214
|
+
* @param {string} targetBranch target branch of commit
|
|
215
|
+
* @param {CommitIteratorOptions} options Query options
|
|
216
|
+
* @param {number} options.maxResults Limit the number of results searched.
|
|
217
|
+
* Defaults to unlimited.
|
|
218
|
+
* @param {boolean} options.backfillFiles If set, use the REST API for
|
|
219
|
+
* fetching the list of touched files in this commit. Defaults to `false`.
|
|
220
|
+
* @yields {Commit}
|
|
221
|
+
* @throws {GitHubAPIError} on an API error
|
|
222
|
+
*/
|
|
223
|
+
async *mergeCommitIterator(targetBranch, options = {}) {
|
|
224
|
+
var _a;
|
|
225
|
+
const maxResults = (_a = options.maxResults) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;
|
|
226
|
+
let cursor = undefined;
|
|
227
|
+
let results = 0;
|
|
228
|
+
while (results < maxResults) {
|
|
229
|
+
const response = await this.mergeCommitsGraphQL(targetBranch, cursor, options);
|
|
230
|
+
// no response usually means that the branch can't be found
|
|
231
|
+
if (!response) {
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
for (let i = 0; i < response.data.length; i++) {
|
|
235
|
+
results += 1;
|
|
236
|
+
yield response.data[i];
|
|
237
|
+
}
|
|
238
|
+
if (!response.pageInfo.hasNextPage) {
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
cursor = response.pageInfo.endCursor;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
async mergeCommitsGraphQL(targetBranch, cursor, options = {}) {
|
|
245
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
246
|
+
var _l;
|
|
247
|
+
this.logger.debug(`Fetching merge commits on branch ${targetBranch} with cursor: ${cursor}`);
|
|
248
|
+
const query = `query pullRequestsSince($owner: String!, $repo: String!, $num: Int!, $maxFilesChanged: Int, $targetBranch: String!, $cursor: String) {
|
|
249
|
+
repository(owner: $owner, name: $repo) {
|
|
250
|
+
ref(qualifiedName: $targetBranch) {
|
|
251
|
+
target {
|
|
252
|
+
... on Commit {
|
|
253
|
+
history(first: $num, after: $cursor) {
|
|
254
|
+
nodes {
|
|
255
|
+
associatedPullRequests(first: 10) {
|
|
256
|
+
nodes {
|
|
257
|
+
number
|
|
258
|
+
title
|
|
259
|
+
baseRefName
|
|
260
|
+
headRefName
|
|
261
|
+
labels(first: 10) {
|
|
262
|
+
nodes {
|
|
263
|
+
name
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
body
|
|
267
|
+
mergeCommit {
|
|
268
|
+
oid
|
|
269
|
+
}
|
|
270
|
+
files(first: $maxFilesChanged) {
|
|
271
|
+
nodes {
|
|
272
|
+
path
|
|
273
|
+
}
|
|
274
|
+
pageInfo {
|
|
275
|
+
endCursor
|
|
276
|
+
hasNextPage
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
sha: oid
|
|
282
|
+
message
|
|
283
|
+
author {
|
|
284
|
+
name
|
|
285
|
+
email
|
|
286
|
+
user {
|
|
287
|
+
login
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
pageInfo {
|
|
292
|
+
hasNextPage
|
|
293
|
+
endCursor
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}`;
|
|
301
|
+
const params = {
|
|
302
|
+
cursor,
|
|
303
|
+
owner: this.repository.owner,
|
|
304
|
+
repo: this.repository.repo,
|
|
305
|
+
num: (_a = options.batchSize) !== null && _a !== void 0 ? _a : 10,
|
|
306
|
+
targetBranch,
|
|
307
|
+
maxFilesChanged: 100, // max is 100
|
|
308
|
+
};
|
|
309
|
+
const response = await this.graphqlRequest({
|
|
310
|
+
query,
|
|
311
|
+
...params,
|
|
312
|
+
});
|
|
313
|
+
if (!response) {
|
|
314
|
+
this.logger.warn(`Did not receive a response for query: ${query}`, params);
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
// if the branch does exist, return null
|
|
318
|
+
if (!((_b = response.repository) === null || _b === void 0 ? void 0 : _b.ref)) {
|
|
319
|
+
this.logger.warn(`Could not find commits for branch ${targetBranch} - it likely does not exist.`);
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
const history = response.repository.ref.target.history;
|
|
323
|
+
const commits = (history.nodes || []);
|
|
324
|
+
// Count the number of pull requests associated with each merge commit. This is
|
|
325
|
+
// used in the next step to make sure we only find pull requests with a
|
|
326
|
+
// merge commit that contain 1 merged commit.
|
|
327
|
+
const mergeCommitCount = {};
|
|
328
|
+
for (const commit of commits) {
|
|
329
|
+
for (const pr of commit.associatedPullRequests.nodes) {
|
|
330
|
+
if ((_c = pr.mergeCommit) === null || _c === void 0 ? void 0 : _c.oid) {
|
|
331
|
+
(_d = mergeCommitCount[_l = pr.mergeCommit.oid]) !== null && _d !== void 0 ? _d : (mergeCommitCount[_l] = 0);
|
|
332
|
+
mergeCommitCount[pr.mergeCommit.oid]++;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const commitData = [];
|
|
337
|
+
for (const graphCommit of commits) {
|
|
338
|
+
const commit = {
|
|
339
|
+
sha: graphCommit.sha,
|
|
340
|
+
message: graphCommit.message,
|
|
341
|
+
author: graphCommit.author
|
|
342
|
+
? {
|
|
343
|
+
name: graphCommit.author.name || 'Unknown',
|
|
344
|
+
email: graphCommit.author.email,
|
|
345
|
+
username: (_e = graphCommit.author.user) === null || _e === void 0 ? void 0 : _e.login,
|
|
346
|
+
}
|
|
347
|
+
: undefined,
|
|
348
|
+
};
|
|
349
|
+
const mergePullRequest = graphCommit.associatedPullRequests.nodes.find(pr => {
|
|
350
|
+
return (
|
|
351
|
+
// Only match the pull request with a merge commit if there is a
|
|
352
|
+
// single merged commit in the PR. This means merge commits and squash
|
|
353
|
+
// merges will be matched, but rebase merged PRs will only be matched
|
|
354
|
+
// if they contain a single commit. This is so PRs that are rebased
|
|
355
|
+
// and merged will have ßSfiles backfilled from each commit instead of
|
|
356
|
+
// the whole PR.
|
|
357
|
+
pr.mergeCommit &&
|
|
358
|
+
pr.mergeCommit.oid === graphCommit.sha &&
|
|
359
|
+
mergeCommitCount[pr.mergeCommit.oid] === 1);
|
|
360
|
+
});
|
|
361
|
+
const pullRequest = mergePullRequest || graphCommit.associatedPullRequests.nodes[0];
|
|
362
|
+
if (pullRequest) {
|
|
363
|
+
commit.pullRequest = {
|
|
364
|
+
sha: commit.sha,
|
|
365
|
+
number: pullRequest.number,
|
|
366
|
+
baseBranchName: pullRequest.baseRefName,
|
|
367
|
+
headBranchName: pullRequest.headRefName,
|
|
368
|
+
mergeCommitOid: (_f = pullRequest.mergeCommit) === null || _f === void 0 ? void 0 : _f.oid,
|
|
369
|
+
title: pullRequest.title,
|
|
370
|
+
body: pullRequest.body,
|
|
371
|
+
labels: pullRequest.labels.nodes.map(node => node.name),
|
|
372
|
+
files: (((_g = pullRequest.files) === null || _g === void 0 ? void 0 : _g.nodes) || []).map(node => node.path),
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
if (mergePullRequest) {
|
|
376
|
+
if (((_j = (_h = mergePullRequest.files) === null || _h === void 0 ? void 0 : _h.pageInfo) === null || _j === void 0 ? void 0 : _j.hasNextPage) &&
|
|
377
|
+
options.backfillFiles) {
|
|
378
|
+
this.logger.info(`PR #${mergePullRequest.number} has many files, backfilling`);
|
|
379
|
+
commit.files = await this.getCommitFiles(graphCommit.sha);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
// We cannot directly fetch files on commits via graphql, only provide file
|
|
383
|
+
// information for commits with associated pull requests
|
|
384
|
+
commit.files = (((_k = mergePullRequest.files) === null || _k === void 0 ? void 0 : _k.nodes) || []).map(node => node.path);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
else if (options.backfillFiles) {
|
|
388
|
+
// In this case, there is no squashed merge commit. This could be a simple
|
|
389
|
+
// merge commit, a rebase merge commit, or a direct commit to the branch.
|
|
390
|
+
// Fallback to fetching the list of commits from the REST API. In the future
|
|
391
|
+
// we can perhaps lazy load these.
|
|
392
|
+
commit.files = await this.getCommitFiles(graphCommit.sha);
|
|
393
|
+
}
|
|
394
|
+
commitData.push(commit);
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
pageInfo: history.pageInfo,
|
|
398
|
+
data: commitData,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Iterate through merged pull requests with a max number of results scanned.
|
|
403
|
+
*
|
|
404
|
+
* @param {string} targetBranch The base branch of the pull request
|
|
405
|
+
* @param {string} status The status of the pull request
|
|
406
|
+
* @param {number} maxResults Limit the number of results searched. Defaults to
|
|
407
|
+
* unlimited.
|
|
408
|
+
* @param {boolean} includeFiles Whether to fetch the list of files included in
|
|
409
|
+
* the pull request. Defaults to `true`.
|
|
410
|
+
* @yields {PullRequest}
|
|
411
|
+
* @throws {GitHubAPIError} on an API error
|
|
412
|
+
*/
|
|
413
|
+
async *pullRequestIterator(targetBranch, status = 'MERGED', maxResults = Number.MAX_SAFE_INTEGER, includeFiles = true) {
|
|
414
|
+
yield* this.gitHubApi.pullRequestIterator(targetBranch, status, maxResults, includeFiles);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Iterate through releases with a max number of results scanned.
|
|
418
|
+
*
|
|
419
|
+
* @param {ReleaseIteratorOptions} options Query options
|
|
420
|
+
* @param {number} options.maxResults Limit the number of results searched.
|
|
421
|
+
* Defaults to unlimited.
|
|
422
|
+
* @yields {GitHubRelease}
|
|
423
|
+
* @throws {GitHubAPIError} on an API error
|
|
424
|
+
*/
|
|
425
|
+
async *releaseIterator(options = {}) {
|
|
426
|
+
yield* this.gitHubApi.releaseIterator(options);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Iterate through tags with a max number of results scanned.
|
|
430
|
+
*
|
|
431
|
+
* @param {TagIteratorOptions} options Query options
|
|
432
|
+
* @param {number} options.maxResults Limit the number of results searched.
|
|
433
|
+
* Defaults to unlimited.
|
|
434
|
+
* @yields {GitHubTag}
|
|
435
|
+
* @throws {GitHubAPIError} on an API error
|
|
436
|
+
*/
|
|
437
|
+
async *tagIterator(options = {}) {
|
|
438
|
+
const maxResults = options.maxResults || Number.MAX_SAFE_INTEGER;
|
|
439
|
+
let results = 0;
|
|
440
|
+
for await (const response of this.octokit.paginate.iterator('GET /repos/{owner}/{repo}/tags', {
|
|
441
|
+
owner: this.repository.owner,
|
|
442
|
+
repo: this.repository.repo,
|
|
443
|
+
})) {
|
|
444
|
+
for (const tag of response.data) {
|
|
445
|
+
if ((results += 1) > maxResults) {
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
yield {
|
|
449
|
+
name: tag.name,
|
|
450
|
+
sha: tag.commit.sha,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
if (results > maxResults)
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Fetch the contents of a file from the configured branch
|
|
459
|
+
*
|
|
460
|
+
* @param {string} path The path to the file in the repository
|
|
461
|
+
* @returns {GitHubFileContents}
|
|
462
|
+
* @throws {GitHubAPIError} on other API errors
|
|
463
|
+
*/
|
|
464
|
+
async getFileContents(path) {
|
|
465
|
+
return await this.getFileContentsOnBranch(path, this.repository.defaultBranch);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Fetch the contents of a file
|
|
469
|
+
*
|
|
470
|
+
* @param {string} path The path to the file in the repository
|
|
471
|
+
* @param {string} branch The branch to fetch from
|
|
472
|
+
* @returns {GitHubFileContents}
|
|
473
|
+
* @throws {FileNotFoundError} if the file cannot be found
|
|
474
|
+
* @throws {GitHubAPIError} on other API errors
|
|
475
|
+
*/
|
|
476
|
+
async getFileContentsOnBranch(path, branch) {
|
|
477
|
+
this.logger.debug(`Fetching ${path} from branch ${branch}`);
|
|
478
|
+
try {
|
|
479
|
+
return await this.fileCache.getFileContents(path, branch);
|
|
480
|
+
}
|
|
481
|
+
catch (e) {
|
|
482
|
+
if (e instanceof git_file_utils_1.FileNotFoundError) {
|
|
483
|
+
throw new errors_1.FileNotFoundError(path);
|
|
484
|
+
}
|
|
485
|
+
throw e;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
async getFileJson(path, branch) {
|
|
489
|
+
const content = await this.getFileContentsOnBranch(path, branch);
|
|
490
|
+
return JSON.parse(content.parsedContent);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Returns a list of paths to all files with a given name.
|
|
494
|
+
*
|
|
495
|
+
* If a prefix is specified, only return paths that match
|
|
496
|
+
* the provided prefix.
|
|
497
|
+
*
|
|
498
|
+
* @param filename The name of the file to find
|
|
499
|
+
* @param prefix Optional path prefix used to filter results
|
|
500
|
+
* @returns {string[]} List of file paths
|
|
501
|
+
* @throws {GitHubAPIError} on an API error
|
|
502
|
+
*/
|
|
503
|
+
async findFilesByFilename(filename, prefix) {
|
|
504
|
+
return this.findFilesByFilenameAndRef(filename, this.repository.defaultBranch, prefix);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Returns a list of paths to all files matching a glob pattern.
|
|
508
|
+
*
|
|
509
|
+
* If a prefix is specified, only return paths that match
|
|
510
|
+
* the provided prefix.
|
|
511
|
+
*
|
|
512
|
+
* @param glob The glob to match
|
|
513
|
+
* @param prefix Optional path prefix used to filter results
|
|
514
|
+
* @returns {string[]} List of file paths
|
|
515
|
+
* @throws {GitHubAPIError} on an API error
|
|
516
|
+
*/
|
|
517
|
+
async findFilesByGlob(glob, prefix) {
|
|
518
|
+
return this.findFilesByGlobAndRef(glob, this.repository.defaultBranch, prefix);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Open a pull request
|
|
522
|
+
*
|
|
523
|
+
* @param {PullRequest} pullRequest Pull request data to update
|
|
524
|
+
* @param {string} targetBranch The base branch of the pull request
|
|
525
|
+
* @param {string} message The commit message for the commit
|
|
526
|
+
* @param {Update[]} updates The files to update
|
|
527
|
+
* @param {CreatePullRequestOptions} options The pull request options
|
|
528
|
+
* @throws {GitHubAPIError} on an API error
|
|
529
|
+
*/
|
|
530
|
+
async createPullRequest(pullRequest, targetBranch, message, updates, options) {
|
|
531
|
+
const changes = await this.buildChangeSet(updates, targetBranch);
|
|
532
|
+
const prNumber = await (0, code_suggester_1.createPullRequest)(this.octokit, changes, {
|
|
533
|
+
upstreamOwner: this.repository.owner,
|
|
534
|
+
upstreamRepo: this.repository.repo,
|
|
535
|
+
title: pullRequest.title,
|
|
536
|
+
branch: pullRequest.headBranchName,
|
|
537
|
+
description: pullRequest.body,
|
|
538
|
+
primary: targetBranch,
|
|
539
|
+
force: true,
|
|
540
|
+
fork: !!(options === null || options === void 0 ? void 0 : options.fork),
|
|
541
|
+
message,
|
|
542
|
+
logger: this.logger,
|
|
543
|
+
draft: !!(options === null || options === void 0 ? void 0 : options.draft),
|
|
544
|
+
labels: pullRequest.labels,
|
|
545
|
+
});
|
|
546
|
+
if (prNumber === 0) {
|
|
547
|
+
this.logger.warn('no code changes detected, skipping pull request creation');
|
|
548
|
+
return {
|
|
549
|
+
headBranchName: pullRequest.headBranchName,
|
|
550
|
+
baseBranchName: targetBranch,
|
|
551
|
+
number: 0,
|
|
552
|
+
title: pullRequest.title,
|
|
553
|
+
body: pullRequest.body,
|
|
554
|
+
labels: pullRequest.labels,
|
|
555
|
+
files: [],
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
return await this.getPullRequest(prNumber);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Fetch a pull request given the pull number
|
|
562
|
+
* @param {number} number The pull request number
|
|
563
|
+
* @returns {PullRequest}
|
|
564
|
+
*/
|
|
565
|
+
async getPullRequest(number) {
|
|
566
|
+
return await this.gitHubApi.getPullRequest(number);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Update a pull request's title and body.
|
|
570
|
+
* @param {number} number The pull request number
|
|
571
|
+
* @param {ReleasePullRequest} releasePullRequest Pull request data to update
|
|
572
|
+
* @param {string} targetBranch The target branch of the pull request
|
|
573
|
+
* @param {string} options.signoffUser Optional. Commit signoff message
|
|
574
|
+
* @param {boolean} options.fork Optional. Whether to open the pull request from
|
|
575
|
+
* a fork or not. Defaults to `false`
|
|
576
|
+
* @param {PullRequestOverflowHandler} options.pullRequestOverflowHandler Optional.
|
|
577
|
+
* Handles extra large pull request body messages.
|
|
578
|
+
*/
|
|
579
|
+
async updatePullRequest(number, releasePullRequest, targetBranch, options) {
|
|
580
|
+
const changes = await this.buildChangeSet(releasePullRequest.updates, targetBranch);
|
|
581
|
+
let message = releasePullRequest.title.toString();
|
|
582
|
+
if (options === null || options === void 0 ? void 0 : options.signoffUser) {
|
|
583
|
+
message = (0, signoff_commit_message_1.signoffCommitMessage)(message, options.signoffUser);
|
|
584
|
+
}
|
|
585
|
+
const title = releasePullRequest.title.toString();
|
|
586
|
+
const body = ((options === null || options === void 0 ? void 0 : options.pullRequestOverflowHandler)
|
|
587
|
+
? await options.pullRequestOverflowHandler.handleOverflow(releasePullRequest)
|
|
588
|
+
: releasePullRequest.body)
|
|
589
|
+
.toString()
|
|
590
|
+
.slice(0, MAX_ISSUE_BODY_SIZE);
|
|
591
|
+
const prNumber = await (0, code_suggester_1.createPullRequest)(this.octokit, changes, {
|
|
592
|
+
upstreamOwner: this.repository.owner,
|
|
593
|
+
upstreamRepo: this.repository.repo,
|
|
594
|
+
title,
|
|
595
|
+
branch: releasePullRequest.headRefName,
|
|
596
|
+
description: body,
|
|
597
|
+
primary: targetBranch,
|
|
598
|
+
force: true,
|
|
599
|
+
fork: (options === null || options === void 0 ? void 0 : options.fork) === false ? false : true,
|
|
600
|
+
message,
|
|
601
|
+
logger: this.logger,
|
|
602
|
+
draft: releasePullRequest.draft,
|
|
603
|
+
});
|
|
604
|
+
if (prNumber !== number) {
|
|
605
|
+
this.logger.warn(`updated code for ${prNumber}, but update requested for ${number}`);
|
|
606
|
+
}
|
|
607
|
+
return this.gitHubApi.updatePullRequest(number, title, body);
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Given a set of proposed updates, build a changeset to suggest.
|
|
611
|
+
*
|
|
612
|
+
* @param {Update[]} updates The proposed updates
|
|
613
|
+
* @param {string} defaultBranch The target branch
|
|
614
|
+
* @return {Changes} The changeset to suggest.
|
|
615
|
+
* @throws {GitHubAPIError} on an API error
|
|
616
|
+
*/
|
|
617
|
+
async buildChangeSet(updates, defaultBranch) {
|
|
618
|
+
// Sometimes multiple updates are proposed for the same file,
|
|
619
|
+
// such as when the manifest file is additionally changed by the
|
|
620
|
+
// node-workspace plugin. We need to merge these updates.
|
|
621
|
+
const mergedUpdates = (0, composite_1.mergeUpdates)(updates);
|
|
622
|
+
const changes = new Map();
|
|
623
|
+
for (const update of mergedUpdates) {
|
|
624
|
+
let content;
|
|
625
|
+
try {
|
|
626
|
+
content = await this.getFileContentsOnBranch(update.path, defaultBranch);
|
|
627
|
+
}
|
|
628
|
+
catch (err) {
|
|
629
|
+
if (!(err instanceof errors_1.FileNotFoundError))
|
|
630
|
+
throw err;
|
|
631
|
+
// if the file is missing and create = false, just continue
|
|
632
|
+
// to the next update, otherwise create the file.
|
|
633
|
+
if (!update.createIfMissing) {
|
|
634
|
+
this.logger.warn(`file ${update.path} did not exist`);
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
const contentText = content
|
|
639
|
+
? Buffer.from(content.content, 'base64').toString('utf8')
|
|
640
|
+
: undefined;
|
|
641
|
+
const updatedContent = update.updater.updateContent(contentText, this.logger);
|
|
642
|
+
if (updatedContent) {
|
|
643
|
+
changes.set(update.path, {
|
|
644
|
+
content: updatedContent,
|
|
645
|
+
originalContent: (content === null || content === void 0 ? void 0 : content.parsedContent) || null,
|
|
646
|
+
mode: (content === null || content === void 0 ? void 0 : content.mode) || git_file_utils_1.DEFAULT_FILE_MODE,
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return changes;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Returns a list of paths to all files with a given file
|
|
654
|
+
* extension.
|
|
655
|
+
*
|
|
656
|
+
* If a prefix is specified, only return paths that match
|
|
657
|
+
* the provided prefix.
|
|
658
|
+
*
|
|
659
|
+
* @param extension The file extension used to filter results.
|
|
660
|
+
* Example: `js`, `java`
|
|
661
|
+
* @param prefix Optional path prefix used to filter results
|
|
662
|
+
* @returns {string[]} List of file paths
|
|
663
|
+
* @throws {GitHubAPIError} on an API error
|
|
664
|
+
*/
|
|
665
|
+
async findFilesByExtension(extension, prefix) {
|
|
666
|
+
return this.findFilesByExtensionAndRef(extension, this.repository.defaultBranch, prefix);
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Create a GitHub release
|
|
670
|
+
*
|
|
671
|
+
* @param {Release} release Release parameters
|
|
672
|
+
* @param {ReleaseOptions} options Release option parameters
|
|
673
|
+
* @throws {DuplicateReleaseError} if the release tag already exists
|
|
674
|
+
* @throws {GitHubAPIError} on other API errors
|
|
675
|
+
*/
|
|
676
|
+
async createRelease(release, options = {}) {
|
|
677
|
+
return await this.gitHubApi.createRelease(release, options);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Makes a comment on a issue/pull request.
|
|
681
|
+
*
|
|
682
|
+
* @param {string} comment - The body of the comment to post.
|
|
683
|
+
* @param {number} number - The issue or pull request number.
|
|
684
|
+
* @throws {GitHubAPIError} on an API error
|
|
685
|
+
*/
|
|
686
|
+
async commentOnIssue(comment, number) {
|
|
687
|
+
return await this.gitHubApi.commentOnIssue(comment, number);
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Removes labels from an issue/pull request.
|
|
691
|
+
*
|
|
692
|
+
* @param {string[]} labels The labels to remove.
|
|
693
|
+
* @param {number} number The issue/pull request number.
|
|
694
|
+
*/
|
|
695
|
+
async removeIssueLabels(labels, number) {
|
|
696
|
+
return await this.gitHubApi.removeIssueLabels(labels, number);
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Adds label to an issue/pull request.
|
|
700
|
+
*
|
|
701
|
+
* @param {string[]} labels The labels to add.
|
|
702
|
+
* @param {number} number The issue/pull request number.
|
|
703
|
+
*/
|
|
704
|
+
async addIssueLabels(labels, number) {
|
|
705
|
+
return await this.gitHubApi.addIssueLabels(labels, number);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Generate release notes from GitHub at tag
|
|
709
|
+
* @param {string} tagName Name of new release tag
|
|
710
|
+
* @param {string} targetCommitish Target commitish for new tag
|
|
711
|
+
* @param {string} previousTag Optional. Name of previous tag to analyze commits since
|
|
712
|
+
*/
|
|
713
|
+
async generateReleaseNotes(tagName, targetCommitish, previousTag) {
|
|
714
|
+
return await this.gitHubApi.generateReleaseNotes(tagName, targetCommitish, previousTag);
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Create a single file on a new branch based on an existing
|
|
718
|
+
* branch. This will force-push to that branch.
|
|
719
|
+
* @param {string} filename Filename with path in the repository
|
|
720
|
+
* @param {string} contents Contents of the file
|
|
721
|
+
* @param {string} newBranchName Name of the new branch
|
|
722
|
+
* @param {string} baseBranchName Name of the base branch (where
|
|
723
|
+
* new branch is forked from)
|
|
724
|
+
* @returns {string} HTML URL of the new file
|
|
725
|
+
*/
|
|
726
|
+
async createFileOnNewBranch(filename, contents, newBranchName, baseBranchName) {
|
|
727
|
+
return await this.gitHubApi.createFileOnNewBranch(filename, contents, newBranchName, baseBranchName);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
exports.GitHub = GitHub;
|
|
731
|
+
/**
|
|
732
|
+
* Normalize a provided prefix by removing leading and trailing
|
|
733
|
+
* slashes.
|
|
734
|
+
*
|
|
735
|
+
* @param prefix String to normalize
|
|
736
|
+
*/
|
|
737
|
+
function normalizePrefix(prefix) {
|
|
738
|
+
const normalized = prefix.replace(/^[/\\]/, '').replace(/[/\\]$/, '');
|
|
739
|
+
if (normalized === manifest_1.ROOT_PROJECT_PATH) {
|
|
740
|
+
return '';
|
|
741
|
+
}
|
|
742
|
+
return normalized;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Wrap an async method with error handling
|
|
746
|
+
*
|
|
747
|
+
* @param fn Async function that can throw Errors
|
|
748
|
+
* @param errorHandler An optional error handler for rethrowing custom exceptions
|
|
749
|
+
*/
|
|
750
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
751
|
+
const wrapAsync = (fn, errorHandler) => {
|
|
752
|
+
return async (...args) => {
|
|
753
|
+
try {
|
|
754
|
+
return await fn(...args);
|
|
755
|
+
}
|
|
756
|
+
catch (e) {
|
|
757
|
+
if (errorHandler) {
|
|
758
|
+
errorHandler(e);
|
|
759
|
+
}
|
|
760
|
+
if (e instanceof request_error_1.RequestError) {
|
|
761
|
+
throw new errors_1.GitHubAPIError(e);
|
|
762
|
+
}
|
|
763
|
+
throw e;
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
const sleepInMs = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
768
|
+
exports.sleepInMs = sleepInMs;
|
|
769
|
+
//# sourceMappingURL=github.js.map
|