Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add new getBooleanInput function for the core #723

Closed
yi-Xu-0100 opened this issue Feb 21, 2021 · 1 comment · Fixed by #725
Closed

[feature] Add new getBooleanInput function for the core #723

yi-Xu-0100 opened this issue Feb 21, 2021 · 1 comment · Fixed by #725
Labels
enhancement New feature or request

Comments

@yi-Xu-0100
Copy link
Contributor

yi-Xu-0100 commented Feb 21, 2021

Thank you 🙇‍♀ for wanting to create an issue in this repository. Before you do, please ensure you are filing the issue in the right place. Issues should only be opened on if the issue relates to code in this repository.

If your issue is relevant to this repository, please include the information below:

Describe the enhancement

get the correct boolean input of workflows.

Code Snippet

export function getBooleanInput(booleanInputName: string, options?: core.InputOptions) {
  const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON'];
  const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF'];
  var stringInput = core.getInput(booleanInputName, options);
  if (trueValue.indexOf(stringInput) > -1) return true;
  if (falseValue.indexOf(stringInput) > -1) return false;
  throw TypeError(`Wrong boolean input value of ${booleanInputName}`);
}
const booleanInput = getBooleanInput('booleanInput')

Additional information

https://yaml.org/type/bool.html

@yi-Xu-0100
Copy link
Contributor Author

/**
 * 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
 *
 * @param     name     name of the input to get
 * @returns   boolean
 */
export function getBooleanInput(name: string): boolean {
  const trueValue = [
    'true',
    'True',
    'TRUE',
    'yes',
    'Yes',
    'YES',
    'y',
    'Y',
    'on',
    'On',
    'ON'
  ]
  const falseValue = [
    'false',
    'False',
    'FALSE',
    'no',
    'No',
    'NO',
    'n',
    'N',
    'off',
    'Off',
    'OFF'
  ]
  const val: string = (
    process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
  ).trim()
  if (trueValue.includes(val)) return true
  if (falseValue.includes(val)) return false
  throw new TypeError(`Input does not meet YAML specifications: ${name}`)
}

yi-Xu-0100 added a commit to yi-Xu-0100/toolkit that referenced this issue Feb 24, 2021
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 actions#723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant