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

fix: Boolean false value on inputs breaks configuration syntax #1529

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ function parseIncludeInputs (ctx: any): {inputValue: any; inputType: InputType}

function getInputValue (ctx: any) {
const {inputs, interpolationKey, configFilePath, inputsSpecification} = ctx;
const inputValue = inputs[interpolationKey] || inputsSpecification.spec.inputs[interpolationKey]?.default;
const inputValue = inputs[interpolationKey] ??
inputsSpecification.spec.inputs[interpolationKey]?.default;
assert(inputValue !== undefined, chalk`This GitLab CI configuration is invalid: \`{blueBright ${configFilePath}}\`: \`{blueBright ${interpolationKey}}\` input: required value has not been provided.`);
return inputValue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
include:
- local: '/.gitlab-ci-input-template.yml'
inputs:
boolean_input: false
stages:
- test
24 changes: 23 additions & 1 deletion tests/test-cases/include-inputs/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,11 @@ test_job:
expect(writeStreams.stdoutLines[0]).toEqual(expected);
});

test("include-inputs for type boolean", async () => {
test("include-inputs for type boolean (truthy)", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
cwd: "tests/test-cases/include-inputs/input-templates/types/boolean",
file: ".gitlab-ci-1.yml",
preview: true,
jsonSchemaValidation: true, // this test depends on the json schema validation, do not set to false
}, writeStreams);
Expand All @@ -244,6 +245,27 @@ scan-website:
expect(writeStreams.stdoutLines[0]).toEqual(expected);
});

test("include-inputs for type boolean (falsy)", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
cwd: "tests/test-cases/include-inputs/input-templates/types/boolean",
file: ".gitlab-ci-2.yml",
preview: true,
jsonSchemaValidation: true, // this test depends on the json schema validation, do not set to false
}, writeStreams);

const expected = `---
stages:
- .pre
- test
- .post
scan-website:
script:
- echo false`;

expect(writeStreams.stdoutLines[0]).toEqual(expected);
});
Comment on lines +257 to +267
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const expected = `---
stages:
- .pre
- test
- .post
scan-website:
script:
- echo false`;
expect(writeStreams.stdoutLines[0]).toEqual(expected);
});
const expected = [
"---",
"stages:",
" - .pre",
" - test",
" - .post",
"scan-website:",
" script:",
" - echo false",
];
expect(writeStreams.stdoutLines[0]).toEqual(expected.join("\n"));
});

Copy link
Collaborator Author

@ANGkeith ANGkeith Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been doing the backticks versions in multiple places...

personally i prefer the backticks version because for ease of (typing/copy pasting)...

what's your perspective in this ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't prefer the weird indentation or backticks, but I can live with both 😄


test("include-inputs inputs validation for boolean", async () => {
try {
const writeStreams = new WriteStreamsMock();
Expand Down
Loading