如何在 Github 中自动打开 PR 列表?
How to open a list of PRs automatically in Github?
我们有一个包含分支列表 (50-100) 的 repo(SaaS 项目),master 分支是最新的,所以我想为我们必须更新的每个分支打开一个 PR 列表来自
master -> client-*
那么有没有办法自动处理这种情况?
您可以使用 Github 的 API 来获取所有分支并发布 PR。不幸的是,Github 没有提供在列出分支时进行过滤的方法,因此您仍然需要在自己的代码中应用该过滤器。
这是一个使用 Octokit. The two methods needed are repos.listBranches and pulls.create.
的示例执行
Example Implementation
// Fetching branches...
const branches = await userClient.paginate(userClient.rest.repos.listBranches, {
owner: ownerId,
repo: reposId,
});
// Filtering the retrieved branches.
const prefixedBranches = branches.filter((branch) => branch.name.startsWith(branchPrefix));
console.log(`${prefixedBranches.length} branches match the filter`);
// Creating pull requests...
const result = await Promise.allSettled(
prefixedBranches.map((branch) => {
return userClient.rest.pulls.create({
title: `Fusebit Generated PR from ${branch.name}`,
head: branch.name,
base: targetBranch,
owner: ownerId,
repo: reposId,
});
})
);
我们有一个包含分支列表 (50-100) 的 repo(SaaS 项目),master 分支是最新的,所以我想为我们必须更新的每个分支打开一个 PR 列表来自
master -> client-*
那么有没有办法自动处理这种情况?
您可以使用 Github 的 API 来获取所有分支并发布 PR。不幸的是,Github 没有提供在列出分支时进行过滤的方法,因此您仍然需要在自己的代码中应用该过滤器。
这是一个使用 Octokit. The two methods needed are repos.listBranches and pulls.create.
的示例执行Example Implementation |
---|
// Fetching branches...
const branches = await userClient.paginate(userClient.rest.repos.listBranches, {
owner: ownerId,
repo: reposId,
});
// Filtering the retrieved branches.
const prefixedBranches = branches.filter((branch) => branch.name.startsWith(branchPrefix));
console.log(`${prefixedBranches.length} branches match the filter`);
// Creating pull requests...
const result = await Promise.allSettled(
prefixedBranches.map((branch) => {
return userClient.rest.pulls.create({
title: `Fusebit Generated PR from ${branch.name}`,
head: branch.name,
base: targetBranch,
owner: ownerId,
repo: reposId,
});
})
);