(config: GerritConnectionConfig)
| 33 | const logger = createLogger('gerrit'); |
| 34 | |
| 35 | export const getGerritReposFromConfig = async (config: GerritConnectionConfig): Promise<GerritProject[]> => { |
| 36 | const url = config.url.endsWith('/') ? config.url : `${config.url}/`; |
| 37 | |
| 38 | let { durationMs, data: projects } = await measure(async () => { |
| 39 | const fetchFn = () => fetchAllProjects(url); |
| 40 | return fetchWithRetry(fetchFn, `projects from ${url}`, logger); |
| 41 | }); |
| 42 | |
| 43 | // include repos by glob if specified in config |
| 44 | if (config.projects) { |
| 45 | projects = projects.filter((project) => { |
| 46 | return micromatch.isMatch(project.name, config.projects!); |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | projects = projects |
| 51 | .filter((project) => { |
| 52 | const isExcluded = shouldExcludeProject({ |
| 53 | project, |
| 54 | exclude: config.exclude, |
| 55 | }); |
| 56 | |
| 57 | return !isExcluded; |
| 58 | }); |
| 59 | |
| 60 | logger.debug(`Fetched ${projects.length} projects in ${durationMs}ms.`); |
| 61 | return projects; |
| 62 | }; |
| 63 | |
| 64 | const fetchAllProjects = async (url: string): Promise<GerritProject[]> => { |
| 65 | const projectsEndpoint = `${url}projects/`; |
no test coverage detected