Skip to content

Commit 7d11768

Browse files
committed
fix: correctly populate inputs
1 parent 32b0e6a commit 7d11768

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

dist/index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,8 +3528,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
35283528
const core = __importStar(__webpack_require__(470));
35293529
const github = __importStar(__webpack_require__(469));
35303530
const create_1 = __webpack_require__(646);
3531+
// nullify getInput empty results
3532+
// to allow coalescence ?? operator
3533+
function getInput(name, options) {
3534+
const result = core.getInput(name, options);
3535+
if (result === '') {
3536+
return null;
3537+
}
3538+
return result;
3539+
}
35313540
function run() {
3532-
var _a, _b, _c, _d, _e;
3541+
var _a, _b, _c, _d, _e, _f, _g;
35333542
return __awaiter(this, void 0, void 0, function* () {
35343543
let token;
35353544
let type;
@@ -3545,22 +3554,22 @@ function run() {
35453554
console.log(`ref: ${ref}`);
35463555
try {
35473556
console.log('Inputs..');
3548-
token = core.getInput('token', { required: true });
3549-
type = core.getInput('type', { required: true });
3557+
token = (_a = getInput('token', { required: true })) !== null && _a !== void 0 ? _a : '';
3558+
type = getInput('type', { required: true });
35503559
console.log(`type: ${type}`);
3551-
logsUrl = (_a = core.getInput('logs')) !== null && _a !== void 0 ? _a : '';
3560+
logsUrl = (_b = getInput('logs')) !== null && _b !== void 0 ? _b : '';
35523561
console.log(`logs: ${logsUrl}`);
3553-
description = (_b = core.getInput('description')) !== null && _b !== void 0 ? _b : `deployed by ${actor}`;
3562+
description = (_c = getInput('description')) !== null && _c !== void 0 ? _c : `deployed by ${actor}`;
35543563
console.log(`description: ${description}`);
3555-
initialStatus = ((_c = core.getInput('initial_status')) !== null && _c !== void 0 ? _c : 'in_progress');
3564+
initialStatus = ((_d = getInput('initial_status')) !== null && _d !== void 0 ? _d : 'in_progress');
35563565
console.log(`initialStatus: ${initialStatus}`);
35573566
// default to branch name w/o `deploy-` prefix
3558-
environment = (_d = core.getInput('environment')) !== null && _d !== void 0 ? _d : (ref).replace(/^refs\/heads/, '').replace(/^deploy-/, '');
3567+
environment = (_e = getInput('environment')) !== null && _e !== void 0 ? _e : ref.replace('refs/heads/', '').replace(/^deploy-/, '');
35593568
console.log(`environment: ${environment}`);
3560-
environmentUrl = (_e = core.getInput('environment_url')) !== null && _e !== void 0 ? _e : '';
3569+
environmentUrl = (_f = getInput('environment_url')) !== null && _f !== void 0 ? _f : '';
35613570
console.log(`environmentUrl: ${environmentUrl}`);
35623571
const shouldRequireDeploymentId = type === 'status' || type === 'delete';
3563-
deploymentId = core.getInput('deployment_id', { required: shouldRequireDeploymentId });
3572+
deploymentId = (_g = getInput('deployment_id', { required: shouldRequireDeploymentId })) !== null && _g !== void 0 ? _g : '0';
35643573
}
35653574
catch (error) {
35663575
core.error(error);

src/main.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import { DeploymentStatus } from './deployment-status'
55

66
type ActionType = 'create' | 'delete' | 'delete-all' | 'status'
77

8+
// nullify getInput empty results
9+
// to allow coalescence ?? operator
10+
function getInput (name: string, options?: core.InputOptions): string | null {
11+
const result = core.getInput(name, options)
12+
if (result === '') {
13+
return null
14+
}
15+
return result
16+
}
17+
818
async function run (): Promise<void> {
919
let token: string
1020
let type: ActionType
@@ -23,29 +33,29 @@ async function run (): Promise<void> {
2333

2434
try {
2535
console.log('Inputs..')
26-
token = core.getInput('token', { required: true })
36+
token = getInput('token', { required: true }) ?? ''
2737

28-
type = core.getInput('type', { required: true }) as ActionType
38+
type = getInput('type', { required: true }) as ActionType
2939
console.log(`type: ${type}`)
3040

31-
logsUrl = core.getInput('logs') ?? ''
41+
logsUrl = getInput('logs') ?? ''
3242
console.log(`logs: ${logsUrl}`)
3343

34-
description = core.getInput('description') ?? `deployed by ${actor}`
44+
description = getInput('description') ?? `deployed by ${actor}`
3545
console.log(`description: ${description}`)
3646

37-
initialStatus = (core.getInput('initial_status') ?? 'in_progress') as DeploymentStatus
47+
initialStatus = (getInput('initial_status') ?? 'in_progress') as DeploymentStatus
3848
console.log(`initialStatus: ${initialStatus}`)
3949

4050
// default to branch name w/o `deploy-` prefix
41-
environment = core.getInput('environment') ?? (ref).replace(/^refs\/heads/, '').replace(/^deploy-/, '')
51+
environment = getInput('environment') ?? ref.replace('refs/heads/', '').replace(/^deploy-/, '')
4252
console.log(`environment: ${environment}`)
4353

44-
environmentUrl = core.getInput('environment_url') ?? ''
54+
environmentUrl = getInput('environment_url') ?? ''
4555
console.log(`environmentUrl: ${environmentUrl}`)
4656

4757
const shouldRequireDeploymentId = type === 'status' || type === 'delete'
48-
deploymentId = core.getInput('deployment_id', { required: shouldRequireDeploymentId })
58+
deploymentId = getInput('deployment_id', { required: shouldRequireDeploymentId }) ?? '0'
4959
} catch (error) {
5060
core.error(error)
5161
core.setFailed(`Wrong parameters given: ${JSON.stringify(error, null, 2)}`)

tests/main.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ test('test create', () => {
66
process.env['INPUT_TOKEN'] = 'fake-token'
77
process.env['INPUT_TYPE'] = 'create'
88
process.env['GITHUB_REPOSITORY'] = 'owner/repo'
9+
process.env['GITHUB_REF'] = 'refs/heads/master'
10+
process.env['GITHUB_ACTOR'] = 'fake-actor'
911
const ip = path.join(__dirname, '..', 'lib', 'main.js')
1012
const options: cp.ExecSyncOptions = {
1113
env: process.env

0 commit comments

Comments
 (0)