diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index f4cd3e3be02a353829fff5384180b51946b36de7..abf9d94fd658cc161c91cf5d4d1ac6ca7e07b7dd 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -262,17 +262,36 @@ async function fetchRepositories(): Promise<GhRestRepo[]> { // Get all repositories that the user has access to export async function getRepos(config?: AutodiscoverConfig): Promise<string[]> { logger.debug('Autodiscovering GitHub repositories'); - return (await fetchRepositories()) - .filter(is.nonEmptyObject) - .filter((repo) => !repo.archived) - .filter((repo) => { - if (config?.topics) { - const autodiscoverTopics = config.topics; - return repo.topics.some((topic) => autodiscoverTopics.includes(topic)); - } - return true; - }) - .map((repo) => repo.full_name); + const nonEmptyRepositories = (await fetchRepositories()).filter( + is.nonEmptyObject + ); + const nonArchivedRepositories = nonEmptyRepositories.filter( + (repo) => !repo.archived + ); + if (nonArchivedRepositories.length < nonEmptyRepositories.length) { + logger.debug( + `Filtered out ${ + nonEmptyRepositories.length - nonArchivedRepositories.length + } archived repositories` + ); + } + if (!config?.topics) { + return nonArchivedRepositories.map((repo) => repo.full_name); + } + + logger.debug({ topics: config.topics }, 'Filtering by topics'); + const topicRepositories = nonArchivedRepositories.filter((repo) => + repo.topics?.some((topic) => config?.topics?.includes(topic)) + ); + + if (topicRepositories.length < nonArchivedRepositories.length) { + logger.debug( + `Filtered out ${ + nonArchivedRepositories.length - topicRepositories.length + } repositories not matching topic filters` + ); + } + return topicRepositories.map((repo) => repo.full_name); } async function getBranchProtection( diff --git a/lib/workers/global/autodiscover.ts b/lib/workers/global/autodiscover.ts index 2af10cf07fc277eea9939383659aede8a4c7521e..df8b672bf79dfa9e4352a75e3ada3311e505e99e 100644 --- a/lib/workers/global/autodiscover.ts +++ b/lib/workers/global/autodiscover.ts @@ -13,6 +13,7 @@ function repoName(value: string | { repository: string }): string { export async function autodiscoverRepositories( config: AllConfig ): Promise<AllConfig> { + const { autodiscoverFilter } = config; if (config.platform === 'local') { if (config.repositories?.length) { logger.debug( @@ -42,18 +43,17 @@ export async function autodiscoverRepositories( }); if (!discovered?.length) { // Soft fail (no error thrown) if no accessible repositories - logger.debug( - 'The account associated with your token does not have access to any repos' - ); + logger.debug('No repositories were autodiscovered'); return config; } - if (config.autodiscoverFilter) { + logger.debug(`Autodiscovered ${discovered.length} repositories`); + + if (autodiscoverFilter) { + logger.debug({ autodiscoverFilter }, 'Applying autodiscoverFilter'); discovered = applyFilters( discovered, - is.string(config.autodiscoverFilter) - ? [config.autodiscoverFilter] - : config.autodiscoverFilter + is.string(autodiscoverFilter) ? [autodiscoverFilter] : autodiscoverFilter ); if (!discovered.length) { @@ -61,12 +61,12 @@ export async function autodiscoverRepositories( logger.debug('None of the discovered repositories matched the filter'); return config; } + logger.debug( + `Autodiscovered ${discovered.length} repositories after filter` + ); } - logger.info( - { length: discovered.length, repositories: discovered }, - `Autodiscovered repositories` - ); + logger.info({ repositories: discovered }, `Autodiscovered repositories`); // istanbul ignore if if (config.repositories?.length) {