Skip to content

Commit efac182

Browse files
authored
fix: Fix inputs parsing when ctx.inputs is undefined. (#1555)
* Fix inputs parsing when ctx.inputs is undefined. * Remove unused import in basic-inputs/integration.test.ts
1 parent 78b65eb commit efac182

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ function parseIncludeInputs (ctx: any): {inputValue: any; inputType: InputType}
409409

410410
function getInputValue (ctx: any) {
411411
const {inputs, interpolationKey, configFilePath, inputsSpecification} = ctx;
412-
const inputValue = inputs[interpolationKey] ??
412+
const inputValue = inputs?.[interpolationKey] ??
413413
inputsSpecification.spec.inputs[interpolationKey]?.default;
414414
assert(inputValue !== undefined, chalk`This GitLab CI configuration is invalid: \`{blueBright ${configFilePath}}\`: \`{blueBright ${interpolationKey}}\` input: required value has not been provided.`);
415415
return inputValue;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
spec:
3+
inputs:
4+
default_input_string:
5+
type: string
6+
default: string
7+
default_input_number:
8+
default: 1
9+
type: number
10+
default_input_boolean:
11+
default: true
12+
type: boolean
13+
default_input_array:
14+
type: array
15+
default:
16+
- alice
17+
- bob
18+
---
19+
stages:
20+
- test
21+
scan-website:
22+
script:
23+
- echo $[[ inputs.default_input_string ]]
24+
- echo $[[ inputs.default_input_number ]]
25+
- echo $[[ inputs.default_input_boolean ]]
26+
- $[[ inputs.default_input_array ]]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {WriteStreamsMock} from "../../../src/write-streams.js";
2+
import {handler} from "../../../src/handler.js";
3+
import {initSpawnSpy} from "../../mocks/utils.mock.js";
4+
import {WhenStatics} from "../../mocks/when-statics.js";
5+
6+
beforeAll(() => {
7+
initSpawnSpy(WhenStatics.all);
8+
});
9+
10+
test("basic-inputs defaults no inputs", async () => {
11+
const writeStreams = new WriteStreamsMock();
12+
await handler({
13+
cwd: "tests/test-cases/basic-inputs/input-templates/default-no-inputs",
14+
preview: true,
15+
}, writeStreams);
16+
17+
const expected = `---
18+
stages:
19+
- .pre
20+
- test
21+
- .post
22+
scan-website:
23+
script:
24+
- echo string
25+
- echo 1
26+
- echo true
27+
- alice
28+
- bob`;
29+
30+
expect(writeStreams.stdoutLines[0]).toEqual(expected);
31+
});

0 commit comments

Comments
 (0)