Skip to content

Commit b5b0159

Browse files
committed
fix(circleci-orb): support empty input parameters when e.g. running in cronjob
CircleCI cronjobs do not have the base revision or revision pipeline variables, so they may be empty. To avoid using empty variables which would then cause errors in our shared command- we support the empty string fallback. The command will be a noop anyway since we check for these variables in the actual script. See: https://app.circleci.com/pipelines/github/angular/components/44462.
1 parent 6ca5640 commit b5b0159

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

circleci-orb/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
22

33
ORB_NAME = "angular/dev-infra"
44

5-
ORB_VERSION = "1.0.2"
5+
ORB_VERSION = "1.0.3"
66

77
nodejs_binary(
88
name = "pack_orb_script",

circleci-orb/commands/rebase-pr-on-target-branch.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ description: Rebase PR on the target branch
33
parameters:
44
head_revision:
55
type: string
6+
default: ""
67
description: The `pipeline.git.revision` pipeline value.
78
base_revision:
89
type: string
10+
default: ""
911
description: The `pipeline.git.base_revision` pipeline value.
1012
primary_branch_name:
1113
type: string
12-
description: The primary branch for the repository.
1314
default: 'main'
15+
description: The primary branch for the repository.
1416
shell:
1517
type: string
16-
default: ''
18+
default: ""
1719
description: |
1820
Shell to use for executing the command. Useful for Windows where a
1921
non-bash shell is the default.

circleci-orb/scripts/rebase-pr-on-target-branch/ref-branch-list.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export function getRefFromBranchList(gitOutput: string, primaryBranchName: strin
2525
return b.split('/').slice(1).join('/').trim();
2626
});
2727

28-
const sorted = branches.sort((a: string, b: string) => {
28+
if (branches.length === 0) {
29+
throw new Error(`Could not find ref from branch list: ${gitOutput}`);
30+
}
31+
32+
branches.sort((a: string, b: string) => {
2933
if (a === primaryBranchName) {
3034
return -1;
3135
}
@@ -56,8 +60,5 @@ export function getRefFromBranchList(gitOutput: string, primaryBranchName: strin
5660
return 0;
5761
});
5862

59-
if (sorted.length === 0) {
60-
throw new Error(`Could not find ref from branch list: ${gitOutput}`);
61-
}
62-
return sorted[0];
63+
return branches[0];
6364
}

0 commit comments

Comments
 (0)