mirror of
https://github.com/renovatebot/renovate.git
synced 2025-05-12 23:51:55 +00:00

Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com> Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de> Co-authored-by: Rhys Arkins <rhys@arkins.net>
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import type { RenovateConfig } from '../../../config/types';
|
|
import { logger } from '../../../logger';
|
|
import { minimatch } from '../../../util/minimatch';
|
|
import { matchRegexOrGlob } from '../../../util/string-match';
|
|
|
|
export function getIncludedFiles(
|
|
fileList: string[],
|
|
includePaths: string[],
|
|
): string[] {
|
|
if (!includePaths?.length) {
|
|
return [...fileList];
|
|
}
|
|
return fileList.filter((file) =>
|
|
includePaths.some(
|
|
(includePath) =>
|
|
file === includePath ||
|
|
minimatch(includePath, { dot: true }).match(file),
|
|
),
|
|
);
|
|
}
|
|
|
|
export function filterIgnoredFiles(
|
|
fileList: string[],
|
|
ignorePaths: string[],
|
|
): string[] {
|
|
if (!ignorePaths?.length) {
|
|
return [...fileList];
|
|
}
|
|
return fileList.filter(
|
|
(file) =>
|
|
!ignorePaths.some(
|
|
(ignorePath) =>
|
|
file.includes(ignorePath) ||
|
|
minimatch(ignorePath, { dot: true }).match(file),
|
|
),
|
|
);
|
|
}
|
|
|
|
export function getFilteredFileList(
|
|
config: RenovateConfig,
|
|
fileList: string[],
|
|
): string[] {
|
|
const { includePaths, ignorePaths } = config;
|
|
// TODO #22198
|
|
|
|
let filteredList = getIncludedFiles(fileList, includePaths!);
|
|
filteredList = filterIgnoredFiles(filteredList, ignorePaths!);
|
|
return filteredList;
|
|
}
|
|
|
|
export function getMatchingFiles(
|
|
config: RenovateConfig,
|
|
allFiles: string[],
|
|
): string[] {
|
|
const fileList = getFilteredFileList(config, allFiles);
|
|
const { managerFilePatterns, manager } = config;
|
|
let matchedFiles: string[] = [];
|
|
// TODO: types (#22198)
|
|
for (const pattern of managerFilePatterns!) {
|
|
logger.debug(`Using file pattern: ${pattern} for manager ${manager!}`);
|
|
matchedFiles = matchedFiles.concat(
|
|
fileList.filter((file) => matchRegexOrGlob(file, pattern)),
|
|
);
|
|
}
|
|
// filter out duplicates
|
|
return [...new Set(matchedFiles)].sort();
|
|
}
|