release-please 17.7.0 → 17.9.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/build/src/factory.js +4 -0
- 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/plugins/linked-versions.js +1 -1
- package/build/src/strategies/go-librarian.d.ts +9 -0
- package/build/src/strategies/go-librarian.js +70 -0
- package/build/src/strategies/java-yoshi-mono-repo.js +1 -1
- package/build/src/strategies/node-librarian.js +1 -1
- package/build/src/strategies/python-librarian.d.ts +6 -0
- package/build/src/strategies/python-librarian.js +35 -0
- package/build/src/updaters/go/version-go.js +1 -1
- package/build/src/updaters/{node/librarian-yaml.d.ts → librarian-yaml.d.ts} +16 -7
- package/build/src/updaters/librarian-yaml.js +120 -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 +3 -2
- package/build/src/updaters/java/librarian-yaml.d.ts +0 -29
- package/build/src/updaters/java/librarian-yaml.js +0 -81
- package/build/src/updaters/node/librarian-yaml.js +0 -73
|
@@ -0,0 +1,118 @@
|
|
|
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.branch = exports.createBranch = exports.existsBranchWithName = exports.getBranchHead = exports.createRef = void 0;
|
|
17
|
+
const logger_1 = require("../logger");
|
|
18
|
+
const REF_PREFIX = 'refs/heads/';
|
|
19
|
+
const DEFAULT_PRIMARY_BRANCH = 'main';
|
|
20
|
+
/**
|
|
21
|
+
* Create a new branch reference with the ref prefix
|
|
22
|
+
* @param {string} branchName name of the branch
|
|
23
|
+
*/
|
|
24
|
+
function createRef(branchName) {
|
|
25
|
+
return REF_PREFIX + branchName;
|
|
26
|
+
}
|
|
27
|
+
exports.createRef = createRef;
|
|
28
|
+
/**
|
|
29
|
+
* get branch commit HEAD SHA of a repository
|
|
30
|
+
* Throws an error if the branch cannot be found
|
|
31
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
32
|
+
* @param {RepoDomain} origin The domain information of the remote origin repository
|
|
33
|
+
* @param {string} branch the name of the branch
|
|
34
|
+
* @returns {Promise<string>} branch commit HEAD SHA
|
|
35
|
+
*/
|
|
36
|
+
async function getBranchHead(octokit, origin, branch) {
|
|
37
|
+
const branchData = (await octokit.repos.getBranch({
|
|
38
|
+
owner: origin.owner,
|
|
39
|
+
repo: origin.repo,
|
|
40
|
+
branch,
|
|
41
|
+
})).data;
|
|
42
|
+
logger_1.logger.info(`Successfully found branch HEAD sha "${branchData.commit.sha}".`);
|
|
43
|
+
return branchData.commit.sha;
|
|
44
|
+
}
|
|
45
|
+
exports.getBranchHead = getBranchHead;
|
|
46
|
+
/**
|
|
47
|
+
* Determine if there is a branch with the provided name in the remote GitHub repository
|
|
48
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
49
|
+
* @param {RepoDomain} remote The domain information of the remote repository
|
|
50
|
+
* @param {string} name The branch name to create on the repository
|
|
51
|
+
* @returns {Promise<boolean>} if there is a branch already existing in the remote GitHub repository
|
|
52
|
+
*/
|
|
53
|
+
async function existsBranchWithName(octokit, remote, name) {
|
|
54
|
+
try {
|
|
55
|
+
const data = (await octokit.git.getRef({
|
|
56
|
+
owner: remote.owner,
|
|
57
|
+
repo: remote.repo,
|
|
58
|
+
ref: `heads/${name}`,
|
|
59
|
+
})).data;
|
|
60
|
+
return data.ref ? true : false;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
if (err.status === 404)
|
|
64
|
+
return false;
|
|
65
|
+
else
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.existsBranchWithName = existsBranchWithName;
|
|
70
|
+
/**
|
|
71
|
+
* Create a branch on the remote repository if there is not an existing branch
|
|
72
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
73
|
+
* @param {RepoDomain} remote The domain information of the remote origin repository
|
|
74
|
+
* @param {string} name The branch name to create on the origin repository
|
|
75
|
+
* @param {string} baseSha the sha that the base of the reference points to
|
|
76
|
+
* @param {boolean} duplicate whether there is an existing branch or not
|
|
77
|
+
* @returns {Promise<void>}
|
|
78
|
+
*/
|
|
79
|
+
async function createBranch(octokit, remote, name, baseSha, duplicate) {
|
|
80
|
+
if (!duplicate) {
|
|
81
|
+
const refData = (await octokit.git.createRef({
|
|
82
|
+
owner: remote.owner,
|
|
83
|
+
repo: remote.repo,
|
|
84
|
+
ref: createRef(name),
|
|
85
|
+
sha: baseSha,
|
|
86
|
+
})).data;
|
|
87
|
+
logger_1.logger.info(`Successfully created branch at ${refData.url}`);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
logger_1.logger.info('Skipping branch creation step...');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.createBranch = createBranch;
|
|
94
|
+
/**
|
|
95
|
+
* Create a GitHub branch given a remote origin.
|
|
96
|
+
* Throws an exception if octokit fails, or if the base branch is invalid
|
|
97
|
+
* @param {Octokit} octokit The authenticated octokit instance
|
|
98
|
+
* @param {RepoDomain} origin The domain information of the remote origin repository
|
|
99
|
+
* @param {RepoDomain} upstream The domain information of the remote upstream repository
|
|
100
|
+
* @param {string} name The branch name to create on the origin repository
|
|
101
|
+
* @param {string} baseBranch the name of the branch to base the new branch off of. Default is main
|
|
102
|
+
* @returns {Promise<string>} the base SHA for subsequent commits to be based off for the origin branch
|
|
103
|
+
*/
|
|
104
|
+
async function branch(octokit, origin, upstream, name, baseBranch = DEFAULT_PRIMARY_BRANCH) {
|
|
105
|
+
// create branch from primary branch HEAD SHA
|
|
106
|
+
try {
|
|
107
|
+
const baseSha = await getBranchHead(octokit, upstream, baseBranch);
|
|
108
|
+
const duplicate = await existsBranchWithName(octokit, origin, name);
|
|
109
|
+
await createBranch(octokit, origin, name, baseSha, duplicate);
|
|
110
|
+
return baseSha;
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
logger_1.logger.error('Error when creating branch');
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.branch = branch;
|
|
118
|
+
//# sourceMappingURL=branch.js.map
|
|
@@ -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 };
|