Skip to content

Commit

Permalink
fix: gha input parser
Browse files Browse the repository at this point in the history
  • Loading branch information
lampajr committed Jun 20, 2023
1 parent 941beda commit 95b35aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
19 changes: 14 additions & 5 deletions dist/gha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,26 @@ runner.run();
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core_1 = __nccwpck_require__(2186);
class GHAArgsParser {
/**
* Return the input only if it is not a blank or null string, otherwise returns undefined
* @param key input key
* @returns the value or undefined
*/
_getOrUndefined(key) {
const value = (0, core_1.getInput)(key);
return value !== "" ? value : undefined;
}
parse() {
return {
dryRun: (0, core_1.getInput)("dry-run") === "true",
auth: (0, core_1.getInput)("auth") ? (0, core_1.getInput)("auth") : "",
pullRequest: (0, core_1.getInput)("pull-request"),
targetBranch: (0, core_1.getInput)("target-branch"),
folder: (0, core_1.getInput)("folder") !== "" ? (0, core_1.getInput)("folder") : undefined,
title: (0, core_1.getInput)("title"),
body: (0, core_1.getInput)("body"),
bodyPrefix: (0, core_1.getInput)("body-prefix"),
bpBranchName: (0, core_1.getInput)("bp-branch-name"),
folder: this._getOrUndefined("folder"),
title: this._getOrUndefined("title"),
body: this._getOrUndefined("body"),
bodyPrefix: this._getOrUndefined("body-prefix"),
bpBranchName: this._getOrUndefined("bp-branch-name"),
};
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/service/args/gha/gha-args-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ import { getInput } from "@actions/core";

export default class GHAArgsParser implements ArgsParser {

/**
* Return the input only if it is not a blank or null string, otherwise returns undefined
* @param key input key
* @returns the value or undefined
*/
private _getOrUndefined(key: string): string | undefined {
const value = getInput(key);
return value !== "" ? value : undefined;
}

parse(): Args {
return {
dryRun: getInput("dry-run") === "true",
auth: getInput("auth") ? getInput("auth") : "",
pullRequest: getInput("pull-request"),
targetBranch: getInput("target-branch"),
folder: getInput("folder") !== "" ? getInput("folder") : undefined,
title: getInput("title"),
body: getInput("body"),
bodyPrefix: getInput("body-prefix"),
bpBranchName: getInput("bp-branch-name"),
folder: this._getOrUndefined("folder"),
title: this._getOrUndefined("title"),
body: this._getOrUndefined("body"),
bodyPrefix: this._getOrUndefined("body-prefix"),
bpBranchName: this._getOrUndefined("bp-branch-name"),
};
}

Expand Down

0 comments on commit 95b35aa

Please sign in to comment.