diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 3f243012c107af..b6673d42fc629a 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 9d9d2c57f8c3a6..ecc1d455c5f7b1 100644 --- a/lib/config/definitions.ts +++ b/lib/config/definitions.ts @@ -579,9 +579,7 @@ const options: RenovateOptions[] = [ name: 'autodiscoverFilter', description: 'Filter the list of autodiscovered repositories.', stage: 'global', - type: 'array', - subType: 'string', - allowString: true, + type: 'string', default: null, }, { diff --git a/lib/config/types.ts b/lib/config/types.ts index d873e9027c24ad..7ae1789e6f9a7a 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 bec82c983af74b..7779fcd41ff571 100644 --- a/lib/workers/global/autodiscover.spec.ts +++ b/lib/workers/global/autodiscover.spec.ts @@ -49,36 +49,18 @@ describe(getName(__filename), () => { }); it('filters autodiscovered github repos', async () => { config.autodiscover = true; - config.autodiscoverFilter = ['project/re*', 'new/prj*']; + config.autodiscoverFilter = 'project/re*'; config.platform = PLATFORM_TYPE_GITHUB; hostRules.find = jest.fn(() => ({ token: 'abc', })); ghApi.getRepos = jest.fn(() => - Promise.resolve([ - 'project/repo', - 'project/another-repo', - 'new/prj-test', - 'new/not-matched', - ]) + Promise.resolve(['project/repo', 'project/another-repo']) ); const res = await autodiscoverRepositories(config); - expect(res.repositories).toEqual(['project/repo', 'new/prj-test']); + expect(res.repositories).toEqual(['project/repo']); }); 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 bfc3b666d2d0a3..396f32b9e2c19b 100644 --- a/lib/workers/global/autodiscover.ts +++ b/lib/workers/global/autodiscover.ts @@ -30,14 +30,7 @@ export async function autodiscoverRepositories( return config; } if (config.autodiscoverFilter) { - const matched = new Set(); - - for (const filter of config.autodiscoverFilter) { - const res = minimatch.match(discovered, filter); - res.forEach((e) => matched.add(e)); - } - - discovered = [...matched]; + discovered = discovered.filter(minimatch.filter(config.autodiscoverFilter)); 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');