renovate/lib/workers/repository/extract/file-match.ts
Michael Kriese 8270d5512d
refactor: fix lint issues (#16779)
* refactor: fix lint issues

* Update lib/renovate.ts

* chore: revert toplevel await for ts
2022-07-26 08:32:12 +00:00

67 lines
1.7 KiB
TypeScript

import minimatch from 'minimatch';
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import { regEx } from '../../../util/regex';
export function getIncludedFiles(
fileList: string[],
includePaths: string[]
): string[] {
if (!includePaths?.length) {
return [...fileList];
}
return fileList.filter((file) =>
includePaths.some(
(includePath) =>
file === includePath || minimatch(file, includePath, { dot: true })
)
);
}
export function filterIgnoredFiles(
fileList: string[],
ignorePaths: string[]
): string[] {
if (!ignorePaths?.length) {
return [...fileList];
}
return fileList.filter(
(file) =>
!ignorePaths.some(
(ignorePath) =>
file.includes(ignorePath) ||
minimatch(file, ignorePath, { dot: true })
)
);
}
export function getFilteredFileList(
config: RenovateConfig,
fileList: string[]
): string[] {
const { includePaths, ignorePaths } = config;
// TODO #7154
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 { fileMatch, manager } = config;
let matchedFiles: string[] = [];
// TODO: types (#7154)
for (const match of fileMatch!) {
logger.debug(`Using file match: ${match} for manager ${manager!}`);
const re = regEx(match);
matchedFiles = matchedFiles.concat(
fileList.filter((file) => re.test(file))
);
}
// filter out duplicates
return [...new Set(matchedFiles)].sort();
}