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

2
dist/index.js vendored
View File

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