Skip to content

Commit eb1030a

Browse files
committed
jk4h5og34lj5h
1 parent 834b168 commit eb1030a

2 files changed

Lines changed: 91 additions & 18 deletions

File tree

6f74386fg8346gff8g3f.txt

Whitespace-only changes.

src/scanners/diffScan.js

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,93 @@ async function scanDiff({
1818

1919
const git = simpleGit(repoPath);
2020

21-
const diffSummary = await git.diffSummary([`${commitSha}^..${commitSha}`]);
21+
const diffResult = await git.diff([`${commitSha}^..${commitSha}`, '--name-status', '-M']);
2222

23-
const changedFiles = diffSummary.files
24-
.map(file => file.file)
25-
.filter(file => fileExtensions.some(ext => file.endsWith(ext)))
26-
.filter(file => !excludePatterns.some(pattern => {
23+
24+
const changedFiles = [];
25+
const deletedFiles = [];
26+
27+
diffResult.split('\n').forEach(line => {
28+
if (!line.trim()) return;
29+
30+
const parts = line.split('\t');
31+
const status = parts[0];
32+
33+
// Перевіряємо чи це перейменований файл
34+
if (status.startsWith('R')) {
35+
// Для перейменованих файлів формат: R<score>\t<oldPath>\t<newPath>
36+
const oldPath = parts[1];
37+
const newPath = parts[2];
38+
39+
const oldMatchesExtension = fileExtensions.some(ext => oldPath.endsWith(ext));
40+
const newMatchesExtension = fileExtensions.some(ext => newPath.endsWith(ext));
41+
42+
const oldMatchesExcludePattern = excludePatterns.some(pattern => {
43+
const regexPattern = pattern
44+
.replace(/\*\*/g, '.*')
45+
.replace(/\*/g, '[^/]*')
46+
.replace(/\?/g, '[^/]');
47+
48+
return new RegExp(`^${regexPattern}$`).test(oldPath);
49+
});
50+
51+
const newMatchesExcludePattern = excludePatterns.some(pattern => {
52+
const regexPattern = pattern
53+
.replace(/\*\*/g, '.*')
54+
.replace(/\*/g, '[^/]*')
55+
.replace(/\?/g, '[^/]');
56+
57+
return new RegExp(`^${regexPattern}$`).test(newPath);
58+
});
59+
60+
// Додаємо старий шлях до видалених, якщо він відповідає критеріям
61+
if (oldMatchesExtension && !oldMatchesExcludePattern) {
62+
deletedFiles.push(oldPath);
63+
}
64+
65+
// Додаємо новий шлях до змінених, якщо він відповідає критеріям
66+
if (newMatchesExtension && !newMatchesExcludePattern) {
67+
changedFiles.push(path.resolve(repoPath, newPath));
68+
}
69+
} else {
70+
const filePath = parts[1];
71+
72+
// Перевіряємо розширення та патерни
73+
const matchesExtension = fileExtensions.some(ext => filePath.endsWith(ext));
74+
const matchesExcludePattern = excludePatterns.some(pattern => {
2775
const regexPattern = pattern
2876
.replace(/\*\*/g, '.*')
2977
.replace(/\*/g, '[^/]*')
3078
.replace(/\?/g, '[^/]');
3179

32-
return new RegExp(`^${regexPattern}$`).test(file);
33-
}))
34-
.map(file => path.resolve(repoPath, file));
80+
return new RegExp(`^${regexPattern}$`).test(filePath);
81+
});
82+
83+
if (matchesExtension && !matchesExcludePattern) {
84+
if (status === 'D') {
85+
// Видалений файл
86+
deletedFiles.push(filePath);
87+
} else if (status === 'A' || status === 'M') {
88+
// Доданий (A) або змінений (M) файл
89+
changedFiles.push(path.resolve(repoPath, filePath));
90+
}
91+
}
92+
}
93+
});
94+
95+
96+
// const changedFiles = diffSummary.files
97+
// .map(file => file.file)
98+
// .filter(file => fileExtensions.some(ext => file.endsWith(ext)))
99+
// .filter(file => !excludePatterns.some(pattern => {
100+
// const regexPattern = pattern
101+
// .replace(/\*\*/g, '.*')
102+
// .replace(/\*/g, '[^/]*')
103+
// .replace(/\?/g, '[^/]');
104+
//
105+
// return new RegExp(`^${regexPattern}$`).test(file);
106+
// }))
107+
// .map(file => path.resolve(repoPath, file));
35108

36109
console.log(`Found ${changedFiles.length} changed files in commit ${commitSha}`);
37110

@@ -64,16 +137,16 @@ async function scanDiff({
64137
// .map(file => path.resolve(repoPath, file));
65138

66139
// Видалені файли
67-
const deletedFiles = status.deleted
68-
.filter(file => fileExtensions.some(ext => file.endsWith(ext)))
69-
.filter(file => !excludePatterns.some(pattern => {
70-
const regexPattern = pattern
71-
.replace(/\*\*/g, '.*')
72-
.replace(/\*/g, '[^/]*')
73-
.replace(/\?/g, '[^/]');
74-
75-
return new RegExp(`^${regexPattern}$`).test(file);
76-
}));
140+
// const deletedFiles = status.deleted
141+
// .filter(file => fileExtensions.some(ext => file.endsWith(ext)))
142+
// .filter(file => !excludePatterns.some(pattern => {
143+
// const regexPattern = pattern
144+
// .replace(/\*\*/g, '.*')
145+
// .replace(/\*/g, '[^/]*')
146+
// .replace(/\?/g, '[^/]');
147+
//
148+
// return new RegExp(`^${regexPattern}$`).test(file);
149+
// }));
77150

78151
console.log(`Found ${changedFiles.length} changed files`);
79152
console.log(`Found ${deletedFiles.length} deleted files`);

0 commit comments

Comments
 (0)