Skip to content

Commit

Permalink
fix(get-changed-files): allow space delimiter (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Jan 10, 2024
1 parent a7fd137 commit a29a874
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
5 changes: 4 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47554,7 +47554,10 @@ limitations under the License.

const getActionInputs = (requiredInputs = []) => {
const yamlContents = (0,external_fs_.readFileSync)(`${__dirname}/action.yml`).toString();
const inputsFromFile = getInputsFromFile(yamlContents).reduce((acc, current) => (Object.assign(Object.assign({}, acc), { [current]: (0,core.getInput)(current, { required: requiredInputs.includes(current) }) })), {});
const inputsFromFile = getInputsFromFile(yamlContents).reduce((acc, current) => {
const trimWhitespaceOptions = current === 'delimiter' ? { trimWhitespace: false } : {};
return Object.assign(Object.assign({}, acc), { [current]: (0,core.getInput)(current, Object.assign({ required: requiredInputs.includes(current) }, trimWhitespaceOptions)) });
}, {});
return (0,lodash.pickBy)(inputsFromFile);
};

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

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/utils/get-action-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { readFileSync } from 'fs';

export const getActionInputs = (requiredInputs: string[] = []) => {
const yamlContents = readFileSync(`${__dirname}/action.yml`).toString();
const inputsFromFile = getInputsFromFile(yamlContents).reduce(
(acc, current) => ({
const inputsFromFile = getInputsFromFile(yamlContents).reduce((acc, current) => {
const trimWhitespaceOptions = current === 'delimiter' ? { trimWhitespace: false } : {};
return {
...acc,
[current]: getInput(current, { required: requiredInputs.includes(current) })
}),
{}
);
[current]: getInput(current, { required: requiredInputs.includes(current), ...trimWhitespaceOptions })
};
}, {});

return pickBy(inputsFromFile);
};
15 changes: 14 additions & 1 deletion test/utils/get-action-inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jest.mock('fs', () => ({
}))
}));

(getInputsFromFile as jest.Mock).mockReturnValue(['input1', 'input2', 'input3']);
(getInput as jest.Mock).mockImplementation(input => (input === 'input2' ? '' : input));

describe('getActionInputs', () => {
const requiredInputs = ['input1'];

it('should call getInput with correct params and return expected inputs', () => {
(getInputsFromFile as jest.Mock).mockReturnValue(['input1', 'input2', 'input3']);
const result = getActionInputs(requiredInputs);

expect(getInput).toHaveBeenCalledWith('input1', { required: true });
Expand All @@ -43,4 +43,17 @@ describe('getActionInputs', () => {
input3: 'input3'
});
});

it('should call getInput with trimWhiteSpace false for delimiter input', () => {
(getInputsFromFile as jest.Mock).mockReturnValue(['input1', 'input2', 'delimiter']);
const result = getActionInputs(requiredInputs);

expect(getInput).toHaveBeenCalledWith('input1', { required: true });
expect(getInput).toHaveBeenCalledWith('input2', { required: false });
expect(getInput).toHaveBeenCalledWith('delimiter', { required: false, trimWhitespace: false });
expect(result).toEqual({
input1: 'input1',
delimiter: 'delimiter'
});
});
});

0 comments on commit a29a874

Please sign in to comment.