Early exit when no files are changed. (#456)

* Early exit when no files are changed.

As a consequence of the `checkAll` function call returning `true` if the length of `changedFiles` is 0, this must early-exit in order to avoid labeling empty PRs.

* Update dist.

* Update for new code styles.

* review changes requested

* Update dist.

* chore: prettify code

---------

Co-authored-by: MaksimZhukov <maksimzhukov@github.com>
Co-authored-by: IvanZosimov <ivanzosimov@github.com>
This commit is contained in:
Nathan Hammond
2023-07-07 22:35:16 +08:00
committed by GitHub
parent 994304c5d5
commit be13bbd1b7
3 changed files with 20 additions and 0 deletions

View File

@@ -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);

4
dist/index.js vendored
View File

@@ -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);

View File

@@ -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<string, StringOrMatchConfig[]> =
await getLabelGlobs(client, configPath);