Skip to content

Commit

Permalink
fix(worker/autodiscover): retain repo order on filtering (#32402)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Nov 7, 2024
1 parent f66b8f9 commit 63151a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/workers/global/autodiscover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
6 changes: 5 additions & 1 deletion lib/workers/global/autodiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -116,5 +120,5 @@ export function applyFilters(repos: string[], filters: string[]): string[] {
matched.add(repository);
}
}
return [...matched];
return repos.filter((repository) => matched.has(repository));
}

0 comments on commit 63151a4

Please # to comment.