feat(core): add getBooleanInput function#725
Conversation
|
@ericsciple After I read the discussion in #362, I find that the YAML 1.2 core schema is implemented (#362 (comment)). So could we add the |
There was a problem hiding this comment.
Thanks for the contribution @yi-Xu-0100! I left some minor feedback before merging, happy to take the pr over if you don't have the time to continue working on this!
packages/core/src/core.ts
Outdated
| * @param name name of the input to get | ||
| * @returns boolean | ||
| */ | ||
| export function getBooleanInput(name: string): boolean { |
There was a problem hiding this comment.
| export function getBooleanInput(name: string): boolean { | |
| export function getBooleanInput(name: string, options?: InputOptions: boolean) { |
Lets keep consistent with the getInput function. We really shouldn't throw if the value does not exist or is invalid, just return false. We can debug if the parsing does not match either case, to help with troubleshooting if users encounter this issue
We can add another option to InputOptions to set a default value, and return that instead of false if needed as well. I'm happy to tackle that in another pr if you want.
|
@thboop Sorry for the delayed reply, I tried to fix the conflict with the main branch, but it didn't seem to get it right. 😅 So I pulled it again, attached my changes, and pushed it forcibly. The change of what I did:
For the error, I think the function is used to deal with boolean input, It should have a default value in |
Agreed, thanks for the contribution! |
thboop
left a comment
There was a problem hiding this comment.
LGTM thanks for the contribution @yi-Xu-0100!
| const val = getInput(name, options) | ||
| if (trueValue.includes(val)) return true | ||
| if (falseValue.includes(val)) return false | ||
| throw new TypeError( |
There was a problem hiding this comment.
@chamini2 The required: false will be dealt with the getInput(Line 107) and get the default value. 👀
There was a problem hiding this comment.
But if there is no default value, that will make val an empty string, which we don't consider in line 108 or 109. Resulting in throw new TypeError because trueValue.includes('') and falseValue.includes('') are both false.
There was a problem hiding this comment.
Action inputs can be read with
getInputwhich returns astringorgetBooleanInputwhich parses a boolean based on the yaml 1.2 specification. If required set to be false, the input should have a default value inaction.yml.
https://github.com/yi-Xu-0100/toolkit/blob/main/packages/core/README.md
@chamini2 Why a boolean type input have no default value? 👀
There was a problem hiding this comment.
Oh, I did not know this was expected. If required: false and no default I thought it had just to return null or ''. Thanks, sorry for the inconvenience.
Gets the input value of the boolean type in the YAML specification.
The return value is also in boolean type.
ref: https://yaml.org/type/bool.html
close #723