This commit is contained in:
Alexander Kachkaev
2023-03-27 09:44:05 +01:00
parent b898cc8e29
commit b28379f6ed
3 changed files with 13 additions and 28 deletions

View File

@@ -22,13 +22,16 @@ const configureInput = (
mockInput: Partial<{
'repo-token': string;
'configuration-path': string;
'sync-labels': boolean;
dot: boolean;
'sync-labels': string;
dot: string;
}>
) => {
jest
.spyOn(core, 'getInput')
.mockImplementation((name: string, ...opts) => mockInput[name]);
jest
.spyOn(core, 'getBooleanInput')
.mockImplementation((name: string, ...opts) => mockInput[name] === 'true');
};
afterAll(() => jest.restoreAllMocks());
@@ -52,7 +55,7 @@ describe('run', () => {
});
it('(with dot: true) adds labels to PRs that match our glob patterns', async () => {
configureInput({dot: true});
configureInput({dot: 'true'});
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('.foo.pdf');
@@ -80,7 +83,7 @@ describe('run', () => {
});
it('(with dot: true) does not add labels to PRs that do not match our glob patterns', async () => {
configureInput({dot: true});
configureInput({dot: 'true'});
usingLabelerConfigYaml('only_pdfs.yml');
mockGitHubResponseChangedFiles('foo.txt');
@@ -91,20 +94,11 @@ describe('run', () => {
});
it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
const mockInput = {
configureInput({
'repo-token': 'foo',
'configuration-path': 'bar',
'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');
@@ -127,20 +121,11 @@ 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 () => {
const mockInput = {
configureInput({
'repo-token': 'foo',
'configuration-path': 'bar',
'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');

2
dist/index.js vendored
View File

@@ -50,7 +50,7 @@ function run() {
const token = core.getInput('repo-token');
const configPath = core.getInput('configuration-path', { required: true });
const syncLabels = core.getBooleanInput('sync-labels');
const dot = !!core.getInput('dot', { required: false });
const dot = !!core.getBooleanInput('dot', { required: false });
const prNumber = getPrNumber();
if (!prNumber) {
core.info('Could not get pull request number from context, exiting');

View File

@@ -16,7 +16,7 @@ export async function run() {
const token = core.getInput('repo-token');
const configPath = core.getInput('configuration-path', {required: true});
const syncLabels = core.getBooleanInput('sync-labels');
const dot = !!core.getInput('dot', {required: false});
const dot = !!core.getBooleanInput('dot', {required: false});
const prNumber = getPrNumber();
if (!prNumber) {