Skip to content

Commit

Permalink
fix: Revert "feat: Allow multiple autodiscover filter (#9453)" (#9641)
Browse files Browse the repository at this point in the history
This reverts commit 45739cd.
  • Loading branch information
rarkins committed Apr 20, 2021
1 parent 9a30604 commit f654f2d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/usage/self-hosted-configuration.md
Expand Up @@ -81,7 +81,7 @@ e.g.

```json
{
"autodiscoverFilter": ["project/*"]
"autodiscoverFilter": "project/*"
}
```

Expand Down
4 changes: 1 addition & 3 deletions lib/config/definitions.ts
Expand Up @@ -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,
},
{
Expand Down
2 changes: 1 addition & 1 deletion lib/config/types.ts
Expand Up @@ -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;
Expand Down
24 changes: 3 additions & 21 deletions lib/workers/global/autodiscover.spec.ts
Expand Up @@ -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';
Expand Down
9 changes: 1 addition & 8 deletions lib/workers/global/autodiscover.ts
Expand Up @@ -30,14 +30,7 @@ export async function autodiscoverRepositories(
return config;
}
if (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];
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');
Expand Down

0 comments on commit f654f2d

Please sign in to comment.