Skip to content

Commit

Permalink
fix: validation on block-list when used without policy
Browse files Browse the repository at this point in the history
When `block-list` isn't set in the workflow file and policy isn't used.
Validation will fail because the block list is `['']` when undefined.

This commit is a nasty hack and should be replaced with proper validation
using zod library.
  • Loading branch information
jamacku committed May 2, 2023
1 parent ae11cc5 commit 50fa7ab
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 25 deletions.
19 changes: 15 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions dist/labeler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/labeler.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,22 @@ export class Labeler {
this._inputs.section =
inputs.section?.length === 0 ? undefined : inputs.section;

if (inputs.blockList)
this._inputs.blockList =
inputs.blockList?.length === 0 ? undefined : inputs.blockList;
// ! FIXME: Should be handled by zod in future ...
if (inputs.blockList) {
if (inputs.blockList.length === 0) {
this._inputs.blockList = undefined;
return;
}

if (Array.isArray(inputs.blockList) && inputs.blockList.length > 0) {
if (inputs.blockList[0].length === 0) {
this._inputs.blockList = undefined;
return;
}
}

this._inputs.blockList = inputs.blockList;
}
}

get isConfig() {
Expand Down
12 changes: 9 additions & 3 deletions test/unit/__snapshots__/inputs.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@

exports[`Inputs Object > get blockList() 1`] = `undefined`;

exports[`Inputs Object > get blockList() 2`] = `
exports[`Inputs Object > get blockList() 2`] = `undefined`;

exports[`Inputs Object > get blockList() 3`] = `
[
"block1",
"block2",
]
`;

exports[`Inputs Object > get blockList() 3`] = `undefined`;
exports[`Inputs Object > get blockList() 4`] = `undefined`;

exports[`Inputs Object > get section() 1`] = `"section"`;

exports[`Inputs Object > get section() 2`] = `"section"`;

exports[`Inputs Object > get section() 3`] = `"section"`;

exports[`Inputs Object > get section() 4`] = `"section"`;

exports[`Inputs Object > get template() 1`] = `undefined`;

exports[`Inputs Object > get template() 2`] = `undefined`;

exports[`Inputs Object > get template() 3`] = `"template"`;
exports[`Inputs Object > get template() 3`] = `undefined`;

exports[`Inputs Object > get template() 4`] = `"template"`;

exports[`Inputs Object > is invalid 1`] = `
[
Expand Down
1 change: 1 addition & 0 deletions test/unit/fixtures/inputs.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IInputsTestContext {
export const inputsContextFixture: IInputsTestContext = {
inputs: [
new Inputs({ section: 'section' }),
new Inputs({ section: 'section', blockList: undefined }),
new Inputs({ section: 'section', blockList: ['block1', 'block2'] }),
new Inputs({ section: 'section', template: 'template' }),
],
Expand Down
12 changes: 3 additions & 9 deletions test/unit/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ describe('IssueForm Object', () => {
labeler.setInputs({ blockList: [''], template: 'template' });
expect(labeler.inputs).toMatchInlineSnapshot(`
Inputs {
"_blockList": [
"",
],
"_blockList": undefined,
"_section": "section",
"_template": "template",
}
Expand All @@ -69,9 +67,7 @@ describe('IssueForm Object', () => {
labeler.setInputs({ section: '', template: '', blockList: [''] });
expect(labeler.inputs).toMatchInlineSnapshot(`
Inputs {
"_blockList": [
"",
],
"_blockList": undefined,
"_section": "section",
"_template": "template",
}
Expand All @@ -85,9 +81,7 @@ describe('IssueForm Object', () => {
});
expect(labeler.inputs).toMatchInlineSnapshot(`
Inputs {
"_blockList": [
"",
],
"_blockList": undefined,
"_section": "section",
"_template": "template",
}
Expand Down

0 comments on commit 50fa7ab

Please sign in to comment.