Skip to content
Snippets Groups Projects
Unverified Commit 45739cdd authored by Emanuel Bennici's avatar Emanuel Bennici Committed by GitHub
Browse files

feat: Allow multiple autodiscover filter (#9453)

parent 16c080fa
No related branches found
No related tags found
No related merge requests found
...@@ -81,7 +81,7 @@ e.g. ...@@ -81,7 +81,7 @@ e.g.
```json ```json
{ {
"autodiscoverFilter": "project/*" "autodiscoverFilter": ["project/*"]
} }
``` ```
......
...@@ -579,7 +579,9 @@ const options: RenovateOptions[] = [ ...@@ -579,7 +579,9 @@ const options: RenovateOptions[] = [
name: 'autodiscoverFilter', name: 'autodiscoverFilter',
description: 'Filter the list of autodiscovered repositories.', description: 'Filter the list of autodiscovered repositories.',
stage: 'global', stage: 'global',
type: 'string', type: 'array',
subType: 'string',
allowString: true,
default: null, default: null,
}, },
{ {
......
...@@ -68,7 +68,7 @@ export interface RenovateSharedConfig { ...@@ -68,7 +68,7 @@ export interface RenovateSharedConfig {
// The below should contain config options where stage=global // The below should contain config options where stage=global
export interface GlobalOnlyConfig { export interface GlobalOnlyConfig {
autodiscover?: boolean; autodiscover?: boolean;
autodiscoverFilter?: string; autodiscoverFilter?: string[];
baseDir?: string; baseDir?: string;
forceCli?: boolean; forceCli?: boolean;
gitPrivateKey?: string; gitPrivateKey?: string;
......
...@@ -49,18 +49,36 @@ describe(getName(__filename), () => { ...@@ -49,18 +49,36 @@ describe(getName(__filename), () => {
}); });
it('filters autodiscovered github repos', async () => { it('filters autodiscovered github repos', async () => {
config.autodiscover = true; config.autodiscover = true;
config.autodiscoverFilter = 'project/re*'; config.autodiscoverFilter = ['project/re*', 'new/prj*'];
config.platform = PLATFORM_TYPE_GITHUB; config.platform = PLATFORM_TYPE_GITHUB;
hostRules.find = jest.fn(() => ({ hostRules.find = jest.fn(() => ({
token: 'abc', token: 'abc',
})); }));
ghApi.getRepos = jest.fn(() => 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); 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 () => { 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.autodiscover = true;
config.autodiscoverFilter = 'project/re*'; config.autodiscoverFilter = 'project/re*';
config.platform = 'github'; config.platform = 'github';
......
...@@ -30,7 +30,14 @@ export async function autodiscoverRepositories( ...@@ -30,7 +30,14 @@ export async function autodiscoverRepositories(
return config; return config;
} }
if (config.autodiscoverFilter) { 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) { if (!discovered.length) {
// Soft fail (no error thrown) if no accessible repositories match the filter // Soft fail (no error thrown) if no accessible repositories match the filter
logger.debug('None of the discovered repositories matched the filter'); logger.debug('None of the discovered repositories matched the filter');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment