Skip to content

Commit

Permalink
Set 'error' in projects for missing files and refactor comparison logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AvrAlexandra committed Dec 1, 2024
1 parent a649ce1 commit e802343
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
21 changes: 19 additions & 2 deletions src/commands/history/history-git-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function processCommitForPlugins(
commit: any,
folder: string,
selectedPlugins: Plugin[],
commitProjectsMap: Map<string, { commit: any, projects: DepinderProject[] }[]>
commitProjectsMap: Map<string, { commit: any, projects: DepinderProject[] | string}[]>
) {
const changes = await getChangedFiles(commit, folder);
await ensureDirectoryExists(depinderTempFolder);
Expand All @@ -46,6 +46,8 @@ export async function processCommitForPlugins(

if (filteredFiles.length > 0) {
const tempFilePaths: string[] = [];
let allFilesExist = true;

for (const file of filteredFiles) {
const tempFilePath = path.join(depinderTempFolder, `${commit.oid}-${path.basename(file)}`);
try {
Expand All @@ -59,10 +61,25 @@ export async function processCommitForPlugins(
await fs.writeFile(tempFilePath, fileContent.blob);
tempFilePaths.push(tempFilePath);
} catch (error) {
console.error(`Failed to create temp file for ${file} at commit ${commit.oid}:`, error);
console.error(`Failed to read file ${file} at commit ${commit.oid}:`, error);
allFilesExist = false;
}
}

if (!allFilesExist) {
console.log(`Skipping plugin ${plugin.name} for commit ${commit.oid} due to missing files.`);
if (!commitProjectsMap.has(plugin.name)) {
commitProjectsMap.set(plugin.name, []);
}
commitProjectsMap.get(plugin.name)!.push({
commit,
projects: "error",
});

await cleanupTempFiles(tempFilePaths);
continue;
}

const projects: DepinderProject[] = await extractProjects(plugin, tempFilePaths);
projects.forEach(project => {
const dependencyIds = Object.values(project.dependencies).map(dep => dep.id).join(', ');
Expand Down
33 changes: 22 additions & 11 deletions src/commands/history/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,31 @@ function sortCommitsInOrder(commits: any[]): any[] {

// Function to compare dependencies across commits
async function compareDependenciesBetweenCommits(
commitProjectsMap: Map<string, { commit: any, projects: DepinderProject[] }[]>,
commitProjectsMap: Map<string, { commit: any; projects: DepinderProject[] | "error" }[]>,
dependencyHistory: DependencyHistory
) {
for (const [pluginName, entries] of commitProjectsMap.entries()) {
const reversedEntries = [...entries].reverse();

for (let i = 1; i < reversedEntries.length; i++) {
const currentEntry = reversedEntries[i - 1];
const nextEntry = reversedEntries[i];
const currentDeps = getDependencyMap(currentEntry.projects[0]);
const nextDeps = getDependencyMap(nextEntry.projects[0]);
const changes = identifyDependencyChanges(currentDeps, nextDeps);
const commitDate = new Date(nextEntry.commit.commit.committer.timestamp * 1000).toISOString();
await processDependencyChanges(dependencyHistory, changes, nextEntry.commit.oid, commitDate);
const reversedEntries = [...entries].reverse(); // Reverse to process in chronological order

let lastValidEntry: { commit: any; projects: DepinderProject[] } | null = null;

for (const entry of reversedEntries) {
if (entry.projects === "error") {
console.log(
`Skipping entry for plugin ${pluginName} at commit ${entry.commit.oid} due to errors.`
);
continue;
}

if (lastValidEntry) {
const currentDeps = getDependencyMap(lastValidEntry.projects[0]);
const nextDeps = getDependencyMap(entry.projects[0]);
const changes = identifyDependencyChanges(currentDeps, nextDeps);
const commitDate = new Date(entry.commit.commit.committer.timestamp * 1000).toISOString();
await processDependencyChanges(dependencyHistory, changes, entry.commit.oid, commitDate);
}

lastValidEntry = entry as { commit: any; projects: DepinderProject[] };
}
}
}
Expand Down

0 comments on commit e802343

Please sign in to comment.