diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index bd4f6cd1a..6b10904cb 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -313,6 +313,15 @@ describe('run', () => { ); }); + it('does not add labels to PRs that have no changed files', async () => { + usingLabelerConfigYaml('only_pdfs.yml'); + mockGitHubResponseChangedFiles(); + + await run(); + + expect(setLabelsMock).toHaveBeenCalledTimes(0); + }); + it('should use local configuration file if it exists', async () => { const configFile = 'only_pdfs.yml'; const configFilePath = path.join(__dirname, 'fixtures', configFile); diff --git a/dist/index.js b/dist/index.js index 50da5bd83..5cb19babf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -81,6 +81,10 @@ function run() { } core.debug(`fetching changed files for pr #${prNumber}`); const changedFiles = yield getChangedFiles(client, prNumber); + if (!changedFiles.length) { + core.warning(`Pull request #${prNumber} has no changed files, skipping`); + continue; + } const labelGlobs = yield getLabelGlobs(client, configPath); const preexistingLabels = pullRequest.labels.map(l => l.name); const allLabels = new Set(preexistingLabels); diff --git a/src/labeler.ts b/src/labeler.ts index 8893a81e5..995abaa35 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -48,6 +48,13 @@ export async function run() { core.debug(`fetching changed files for pr #${prNumber}`); const changedFiles: string[] = await getChangedFiles(client, prNumber); + if (!changedFiles.length) { + core.warning( + `Pull request #${prNumber} has no changed files, skipping` + ); + continue; + } + const labelGlobs: Map = await getLabelGlobs(client, configPath);