豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 639ed26

Browse files
gkalpakdevversion
authored andcommitted
feat(github-actions): allow specifying a base branch in create-pr-for-changes
Previously, the `create-pr-for-changes` GitHub action would use the branch that the workflow was triggered on as the base branch. This prevented the action from being used on other branches as part of a [scheduled workflow][1], since scheduled workflows are only triggered on the default branch of a repository. This commit adds the ability to specify a different base branch. If not specified, this defaults to the branch the workflow was triggered on, as before. [1]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
1 parent 38a9f9e commit 639ed26

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

github-actions/create-pr-for-changes/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ description: |
88
author: Angular
99

1010
inputs:
11+
base-branch:
12+
required: false
13+
default: ${{ github.ref_name }}
14+
description: |
15+
The base branch of the pull request (if one is created).
16+
17+
Defaults to the branch that the workflow was triggered on.
18+
19+
Example: `base-branch: my-patch-branch`
1120
branch-prefix:
1221
required: true
1322
description: |

github-actions/create-pr-for-changes/lib/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function main(): Promise<void> {
4848

4949
// Unless configured otherwise, clean up obsolete branches.
5050
const branchPrefix = `${core.getInput('branch-prefix', {required: true})}-`;
51-
const cleanUpBranches = core.getInput('clean-up-branches', {required: false}) === 'true';
51+
const cleanUpBranches = core.getInput('clean-up-branches', {required: true}) === 'true';
5252
const forkRepo = await git.getForkOfAuthenticatedUser();
5353

5454
if (cleanUpBranches) {
@@ -79,7 +79,7 @@ async function main(): Promise<void> {
7979
// Hashing the contents of the changed files is a heuristic to uniquely-ish represent a
8080
// particular set of changes. It is not 100% accurate (and could result in both false
8181
// positives and false negatives), but should be good enough for our purposes.
82-
const baseBranch = context.ref.replace(/^refs\/heads\//, '');
82+
const baseBranch = core.getInput('base-branch', {required: true});
8383
const branchName = `${branchPrefix}${repo.owner}-${repo.name}-${baseBranch}-${hashFiles(
8484
touchedFiles,
8585
)}`;

github-actions/create-pr-for-changes/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24749,7 +24749,7 @@ async function main() {
2474924749
git.run(["config", "user.name", "Angular Robot"]);
2475024750
core.info("Initialized git/GitHub client.");
2475124751
const branchPrefix = `${core.getInput("branch-prefix", { required: true })}-`;
24752-
const cleanUpBranches = core.getInput("clean-up-branches", { required: false }) === "true";
24752+
const cleanUpBranches = core.getInput("clean-up-branches", { required: true }) === "true";
2475324753
const forkRepo = await git.getForkOfAuthenticatedUser();
2475424754
if (cleanUpBranches) {
2475524755
await cleanUpObsoleteBranches(git, repo, forkRepo, branchPrefix);
@@ -24761,7 +24761,7 @@ async function main() {
2476124761
} else {
2476224762
core.info(`Found ${touchedFiles.length} affected file(s).`);
2476324763
}
24764-
const baseBranch = import_github4.context.ref.replace(/^refs\/heads\//, "");
24764+
const baseBranch = core.getInput("base-branch", { required: true });
2476524765
const branchName = `${branchPrefix}${repo.owner}-${repo.name}-${baseBranch}-${hashFiles(touchedFiles)}`;
2476624766
const { data: matchingPrs } = await git.github.pulls.list({
2476724767
owner: repo.owner,

0 commit comments

Comments
 (0)