Skip to content

Commit

Permalink
Fetched git commits
Browse files Browse the repository at this point in the history
  • Loading branch information
AvrAlexandra committed Oct 16, 2024
1 parent e5404a1 commit b3adb0b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
12 changes: 6 additions & 6 deletions __tests__/history.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {analyseHistory} from '../src/commands/history/history'
import { analyseHistory } from '../src/commands/history/history';

describe('test history analysis for default plugins', () => {

it('test history analysis for javascript and ruby', async () => {
await analyseHistory(['...'], {
await analyseHistory(['/Users/avram/licenta/Depinder'], {
results: 'results-history',
refresh: false,
plugins: ['npm'],
})
console.log('done')
})
})
});
console.log('done');
});
});
77 changes: 40 additions & 37 deletions src/commands/history/history.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
import {Command} from 'commander'
import {AnalyseOptions} from '../analyse'
import {getPluginsFromNames} from '../../plugins'
import {DependencyFileContext, DepinderProject} from '../../extension-points/extract'
import { Command } from 'commander'
import git from 'isomorphic-git'

Check failure on line 2 in src/commands/history/history.ts

View workflow job for this annotation

GitHub Actions / Build And Test

Cannot find module 'isomorphic-git' or its corresponding type declarations.
import fs from 'fs'
import { AnalyseOptions } from '../analyse'
import { getPluginsFromNames } from '../../plugins'
import { DepinderProject } from "../../extension-points/extract";
import { Plugin } from "../../extension-points/plugin";

export const historyCommand = new Command()
.name('history')
.argument('[folders...]', 'A list of git repositories to analyse')
// .argument('[depext-files...]', 'A list of files to parse for dependency information')
.option('--results, -r', 'The results folder', 'results')
.option('--refresh', 'Refresh the cache', false)
.option('--plugins, -p [plugins...]', 'A list of plugins')
.action(analyseHistory)

.action(analyseHistory);

export async function analyseHistory(folders: string[], options: AnalyseOptions, useCache = true): Promise<void> {
const selectedPlugins = getPluginsFromNames(options.plugins)

// folders.map(repo => {
// console.log(`Analysing ${repo} with isomorphic Git`)
// const commits: any[] = []
// commits.forEach(commit => {
// const changes: any[] = []
// const files = changes
// .filter(it => plugin.extractor.filter ? plugin.extractor.filter(it) : true)
// .filter(it => plugin.extractor.files
// .some(pattern => minimatch(it, pattern, {matchBase: true}))
// )
// })
// })

const projects: DepinderProject[] =
await Promise.all(selectedPlugins.map(async (plugin: any) => {
console.log(`Running plugin ${plugin.name}`)
const context: DependencyFileContext = {} as DependencyFileContext
return await plugin.parser?.parseDependencyTree(context)
}))
const selectedPlugins = getPluginsFromNames(options.plugins);
if (folders.length === 0) {
console.log('No folders provided to analyze.');
return;
}
const projectMap: Map<string, { commit: string, projects: DepinderProject[] }[]> = new Map();

for (const folder of folders) {
const commits = await getCommits(folder);
if (commits.length === 0) {
console.log(`No commits found for ${folder}`);
continue;
}
for (const commit of commits) {
await processCommitForPlugins(commit, folder, selectedPlugins, projectMap);
}
}
}

class Repo {

// Function to process each commit and update the map by plugin
async function processCommitForPlugins(commit: any, folder: string, selectedPlugins: Plugin[], projectMap: Map<string, { commit: string, projects: DepinderProject[] }[]>) {
console.log('Commit:', JSON.stringify(commit, null, 2));
}

class Commit {

// Function to fetch commits from a Git repository
async function getCommits(folder: string): Promise<any[]> {
console.log("folder: " + folder);
try {
return await git.log({
fs,
dir: folder,
});
} catch (error) {
console.error(`Failed to get commits for ${folder}:`, error);
return [];
}
}

class Change {

}

0 comments on commit b3adb0b

Please sign in to comment.