From 63151a42146bd23befa03dacfa2afc6a86647019 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Thu, 7 Nov 2024 15:00:24 +0100 Subject: [PATCH] fix(worker/autodiscover): retain repo order on filtering (#32402) --- lib/workers/global/autodiscover.spec.ts | 4 +++- lib/workers/global/autodiscover.ts | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/workers/global/autodiscover.spec.ts b/lib/workers/global/autodiscover.spec.ts index bca4cf969d3da2..8af94614df7c4a 100644 --- a/lib/workers/global/autodiscover.spec.ts +++ b/lib/workers/global/autodiscover.spec.ts @@ -167,9 +167,11 @@ describe('workers/global/autodiscover', () => { hostRules.find = jest.fn(() => ({ token: 'abc', })); + // retains order const expectedRepositories = [ - 'another-project/repo', 'department/dev/aProject', + 'another-project/repo', + 'department/dev/bProject', ]; ghApi.getRepos = jest.fn(() => Promise.resolve([ diff --git a/lib/workers/global/autodiscover.ts b/lib/workers/global/autodiscover.ts index e4da1e8c403b5b..6f45baf907cd2e 100644 --- a/lib/workers/global/autodiscover.ts +++ b/lib/workers/global/autodiscover.ts @@ -51,6 +51,10 @@ export async function autodiscoverRepositories( } logger.debug(`Autodiscovered ${discovered.length} repositories`); + logger.trace( + { length: discovered.length, repositories: discovered }, + `Autodiscovered repositories`, + ); if (autodiscoverFilter) { logger.debug({ autodiscoverFilter }, 'Applying autodiscoverFilter'); @@ -116,5 +120,5 @@ export function applyFilters(repos: string[], filters: string[]): string[] { matched.add(repository); } } - return [...matched]; + return repos.filter((repository) => matched.has(repository)); }