Skip to content

Commit

Permalink
fix: correct reading of sync-labels input.
Browse files Browse the repository at this point in the history
Contrary to the assumptions made in the unit tests, core.getInput
always returns a string, and !!'false' is true.

Also updates the unit test to reduce changes of regressions by ensuring
that the mocked getInput returns a string, as it would in production.

Fixes #112

Make sure test catches regressions.
  • Loading branch information
adam-azarchs committed Jan 18, 2023
1 parent b435530 commit 613b00b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ describe('run', () => {
});

it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
let mockInput = {
const mockInput: {[key: string]: string} = {
'repo-token': 'foo',
'configuration-path': 'bar',
'sync-labels': true
'sync-labels': 'true'
};

jest
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);
jest
.spyOn(core, 'getBooleanInput')
.mockImplementation(
(name: string, ...opts) => mockInput[name] === 'true'
);

usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt');
Expand All @@ -79,15 +84,20 @@ describe('run', () => {
});

it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => {
let mockInput = {
const mockInput: {[key: string]: string} = {
'repo-token': 'foo',
'configuration-path': 'bar',
'sync-labels': false
'sync-labels': 'false'
};

jest
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);
jest
.spyOn(core, 'getBooleanInput')
.mockImplementation(
(name: string, ...opts) => mockInput[name] === 'true'
);

usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt');
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function run() {
try {
const token = core.getInput('repo-token', { required: true });
const configPath = core.getInput('configuration-path', { required: true });
const syncLabels = !!core.getInput('sync-labels', { required: false });
const syncLabels = core.getBooleanInput('sync-labels', { required: false });
const prNumber = getPrNumber();
if (!prNumber) {
console.log('Could not get pull request number from context, exiting');
Expand Down
2 changes: 1 addition & 1 deletion src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function run() {
try {
const token = core.getInput('repo-token', {required: true});
const configPath = core.getInput('configuration-path', {required: true});
const syncLabels = !!core.getInput('sync-labels', {required: false});
const syncLabels = core.getBooleanInput('sync-labels');

const prNumber = getPrNumber();
if (!prNumber) {
Expand Down

0 comments on commit 613b00b

Please sign in to comment.