Add getOptionalInput and getRequiredInput
This commit is contained in:
parent
d88fa5cef6
commit
c1cee53da5
18 changed files with 111 additions and 61 deletions
|
|
@ -5,6 +5,29 @@ import * as api from "./api-client";
|
|||
import * as sharedEnv from "./shared-environment";
|
||||
import { isLocalRun, GITHUB_DOTCOM_URL } from "./util";
|
||||
|
||||
/**
|
||||
* Wrapper around core.getInput for inputs that always have a value.
|
||||
* Also see getOptionalInput.
|
||||
*
|
||||
* This allows us to get stronger type checking of required/optional inputs
|
||||
* and make behaviour more consistent between actions and the runner.
|
||||
*/
|
||||
export function getRequiredInput(name: string): string {
|
||||
return core.getInput(name, { required: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around core.getInput that converts empty inputs to undefined.
|
||||
* Also see getRequiredInput.
|
||||
*
|
||||
* This allows us to get stronger type checking of required/optional inputs
|
||||
* and make behaviour more consistent between actions and the runner.
|
||||
*/
|
||||
export function getOptionalInput(name: string): string | undefined {
|
||||
const value = core.getInput(name);
|
||||
return value.length > 0 ? value : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an environment parameter, but throw an error if it is not set.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue