Clean up old stuff & fix ui errors
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
export const extractFileDiff = (diff: string | undefined, filePath: string) => {
|
||||
if (!diff?.trim() || filePath === '.') return '';
|
||||
const lines = diff.split('\n');
|
||||
const sections: string[][] = [];
|
||||
let current: string[] | null = null;
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('diff --git ')) {
|
||||
if (current) sections.push(current);
|
||||
current = [line];
|
||||
continue;
|
||||
}
|
||||
current?.push(line);
|
||||
}
|
||||
if (current) sections.push(current);
|
||||
const normalizedPath = filePath.replace(/^\.\/+/, '');
|
||||
const section = sections.find((item) => {
|
||||
const header = item[0] ?? '';
|
||||
return (
|
||||
header.includes(` a/${normalizedPath} `) ||
|
||||
header.endsWith(` a/${normalizedPath}`) ||
|
||||
header.includes(` b/${normalizedPath}`) ||
|
||||
header.endsWith(` b/${normalizedPath}`)
|
||||
);
|
||||
});
|
||||
return section?.join('\n') ?? '';
|
||||
};
|
||||
Reference in New Issue
Block a user