generated from dxworks/dxworks-template-node-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AvrAlexandra
committed
Oct 16, 2024
1 parent
e5404a1
commit b3adb0b
Showing
2 changed files
with
46 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
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 { | ||
|
||
} | ||
|