Skip to content
Snippets Groups Projects
Unverified Commit 2349e559 authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

fix(autodiscover): accept simple string (#18531)

parent f4f89e12
No related branches found
No related tags found
No related merge requests found
...@@ -84,7 +84,7 @@ export interface RenovateSharedConfig { ...@@ -84,7 +84,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[] | string;
baseDir?: string; baseDir?: string;
cacheDir?: string; cacheDir?: string;
containerbaseDir?: string; containerbaseDir?: string;
......
...@@ -107,6 +107,20 @@ describe('workers/global/autodiscover', () => { ...@@ -107,6 +107,20 @@ describe('workers/global/autodiscover', () => {
expect(res.repositories).toEqual(['project/another-repo']); expect(res.repositories).toEqual(['project/another-repo']);
}); });
it('filters autodiscovered github repos with minimatch negation', async () => {
config.autodiscover = true;
config.autodiscoverFilter = '!project/re*';
config.platform = PlatformId.Github;
hostRules.find = jest.fn(() => ({
token: 'abc',
}));
ghApi.getRepos = jest.fn(() =>
Promise.resolve(['project/repo', 'project/another-repo'])
);
const res = await autodiscoverRepositories(config);
expect(res.repositories).toEqual(['project/another-repo']);
});
it('fail if regex pattern is not valid', async () => { it('fail if regex pattern is not valid', async () => {
config.autodiscover = true; config.autodiscover = true;
config.autodiscoverFilter = ['/project/re**./']; config.autodiscoverFilter = ['/project/re**./'];
......
...@@ -32,7 +32,12 @@ export async function autodiscoverRepositories( ...@@ -32,7 +32,12 @@ export async function autodiscoverRepositories(
} }
if (config.autodiscoverFilter) { if (config.autodiscoverFilter) {
discovered = applyFilters(discovered, config.autodiscoverFilter); discovered = applyFilters(
discovered,
is.string(config.autodiscoverFilter)
? [config.autodiscoverFilter]
: config.autodiscoverFilter
);
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
...@@ -40,6 +45,7 @@ export async function autodiscoverRepositories( ...@@ -40,6 +45,7 @@ export async function autodiscoverRepositories(
return config; return config;
} }
} }
logger.info( logger.info(
{ length: discovered.length, repositories: discovered }, { length: discovered.length, repositories: discovered },
`Autodiscovered repositories` `Autodiscovered repositories`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment