mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat(autodiscover): add autodiscoverFilter option (#3394)
adds a `autodiscoverFilter` option which can be a [minimatch](https://www.npmjs.com/package/minimatch) glob-style pattern for filtering `autodiscover`ed repositories. Ex: `project/*` Closes #3341
This commit is contained in:
parent
d8614aa785
commit
4b6de0f485
4 changed files with 47 additions and 2 deletions
|
@ -287,6 +287,13 @@ const options = [
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'autodiscoverFilter',
|
||||||
|
description: 'Filter the list of autodiscovered repositories',
|
||||||
|
stage: 'global',
|
||||||
|
type: 'string',
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'repositories',
|
name: 'repositories',
|
||||||
description: 'List of Repositories',
|
description: 'List of Repositories',
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const is = require('@sindresorhus/is');
|
const is = require('@sindresorhus/is');
|
||||||
|
const minimatch = require('minimatch');
|
||||||
const { getPlatformApi } = require('../../platform');
|
const { getPlatformApi } = require('../../platform');
|
||||||
const hostRules = require('../../util/host-rules');
|
const hostRules = require('../../util/host-rules');
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ async function autodiscoverRepositories(config) {
|
||||||
}
|
}
|
||||||
const credentials = hostRules.find(config, {});
|
const credentials = hostRules.find(config, {});
|
||||||
// Autodiscover list of repositories
|
// Autodiscover list of repositories
|
||||||
const discovered = await getPlatformApi(config.platform).getRepos(
|
let discovered = await getPlatformApi(config.platform).getRepos(
|
||||||
credentials.token,
|
credentials.token,
|
||||||
credentials.endpoint
|
credentials.endpoint
|
||||||
);
|
);
|
||||||
|
@ -23,6 +24,14 @@ async function autodiscoverRepositories(config) {
|
||||||
);
|
);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
if (config.autodiscoverFilter) {
|
||||||
|
discovered = discovered.filter(minimatch.filter(config.autodiscoverFilter));
|
||||||
|
if (!discovered.length) {
|
||||||
|
// Soft fail (no error thrown) if no accessible repositories match the filter
|
||||||
|
logger.info('None of the discovered repositories matched the filter');
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
logger.info(`Discovered ${discovered.length} repositories`);
|
logger.info(`Discovered ${discovered.length} repositories`);
|
||||||
// istanbul ignore if
|
// istanbul ignore if
|
||||||
if (config.repositories && config.repositories.length) {
|
if (config.repositories && config.repositories.length) {
|
||||||
|
|
|
@ -34,4 +34,29 @@ describe('lib/workers/global/autodiscover', () => {
|
||||||
const res = await autodiscoverRepositories(config);
|
const res = await autodiscoverRepositories(config);
|
||||||
expect(res.repositories).toHaveLength(2);
|
expect(res.repositories).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
it('filters autodiscovered github repos', async () => {
|
||||||
|
config.autodiscover = true;
|
||||||
|
config.autodiscoverFilter = 'project/re*';
|
||||||
|
config.platform = 'github';
|
||||||
|
hostRules.find = jest.fn(() => ({
|
||||||
|
token: 'abc',
|
||||||
|
}));
|
||||||
|
ghApi.getRepos = jest.fn(() => ['project/repo', 'project/another-repo']);
|
||||||
|
const res = await autodiscoverRepositories(config);
|
||||||
|
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(() => [
|
||||||
|
'another-project/repo',
|
||||||
|
'another-project/another-repo',
|
||||||
|
]);
|
||||||
|
const res = await autodiscoverRepositories(config);
|
||||||
|
expect(res).toEqual(config);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,11 @@ The below configuration options are applicable only if you are running your own
|
||||||
|
|
||||||
## autodiscover
|
## autodiscover
|
||||||
|
|
||||||
Be cautious when using this option - it will run Renovate over _every_ repository that the bot account has access to.
|
Be cautious when using this option - it will run Renovate over _every_ repository that the bot account has access to. To filter this list, use `autodiscoverFilter`.
|
||||||
|
|
||||||
|
## autodiscoverFilter
|
||||||
|
|
||||||
|
A [minimatch](https://www.npmjs.com/package/minimatch) glob-style pattern for filtering `autodiscover`ed repositories. Ex: `project/*`
|
||||||
|
|
||||||
## binarySource
|
## binarySource
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue