-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata.js
64 lines (52 loc) · 1.99 KB
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const GitHubAPI = require('./src/api/GitHubAPI');
const CodeAnalyzer = require('./src/parser/CodeAnalyzer');
const GraphBuilder = require('./src/graph/GraphBuilder');
require('dotenv').config();
class Data {
constructor() {
this.gitHubAPI = new GitHubAPI();
this.codeAnalyzer = new CodeAnalyzer();
this.graphBuilder = new GraphBuilder();
}
async fetchFilesRecursively(url, files = []) {
const items = await this.gitHubAPI.getFiles(url);
for (const item of items) {
if (item.type === 'file' && item.path.endsWith('.py')) {
files.push(item);
} else if (item.type === 'dir') {
await this.fetchFilesRecursively(item.url, files);
}
}
return files;
}
async main(repoLink) {
let graph;
try {
const repoContentsUrl = `https://api.github.com/repos/${repoLink}/contents`;
let files = await this.fetchFilesRecursively(repoContentsUrl);
const analyses = [];
for (const file of files) {
const content = await this.gitHubAPI.fetchFileContent(file.download_url);
const analysis = this.codeAnalyzer.analyzeCode(content, file.path);
analyses.push(analysis);
}
graph = this.graphBuilder.constructGraph(analyses);
graph.content = {};
for (const node of graph.nodes) {
const content = await this.gitHubAPI.fetchFileContent(`https://raw.githubusercontent.com/${repoLink}/main/${node.id}`);
graph.content[node.id] = content;
}
} catch (error) {
console.error('Error:', error.message);
}
console.log(graph)
return graph;
}
}
// const data = new Data();
// data.main('MLH-Hackionaire/Project')
// .then(graph => {
// console.log("Graph Nodes:", graph.nodes);
// console.log("Graph Links:", graph.links);
// });
module.exports = Data;