release-please 17.8.0 → 17.10.0
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/README.md +1 -1
- package/build/src/github-api.d.ts +1 -1
- package/build/src/github.d.ts +1 -1
- package/build/src/github.js +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.js +1 -1
- package/build/src/local-github.d.ts +1 -1
- package/build/src/local-github.js +1 -1
- package/build/src/manifest.js +22 -20
- package/build/src/plugins/linked-versions.js +1 -1
- package/build/src/strategies/base.js +8 -0
- package/build/src/strategies/go-librarian.d.ts +2 -0
- package/build/src/strategies/go-librarian.js +15 -1
- package/build/src/updaters/librarian-yaml.d.ts +7 -0
- package/build/src/updaters/librarian-yaml.js +47 -21
- package/build/src/util/branch-name.d.ts +1 -0
- package/build/src/util/branch-name.js +9 -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/pull-request-title.js +4 -4
- package/package.json +5 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Changes, TreeObject, RepoDomain, BranchDomain } from '../types';
|
|
2
|
+
import { Octokit } from '@octokit/rest';
|
|
3
|
+
import { CreateCommitOptions } from './create-commit';
|
|
4
|
+
/**
|
|
5
|
+
* Generate and return a GitHub tree object structure
|
|
6
|
+
* containing the target change data
|
|
7
|
+
* See https://developer.github.com/v3/git/trees/#tree-object
|
|
8
|
+
* @param {Changes} changes the set of repository changes
|
|
9
|
+
* @returns {TreeObject[]} The new GitHub changes
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateTreeObjects(changes: Changes): TreeObject[];
|
|
12
|
+
/**
|
|
13
|
+
* Upload and create a remote GitHub tree
|
|
14
|
+
* and resolves with the new tree SHA.
|
|
15
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
16
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
17
|
+
* @param {RepoDomain} origin the the remote repository to push changes to
|
|
18
|
+
* @param {string} refHead the base of the new commit(s)
|
|
19
|
+
* @param {TreeObject[]} tree the set of GitHub changes to upload
|
|
20
|
+
* @returns {Promise<string>} the GitHub tree SHA
|
|
21
|
+
* @throws {CommitError}
|
|
22
|
+
*/
|
|
23
|
+
export declare function createTree(octokit: Octokit, origin: RepoDomain, refHead: string, tree: TreeObject[]): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Update a reference to a SHA
|
|
26
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
27
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
28
|
+
* @param {BranchDomain} origin the the remote branch to push changes to
|
|
29
|
+
* @param {string} newSha the ref to update the commit HEAD to
|
|
30
|
+
* @param {boolean} force to force the commit changes given refHead
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
|
+
*/
|
|
33
|
+
export declare function updateRef(octokit: Octokit, origin: BranchDomain, newSha: string, force: boolean): Promise<void>;
|
|
34
|
+
interface CommitAndPushOptions extends CreateCommitOptions {
|
|
35
|
+
filesPerCommit?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Given a set of changes, apply the commit(s) on top of the given branch's head and upload it to GitHub
|
|
39
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
40
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
41
|
+
* @param {string} refHead the base of the new commit(s)
|
|
42
|
+
* @param {Changes} changes the set of repository changes
|
|
43
|
+
* @param {RepoDomain} origin the the remote repository to push changes to
|
|
44
|
+
* @param {string} originBranchName the remote branch that will contain the new changes
|
|
45
|
+
* @param {string} commitMessage the message of the new commit
|
|
46
|
+
* @param {boolean} force to force the commit changes given refHead
|
|
47
|
+
* @returns {Promise<void>}
|
|
48
|
+
* @throws {CommitError}
|
|
49
|
+
*/
|
|
50
|
+
export declare function commitAndPush(octokit: Octokit, refHead: string, changes: Changes, originBranch: BranchDomain, commitMessage: string, force: boolean, options?: CommitAndPushOptions): Promise<void>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
// https://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.commitAndPush = exports.updateRef = exports.createTree = exports.generateTreeObjects = void 0;
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
const create_commit_1 = require("./create-commit");
|
|
19
|
+
const errors_1 = require("../errors");
|
|
20
|
+
const DEFAULT_FILES_PER_COMMIT = 100;
|
|
21
|
+
/**
|
|
22
|
+
* Generate and return a GitHub tree object structure
|
|
23
|
+
* containing the target change data
|
|
24
|
+
* See https://developer.github.com/v3/git/trees/#tree-object
|
|
25
|
+
* @param {Changes} changes the set of repository changes
|
|
26
|
+
* @returns {TreeObject[]} The new GitHub changes
|
|
27
|
+
*/
|
|
28
|
+
function generateTreeObjects(changes) {
|
|
29
|
+
const tree = [];
|
|
30
|
+
changes.forEach((fileData, path) => {
|
|
31
|
+
if (fileData.content === null) {
|
|
32
|
+
// if no file content then file is deleted
|
|
33
|
+
tree.push({
|
|
34
|
+
path,
|
|
35
|
+
mode: fileData.mode,
|
|
36
|
+
type: 'blob',
|
|
37
|
+
sha: null,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// update file with its content
|
|
42
|
+
tree.push({
|
|
43
|
+
path,
|
|
44
|
+
mode: fileData.mode,
|
|
45
|
+
type: 'blob',
|
|
46
|
+
content: fileData.content,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return tree;
|
|
51
|
+
}
|
|
52
|
+
exports.generateTreeObjects = generateTreeObjects;
|
|
53
|
+
function* inGroupsOf(all, groupSize) {
|
|
54
|
+
for (let i = 0; i < all.length; i += groupSize) {
|
|
55
|
+
yield all.slice(i, i + groupSize);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Upload and create a remote GitHub tree
|
|
60
|
+
* and resolves with the new tree SHA.
|
|
61
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
62
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
63
|
+
* @param {RepoDomain} origin the the remote repository to push changes to
|
|
64
|
+
* @param {string} refHead the base of the new commit(s)
|
|
65
|
+
* @param {TreeObject[]} tree the set of GitHub changes to upload
|
|
66
|
+
* @returns {Promise<string>} the GitHub tree SHA
|
|
67
|
+
* @throws {CommitError}
|
|
68
|
+
*/
|
|
69
|
+
async function createTree(octokit, origin, refHead, tree) {
|
|
70
|
+
const oldTreeSha = (await octokit.git.getCommit({
|
|
71
|
+
owner: origin.owner,
|
|
72
|
+
repo: origin.repo,
|
|
73
|
+
commit_sha: refHead,
|
|
74
|
+
})).data.tree.sha;
|
|
75
|
+
logger_1.logger.info('Got the latest commit tree');
|
|
76
|
+
try {
|
|
77
|
+
const treeSha = (await octokit.git.createTree({
|
|
78
|
+
owner: origin.owner,
|
|
79
|
+
repo: origin.repo,
|
|
80
|
+
tree,
|
|
81
|
+
base_tree: oldTreeSha,
|
|
82
|
+
})).data.sha;
|
|
83
|
+
logger_1.logger.info(`Successfully created a tree with the desired changes with SHA ${treeSha}`);
|
|
84
|
+
return treeSha;
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw new errors_1.CommitError(`Error adding to tree: ${refHead}`, e);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.createTree = createTree;
|
|
91
|
+
/**
|
|
92
|
+
* Update a reference to a SHA
|
|
93
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
94
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
95
|
+
* @param {BranchDomain} origin the the remote branch to push changes to
|
|
96
|
+
* @param {string} newSha the ref to update the commit HEAD to
|
|
97
|
+
* @param {boolean} force to force the commit changes given refHead
|
|
98
|
+
* @returns {Promise<void>}
|
|
99
|
+
*/
|
|
100
|
+
async function updateRef(octokit, origin, newSha, force) {
|
|
101
|
+
logger_1.logger.info(`Updating reference heads/${origin.branch} to ${newSha}`);
|
|
102
|
+
try {
|
|
103
|
+
await octokit.git.updateRef({
|
|
104
|
+
owner: origin.owner,
|
|
105
|
+
repo: origin.repo,
|
|
106
|
+
ref: `heads/${origin.branch}`,
|
|
107
|
+
sha: newSha,
|
|
108
|
+
force,
|
|
109
|
+
});
|
|
110
|
+
logger_1.logger.info(`Successfully updated reference ${origin.branch} to ${newSha}`);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
throw new errors_1.CommitError(`Error updating ref heads/${origin.branch} to ${newSha}`, e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.updateRef = updateRef;
|
|
117
|
+
/**
|
|
118
|
+
* Given a set of changes, apply the commit(s) on top of the given branch's head and upload it to GitHub
|
|
119
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
120
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
121
|
+
* @param {string} refHead the base of the new commit(s)
|
|
122
|
+
* @param {Changes} changes the set of repository changes
|
|
123
|
+
* @param {RepoDomain} origin the the remote repository to push changes to
|
|
124
|
+
* @param {string} originBranchName the remote branch that will contain the new changes
|
|
125
|
+
* @param {string} commitMessage the message of the new commit
|
|
126
|
+
* @param {boolean} force to force the commit changes given refHead
|
|
127
|
+
* @returns {Promise<void>}
|
|
128
|
+
* @throws {CommitError}
|
|
129
|
+
*/
|
|
130
|
+
async function commitAndPush(octokit, refHead, changes, originBranch, commitMessage, force, options) {
|
|
131
|
+
var _a;
|
|
132
|
+
const filesPerCommit = (_a = options === null || options === void 0 ? void 0 : options.filesPerCommit) !== null && _a !== void 0 ? _a : DEFAULT_FILES_PER_COMMIT;
|
|
133
|
+
const tree = generateTreeObjects(changes);
|
|
134
|
+
for (const treeGroup of inGroupsOf(tree, filesPerCommit)) {
|
|
135
|
+
const treeSha = await createTree(octokit, originBranch, refHead, treeGroup);
|
|
136
|
+
refHead = await (0, create_commit_1.createCommit)(octokit, originBranch, refHead, treeSha, commitMessage, options);
|
|
137
|
+
}
|
|
138
|
+
await updateRef(octokit, originBranch, refHead, force);
|
|
139
|
+
}
|
|
140
|
+
exports.commitAndPush = commitAndPush;
|
|
141
|
+
//# sourceMappingURL=commit-and-push.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Octokit } from '@octokit/rest';
|
|
2
|
+
import { RepoDomain, CommitSigner, UserData } from '../types';
|
|
3
|
+
export interface CreateCommitOptions {
|
|
4
|
+
signer?: CommitSigner;
|
|
5
|
+
author?: UserData;
|
|
6
|
+
committer?: UserData;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create a commit with a repo snapshot SHA on top of the reference HEAD
|
|
10
|
+
* and resolves with the SHA of the commit.
|
|
11
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
12
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
13
|
+
* @param {RepoDomain} origin the the remote repository to push changes to
|
|
14
|
+
* @param {string} refHead the base of the new commit(s)
|
|
15
|
+
* @param {string} treeSha the tree SHA that this commit will point to
|
|
16
|
+
* @param {string} message the message of the new commit
|
|
17
|
+
* @returns {Promise<string>} the new commit SHA
|
|
18
|
+
* @see https://docs.github.com/en/rest/git/commits?apiVersion=2022-11-28#create-a-commit
|
|
19
|
+
*/
|
|
20
|
+
export declare function createCommit(octokit: Octokit, origin: RepoDomain, refHead: string, treeSha: string, message: string, options?: CreateCommitOptions): Promise<string>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
// https://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.createCommit = void 0;
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
/**
|
|
20
|
+
* Create a commit with a repo snapshot SHA on top of the reference HEAD
|
|
21
|
+
* and resolves with the SHA of the commit.
|
|
22
|
+
* Rejects if GitHub V3 API fails with the GitHub error response
|
|
23
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
24
|
+
* @param {RepoDomain} origin the the remote repository to push changes to
|
|
25
|
+
* @param {string} refHead the base of the new commit(s)
|
|
26
|
+
* @param {string} treeSha the tree SHA that this commit will point to
|
|
27
|
+
* @param {string} message the message of the new commit
|
|
28
|
+
* @returns {Promise<string>} the new commit SHA
|
|
29
|
+
* @see https://docs.github.com/en/rest/git/commits?apiVersion=2022-11-28#create-a-commit
|
|
30
|
+
*/
|
|
31
|
+
async function createCommit(octokit, origin, refHead, treeSha, message, options = {}) {
|
|
32
|
+
try {
|
|
33
|
+
const signature = options.signer
|
|
34
|
+
? await options.signer.generateSignature({
|
|
35
|
+
message,
|
|
36
|
+
tree: treeSha,
|
|
37
|
+
parents: [refHead],
|
|
38
|
+
author: options.author,
|
|
39
|
+
committer: options.committer,
|
|
40
|
+
})
|
|
41
|
+
: undefined;
|
|
42
|
+
const { data: { sha, url }, } = await octokit.git.createCommit({
|
|
43
|
+
owner: origin.owner,
|
|
44
|
+
repo: origin.repo,
|
|
45
|
+
message,
|
|
46
|
+
tree: treeSha,
|
|
47
|
+
parents: [refHead],
|
|
48
|
+
signature,
|
|
49
|
+
author: options.author,
|
|
50
|
+
committer: options.committer,
|
|
51
|
+
});
|
|
52
|
+
logger_1.logger.info(`Successfully created commit. See commit at ${url}`);
|
|
53
|
+
return sha;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
throw new errors_1.CommitError(`Error creating commit for: ${treeSha}`, e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.createCommit = createCommit;
|
|
60
|
+
//# sourceMappingURL=create-commit.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RepoDomain } from '../types';
|
|
2
|
+
import { Octokit } from '@octokit/rest';
|
|
3
|
+
/**
|
|
4
|
+
* Fork the GitHub owner's repository.
|
|
5
|
+
* Returns the fork owner and fork repo when the fork creation request to GitHub succeeds.
|
|
6
|
+
* Otherwise throws error.
|
|
7
|
+
*
|
|
8
|
+
* If fork already exists no new fork is created, no error occurs, and the existing Fork data is returned
|
|
9
|
+
* with the `updated_at` + any historical repo changes.
|
|
10
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
11
|
+
* @param {RepoDomain} upstream upstream repository information
|
|
12
|
+
* @returns {Promise<RepoDomain>} the forked repository name, as well as the owner of that fork
|
|
13
|
+
*/
|
|
14
|
+
declare function fork(octokit: Octokit, upstream: RepoDomain): Promise<RepoDomain>;
|
|
15
|
+
export { fork };
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
// https://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.fork = void 0;
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
/**
|
|
19
|
+
* Fork the GitHub owner's repository.
|
|
20
|
+
* Returns the fork owner and fork repo when the fork creation request to GitHub succeeds.
|
|
21
|
+
* Otherwise throws error.
|
|
22
|
+
*
|
|
23
|
+
* If fork already exists no new fork is created, no error occurs, and the existing Fork data is returned
|
|
24
|
+
* with the `updated_at` + any historical repo changes.
|
|
25
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
26
|
+
* @param {RepoDomain} upstream upstream repository information
|
|
27
|
+
* @returns {Promise<RepoDomain>} the forked repository name, as well as the owner of that fork
|
|
28
|
+
*/
|
|
29
|
+
async function fork(octokit, upstream) {
|
|
30
|
+
try {
|
|
31
|
+
const forkedRepo = (await octokit.repos.createFork({
|
|
32
|
+
owner: upstream.owner,
|
|
33
|
+
repo: upstream.repo,
|
|
34
|
+
})).data;
|
|
35
|
+
const origin = {
|
|
36
|
+
repo: forkedRepo.name,
|
|
37
|
+
owner: forkedRepo.owner.login,
|
|
38
|
+
};
|
|
39
|
+
logger_1.logger.info(`Create fork request was successful for ${origin.owner}/${origin.repo}`);
|
|
40
|
+
return origin;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
logger_1.logger.error('Error when forking');
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.fork = fork;
|
|
48
|
+
//# sourceMappingURL=fork.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BranchDomain, RepoDomain } from '../types';
|
|
2
|
+
import { Octokit } from '@octokit/rest';
|
|
3
|
+
/**
|
|
4
|
+
* Create a GitHub PR on the upstream organization's repo
|
|
5
|
+
* Throws an error if the GitHub API fails
|
|
6
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
7
|
+
* @param {RepoDomain} upstream The upstream repository
|
|
8
|
+
* @param {BranchDomain} origin The remote origin information that contains the origin branch
|
|
9
|
+
* @param {number} issue_number The issue number to add labels to. Can also be a PR number
|
|
10
|
+
* @param {string[]} labels The list of labels to apply to the newly created PR. Default is []. the funciton will no-op.
|
|
11
|
+
* @returns {Promise<string[]>} The list of resulting labels after the addition of the given labels
|
|
12
|
+
*/
|
|
13
|
+
declare function addLabels(octokit: Octokit, upstream: RepoDomain, origin: BranchDomain, issue_number: number, labels?: string[]): Promise<string[]>;
|
|
14
|
+
export { addLabels };
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
// https://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.addLabels = void 0;
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
/**
|
|
19
|
+
* Create a GitHub PR on the upstream organization's repo
|
|
20
|
+
* Throws an error if the GitHub API fails
|
|
21
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
22
|
+
* @param {RepoDomain} upstream The upstream repository
|
|
23
|
+
* @param {BranchDomain} origin The remote origin information that contains the origin branch
|
|
24
|
+
* @param {number} issue_number The issue number to add labels to. Can also be a PR number
|
|
25
|
+
* @param {string[]} labels The list of labels to apply to the newly created PR. Default is []. the funciton will no-op.
|
|
26
|
+
* @returns {Promise<string[]>} The list of resulting labels after the addition of the given labels
|
|
27
|
+
*/
|
|
28
|
+
async function addLabels(octokit, upstream, origin, issue_number, labels) {
|
|
29
|
+
if (!labels || labels.length === 0) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const labelsResponseData = (await octokit.issues.addLabels({
|
|
33
|
+
owner: upstream.owner,
|
|
34
|
+
repo: origin.repo,
|
|
35
|
+
issue_number: issue_number,
|
|
36
|
+
labels: labels,
|
|
37
|
+
})).data;
|
|
38
|
+
logger_1.logger.info(`Successfully added labels ${labels} to issue: ${issue_number}`);
|
|
39
|
+
return labelsResponseData.map(l => l.name);
|
|
40
|
+
}
|
|
41
|
+
exports.addLabels = addLabels;
|
|
42
|
+
//# sourceMappingURL=labels.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BranchDomain, Description, RepoDomain } from '../types';
|
|
2
|
+
import { Octokit } from '@octokit/rest';
|
|
3
|
+
/**
|
|
4
|
+
* Create a GitHub PR on the upstream organization's repo
|
|
5
|
+
* Throws an error if the GitHub API fails
|
|
6
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
7
|
+
* @param {RepoDomain} upstream The upstream repository
|
|
8
|
+
* @param {BranchDomain} origin The remote origin information that contains the origin branch
|
|
9
|
+
* @param {Description} description The pull request title and detailed description
|
|
10
|
+
* @param {boolean} maintainersCanModify Whether or not maintainers can modify the pull request. Default is true
|
|
11
|
+
* @param {string} upstreamPrimary The upstream repository's primary branch. Default is main.
|
|
12
|
+
* @param draft Open a DRAFT pull request. Defaults to false.
|
|
13
|
+
* @returns {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
declare function openPullRequest(octokit: Octokit, upstream: RepoDomain, origin: BranchDomain, description: Description, maintainersCanModify?: boolean, upstreamPrimary?: string, draft?: boolean): Promise<number>;
|
|
16
|
+
export { openPullRequest };
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
// https://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.openPullRequest = void 0;
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
const DEFAULT_PRIMARY = 'main';
|
|
19
|
+
/**
|
|
20
|
+
* Create a GitHub PR on the upstream organization's repo
|
|
21
|
+
* Throws an error if the GitHub API fails
|
|
22
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
23
|
+
* @param {RepoDomain} upstream The upstream repository
|
|
24
|
+
* @param {BranchDomain} origin The remote origin information that contains the origin branch
|
|
25
|
+
* @param {Description} description The pull request title and detailed description
|
|
26
|
+
* @param {boolean} maintainersCanModify Whether or not maintainers can modify the pull request. Default is true
|
|
27
|
+
* @param {string} upstreamPrimary The upstream repository's primary branch. Default is main.
|
|
28
|
+
* @param draft Open a DRAFT pull request. Defaults to false.
|
|
29
|
+
* @returns {Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
async function openPullRequest(octokit, upstream, origin, description, maintainersCanModify = true, upstreamPrimary = DEFAULT_PRIMARY, draft = false) {
|
|
32
|
+
const head = `${origin.owner}:${origin.branch}`;
|
|
33
|
+
const existingPullRequest = (await octokit.pulls.list({
|
|
34
|
+
owner: upstream.owner,
|
|
35
|
+
repo: origin.repo,
|
|
36
|
+
head,
|
|
37
|
+
})).data.find(pr => pr.head.label === head);
|
|
38
|
+
if (existingPullRequest) {
|
|
39
|
+
logger_1.logger.info(`Found existing pull request for reference ${origin.owner}:${origin.branch}. Skipping creating a new pull request.`);
|
|
40
|
+
return existingPullRequest.number;
|
|
41
|
+
}
|
|
42
|
+
const pullResponseData = (await octokit.pulls.create({
|
|
43
|
+
owner: upstream.owner,
|
|
44
|
+
repo: origin.repo,
|
|
45
|
+
title: description.title,
|
|
46
|
+
head: `${origin.owner}:${origin.branch}`,
|
|
47
|
+
base: upstreamPrimary,
|
|
48
|
+
body: description.body,
|
|
49
|
+
maintainer_can_modify: maintainersCanModify,
|
|
50
|
+
draft: draft,
|
|
51
|
+
})).data;
|
|
52
|
+
logger_1.logger.info(`Successfully opened pull request available at url: ${pullResponseData.url}.`);
|
|
53
|
+
return pullResponseData.number;
|
|
54
|
+
}
|
|
55
|
+
exports.openPullRequest = openPullRequest;
|
|
56
|
+
//# sourceMappingURL=open-pull-request.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Changes, CreatePullRequestUserOptions } from './types';
|
|
2
|
+
import { Octokit } from '@octokit/rest';
|
|
3
|
+
/**
|
|
4
|
+
* Make a new GitHub Pull Request with a set of changes applied on top of primary branch HEAD.
|
|
5
|
+
* The changes are committed into a new branch based on the upstream repository options using the authenticated Octokit account.
|
|
6
|
+
* Then a Pull Request is made from that branch.
|
|
7
|
+
*
|
|
8
|
+
* Also throws error if git data from the fork is not ready in 5 minutes.
|
|
9
|
+
*
|
|
10
|
+
* From the docs
|
|
11
|
+
* https://developer.github.com/v3/repos/forks/#create-a-fork
|
|
12
|
+
* """
|
|
13
|
+
* Forking a Repository happens asynchronously.
|
|
14
|
+
* You may have to wait a short period of time before you can access the git objects.
|
|
15
|
+
* If this takes longer than 5 minutes, be sure to contact GitHub Support or GitHub Premium Support.
|
|
16
|
+
* """
|
|
17
|
+
*
|
|
18
|
+
* If changes are empty then the workflow will not run.
|
|
19
|
+
* Rethrows an HttpError if Octokit GitHub API returns an error. HttpError Octokit access_token and client_secret headers redact all sensitive information.
|
|
20
|
+
* @param {Octokit} octokit The authenticated octokit instance, instantiated with an access token having permissiong to create a fork on the target repository
|
|
21
|
+
* @param {Changes | null | undefined} changes A set of changes. The changes may be empty
|
|
22
|
+
* @param {CreatePullRequestUserOptions} options The configuration for interacting with GitHub provided by the user.
|
|
23
|
+
* @returns {Promise<number>} the pull request number. Returns 0 if unsuccessful.
|
|
24
|
+
* @throws {CommitError} on failure during commit process
|
|
25
|
+
*/
|
|
26
|
+
declare function createPullRequest(octokit: Octokit, changes: Changes | null | undefined, options: CreatePullRequestUserOptions): Promise<number>;
|
|
27
|
+
export { Changes, CommitData, CommitSigner } from './types';
|
|
28
|
+
export { createPullRequest };
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
// https://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.createPullRequest = void 0;
|
|
17
|
+
const logger_1 = require("./logger");
|
|
18
|
+
const default_options_handler_1 = require("./default-options-handler");
|
|
19
|
+
const retry = require("async-retry");
|
|
20
|
+
const branch_1 = require("./github/branch");
|
|
21
|
+
const fork_1 = require("./github/fork");
|
|
22
|
+
const commit_and_push_1 = require("./github/commit-and-push");
|
|
23
|
+
const open_pull_request_1 = require("./github/open-pull-request");
|
|
24
|
+
const labels_1 = require("./github/labels");
|
|
25
|
+
/**
|
|
26
|
+
* Make a new GitHub Pull Request with a set of changes applied on top of primary branch HEAD.
|
|
27
|
+
* The changes are committed into a new branch based on the upstream repository options using the authenticated Octokit account.
|
|
28
|
+
* Then a Pull Request is made from that branch.
|
|
29
|
+
*
|
|
30
|
+
* Also throws error if git data from the fork is not ready in 5 minutes.
|
|
31
|
+
*
|
|
32
|
+
* From the docs
|
|
33
|
+
* https://developer.github.com/v3/repos/forks/#create-a-fork
|
|
34
|
+
* """
|
|
35
|
+
* Forking a Repository happens asynchronously.
|
|
36
|
+
* You may have to wait a short period of time before you can access the git objects.
|
|
37
|
+
* If this takes longer than 5 minutes, be sure to contact GitHub Support or GitHub Premium Support.
|
|
38
|
+
* """
|
|
39
|
+
*
|
|
40
|
+
* If changes are empty then the workflow will not run.
|
|
41
|
+
* Rethrows an HttpError if Octokit GitHub API returns an error. HttpError Octokit access_token and client_secret headers redact all sensitive information.
|
|
42
|
+
* @param {Octokit} octokit The authenticated octokit instance, instantiated with an access token having permissiong to create a fork on the target repository
|
|
43
|
+
* @param {Changes | null | undefined} changes A set of changes. The changes may be empty
|
|
44
|
+
* @param {CreatePullRequestUserOptions} options The configuration for interacting with GitHub provided by the user.
|
|
45
|
+
* @returns {Promise<number>} the pull request number. Returns 0 if unsuccessful.
|
|
46
|
+
* @throws {CommitError} on failure during commit process
|
|
47
|
+
*/
|
|
48
|
+
async function createPullRequest(octokit, changes, options) {
|
|
49
|
+
(0, logger_1.setupLogger)(options.logger);
|
|
50
|
+
// if null undefined, or the empty map then no changes have been provided.
|
|
51
|
+
// Do not execute GitHub workflow
|
|
52
|
+
if (changes === null || changes === undefined || changes.size === 0) {
|
|
53
|
+
logger_1.logger.info('Empty change set provided. No changes need to be made. Cancelling workflow.');
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
const gitHubConfigs = (0, default_options_handler_1.addPullRequestDefaults)(options);
|
|
57
|
+
logger_1.logger.info('Starting GitHub PR workflow...');
|
|
58
|
+
const upstream = {
|
|
59
|
+
owner: gitHubConfigs.upstreamOwner,
|
|
60
|
+
repo: gitHubConfigs.upstreamRepo,
|
|
61
|
+
};
|
|
62
|
+
const origin = options.fork === false ? upstream : await (0, fork_1.fork)(octokit, upstream);
|
|
63
|
+
if (options.fork) {
|
|
64
|
+
// try to sync the fork
|
|
65
|
+
await retry(async () => await octokit.repos.mergeUpstream({
|
|
66
|
+
owner: origin.owner,
|
|
67
|
+
repo: origin.repo,
|
|
68
|
+
branch: gitHubConfigs.primary,
|
|
69
|
+
}), {
|
|
70
|
+
retries: options.retry,
|
|
71
|
+
factor: 2.8411,
|
|
72
|
+
minTimeout: 3000,
|
|
73
|
+
randomize: false,
|
|
74
|
+
onRetry: (e, attempt) => {
|
|
75
|
+
e.message = `Error creating syncing upstream: ${e.message}`;
|
|
76
|
+
logger_1.logger.error(e);
|
|
77
|
+
logger_1.logger.info(`Retry attempt #${attempt}...`);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const originBranch = {
|
|
82
|
+
...origin,
|
|
83
|
+
branch: gitHubConfigs.branch,
|
|
84
|
+
};
|
|
85
|
+
// The `retry` flag defaults to `5` to maintain compatibility
|
|
86
|
+
options.retry = options.retry === undefined ? 5 : options.retry;
|
|
87
|
+
const refHeadSha = await retry(async () => await (0, branch_1.branch)(octokit, origin, upstream, originBranch.branch, gitHubConfigs.primary), {
|
|
88
|
+
retries: options.retry,
|
|
89
|
+
factor: 2.8411,
|
|
90
|
+
minTimeout: 3000,
|
|
91
|
+
randomize: false,
|
|
92
|
+
onRetry: (e, attempt) => {
|
|
93
|
+
e.message = `Error creating Pull Request: ${e.message}`;
|
|
94
|
+
logger_1.logger.error(e);
|
|
95
|
+
logger_1.logger.info(`Retry attempt #${attempt}...`);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
await (0, commit_and_push_1.commitAndPush)(octokit, refHeadSha, changes, originBranch, gitHubConfigs.message, gitHubConfigs.force, options);
|
|
99
|
+
const description = {
|
|
100
|
+
body: gitHubConfigs.description,
|
|
101
|
+
title: gitHubConfigs.title,
|
|
102
|
+
};
|
|
103
|
+
const prNumber = await (0, open_pull_request_1.openPullRequest)(octokit, upstream, originBranch, description, gitHubConfigs.maintainersCanModify, gitHubConfigs.primary, options.draft);
|
|
104
|
+
logger_1.logger.info(`Successfully opened pull request: ${prNumber}.`);
|
|
105
|
+
// addLabels will no-op if options.labels is undefined or empty.
|
|
106
|
+
await (0, labels_1.addLabels)(octokit, upstream, originBranch, prNumber, options.labels);
|
|
107
|
+
return prNumber;
|
|
108
|
+
}
|
|
109
|
+
exports.createPullRequest = createPullRequest;
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
// https://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.setupLogger = exports.logger = void 0;
|
|
17
|
+
class NullLogger {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.error = () => { };
|
|
20
|
+
this.warn = () => { };
|
|
21
|
+
this.info = () => { };
|
|
22
|
+
this.debug = () => { };
|
|
23
|
+
this.trace = () => { };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let logger = new NullLogger();
|
|
27
|
+
exports.logger = logger;
|
|
28
|
+
function setupLogger(userLogger) {
|
|
29
|
+
if (userLogger) {
|
|
30
|
+
exports.logger = logger = userLogger;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
exports.logger = logger = new NullLogger();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.setupLogger = setupLogger;
|
|
37
|
+
//# sourceMappingURL=logger.js.map
|