Skip to content

Commit

Permalink
Added function to compare dependencies across commits
Browse files Browse the repository at this point in the history
  • Loading branch information
AvrAlexandra committed Nov 10, 2024
1 parent c05e26e commit 5a22ff3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/commands/history/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ async function compareDependenciesBetweenCommits(

console.log("current: ", currentEntry.commit.oid);
console.log("next: ", nextEntry.commit.oid);

const changes = identifyDependencyChanges(currentDeps, nextDeps);

if (changes.added.length > 0) {
console.log(`Commit ${nextEntry.commit.oid} - Dependencies added:`, changes.added);
}
if (changes.removed.length > 0) {
console.log(`Commit ${nextEntry.commit.oid} - Dependencies removed:`, changes.removed);
}
if (changes.modified.length > 0) {
console.log(`Commit ${nextEntry.commit.oid} - Dependencies modified:`, changes.modified);
}
}
}
}
Expand All @@ -70,6 +82,31 @@ function getDependencyMap(project: DepinderProject | undefined): Record<string,
}, {} as Record<string, string>);
}

// Function to identify added, removed, and modified dependencies between two maps
function identifyDependencyChanges(
currentDeps: Record<string, string>,
nextDeps: Record<string, string>
) {
const added: string[] = [];
const removed: string[] = [];
const modified: { dependency: string, from: string, to: string }[] = [];

for (const dep in currentDeps) {
if (!nextDeps[dep]) {
removed.push(`${dep}@${currentDeps[dep]}`);
} else if (currentDeps[dep] !== nextDeps[dep]) {
modified.push({ dependency: dep, from: currentDeps[dep], to: nextDeps[dep] });
}
}

for (const dep in nextDeps) {
if (!currentDeps[dep]) {
added.push(`${dep}@${nextDeps[dep]}`);
}
}

return { added, removed, modified };
}

// Function to fetch commits from a Git repository
async function getCommits(folder: string): Promise<any[]> {
Expand Down

0 comments on commit 5a22ff3

Please sign in to comment.