diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index b6673d42fc629ac16de707cf44ffbf2ff98fe36e..3f243012c107afea0e6f27bda1aadc1e7cf1f5df 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -81,7 +81,7 @@ e.g. ```json { - "autodiscoverFilter": "project/*" + "autodiscoverFilter": ["project/*"] } ``` diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts index ecc1d455c5f7b1cab22947cc6e03a6a1946d694a..9d9d2c57f8c3a6c2daede7cb7d55b9e172ce3323 100644 --- a/lib/config/definitions.ts +++ b/lib/config/definitions.ts @@ -579,7 +579,9 @@ const options: RenovateOptions[] = [ name: 'autodiscoverFilter', description: 'Filter the list of autodiscovered repositories.', stage: 'global', - type: 'string', + type: 'array', + subType: 'string', + allowString: true, default: null, }, { diff --git a/lib/config/types.ts b/lib/config/types.ts index ba94103c94458960d7df9a9aa86428df5aeb05db..cadba956bcbe4464361648ffc8d4e5674e3889b3 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -68,7 +68,7 @@ export interface RenovateSharedConfig { // The below should contain config options where stage=global export interface GlobalOnlyConfig { autodiscover?: boolean; - autodiscoverFilter?: string; + autodiscoverFilter?: string[]; baseDir?: string; forceCli?: boolean; gitPrivateKey?: string; diff --git a/lib/workers/global/autodiscover.spec.ts b/lib/workers/global/autodiscover.spec.ts index 7779fcd41ff571a07318db31a3a1ab37a9e2e756..bec82c983af74b5330e1d65dfde3a9512393a19d 100644 --- a/lib/workers/global/autodiscover.spec.ts +++ b/lib/workers/global/autodiscover.spec.ts @@ -49,18 +49,36 @@ describe(getName(__filename), () => { }); it('filters autodiscovered github repos', async () => { config.autodiscover = true; - config.autodiscoverFilter = 'project/re*'; + config.autodiscoverFilter = ['project/re*', 'new/prj*']; config.platform = PLATFORM_TYPE_GITHUB; hostRules.find = jest.fn(() => ({ token: 'abc', })); ghApi.getRepos = jest.fn(() => - Promise.resolve(['project/repo', 'project/another-repo']) + Promise.resolve([ + 'project/repo', + 'project/another-repo', + 'new/prj-test', + 'new/not-matched', + ]) ); const res = await autodiscoverRepositories(config); - expect(res.repositories).toEqual(['project/repo']); + expect(res.repositories).toEqual(['project/repo', 'new/prj-test']); }); it('filters autodiscovered github repos but nothing matches', async () => { + config.autodiscover = true; + config.autodiscoverFilter = ['project/re*']; + config.platform = 'github'; + hostRules.find = jest.fn(() => ({ + token: 'abc', + })); + ghApi.getRepos = jest.fn(() => + Promise.resolve(['another-project/repo', 'another-project/another-repo']) + ); + const res = await autodiscoverRepositories(config); + expect(res).toEqual(config); + }); + it('filters autodiscovered github repos with string variable', async () => { config.autodiscover = true; config.autodiscoverFilter = 'project/re*'; config.platform = 'github'; diff --git a/lib/workers/global/autodiscover.ts b/lib/workers/global/autodiscover.ts index 396f32b9e2c19b730eb9b9af5f089f4728c6c73d..bfc3b666d2d0a3edbaf5333008bbeb2cb78fd99f 100644 --- a/lib/workers/global/autodiscover.ts +++ b/lib/workers/global/autodiscover.ts @@ -30,7 +30,14 @@ export async function autodiscoverRepositories( return config; } if (config.autodiscoverFilter) { - discovered = discovered.filter(minimatch.filter(config.autodiscoverFilter)); + const matched = new Set<string>(); + + for (const filter of config.autodiscoverFilter) { + const res = minimatch.match(discovered, filter); + res.forEach((e) => matched.add(e)); + } + + discovered = [...matched]; if (!discovered.length) { // Soft fail (no error thrown) if no accessible repositories match the filter logger.debug('None of the discovered repositories matched the filter');