Skip to content

Commit 730b76a

Browse files
authored
make sure values not provided by users resolve to undefined (softprops#144)
1 parent 815e458 commit 730b76a

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

__tests__/util.test.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as assert from "assert";
1111

1212
describe("util", () => {
1313
describe("uploadUrl", () => {
14-
it("stripts template", () => {
14+
it("strips template", () => {
1515
assert.equal(
1616
uploadUrl(
1717
"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}"
@@ -95,21 +95,33 @@ describe("util", () => {
9595
});
9696
describe("parseConfig", () => {
9797
it("parses basic config", () => {
98-
assert.deepStrictEqual(parseConfig({}), {
99-
github_ref: "",
100-
github_repository: "",
101-
github_token: "",
102-
input_body: undefined,
103-
input_body_path: undefined,
104-
input_draft: undefined,
105-
input_prerelease: undefined,
106-
input_files: [],
107-
input_name: undefined,
108-
input_tag_name: undefined,
109-
input_fail_on_unmatched_files: false,
110-
input_target_commitish: undefined,
111-
input_discussion_category_name: undefined
112-
});
98+
assert.deepStrictEqual(
99+
parseConfig({
100+
// note: inputs declared in actions.yml, even when declared not required,
101+
// are still provided by the actions runtime env as empty strings instead of
102+
// the normal absent env value one would expect. this breaks things
103+
// as an empty string !== undefined in terms of what we pass to the api
104+
// so we cover that in a test case here to ensure undefined values are actually
105+
// resolved as undefined and not empty strings
106+
INPUT_TARGET_COMMITISH: "",
107+
INPUT_DISCUSSION_CATEGORY_NAME: ""
108+
}),
109+
{
110+
github_ref: "",
111+
github_repository: "",
112+
github_token: "",
113+
input_body: undefined,
114+
input_body_path: undefined,
115+
input_draft: undefined,
116+
input_prerelease: undefined,
117+
input_files: [],
118+
input_name: undefined,
119+
input_tag_name: undefined,
120+
input_fail_on_unmatched_files: false,
121+
input_target_commitish: undefined,
122+
input_discussion_category_name: undefined
123+
}
124+
);
113125
});
114126

115127
it("parses basic config with commitish", () => {

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ export const parseConfig = (env: Env): Config => {
6363
? env.INPUT_PRERELEASE == "true"
6464
: undefined,
6565
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true",
66-
input_target_commitish: env.INPUT_TARGET_COMMITISH,
67-
input_discussion_category_name: env.INPUT_DISCUSSION_CATEGORY_NAME
66+
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
67+
input_discussion_category_name:
68+
env.INPUT_DISCUSSION_CATEGORY_NAME || undefined
6869
};
6970
};
7071

0 commit comments

Comments
 (0)