refactor: Improve file extension handling in CodeRepositoryUtil

The CodeRepositoryUtil class in CodeRepository.ts has been refactored to improve the handling of file extensions. The changes include:
- Simplifying the logic for skipping files with unsupported extensions
- Adding support for accepted file extensions in the getFilesInDirectory method

These improvements enhance the functionality and maintainability of the code.
This commit is contained in:
Simon Larsen 2024-06-12 22:07:01 +01:00
parent d153ad9bf7
commit 21973401fb
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA

View File

@ -57,23 +57,7 @@ export default class CodeRepositoryUtil {
continue;
}
if (
data.acceptedFileExtensions &&
data.acceptedFileExtensions.length > 0
) {
let shouldSkip: boolean = true;
for (const fileExtension of data.acceptedFileExtensions) {
if (fileName.endsWith(fileExtension)) {
shouldSkip = false;
break;
}
}
if (shouldSkip) {
continue;
}
}
const filePath: string = LocalFile.sanitizeFilePath(
`${directoryPath}/${fileName}`
@ -92,6 +76,24 @@ export default class CodeRepositoryUtil {
LocalFile.sanitizeFilePath(`${directoryPath}/${fileName}`)
);
continue;
}else{
if (
data.acceptedFileExtensions &&
data.acceptedFileExtensions.length > 0
) {
let shouldSkip: boolean = true;
for (const fileExtension of data.acceptedFileExtensions) {
if (fileName.endsWith(fileExtension)) {
shouldSkip = false;
break;
}
}
if (shouldSkip) {
continue;
}
}
}
const gitCommitHash: string = await this.getGitCommitHashForFile({
@ -127,6 +129,7 @@ export default class CodeRepositoryUtil {
await this.getFilesInDirectory({
directoryPath: data.directoryPath,
repoPath: data.repoPath,
acceptedFileExtensions: data.acceptedFileExtensions,
});
files = {