Skip to content

Commit

Permalink
feat(backend): improve namcap analysis data
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Nov 7, 2024
1 parent e3c324c commit 7a47b9c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/src/builder/builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class BuilderService {
.getRawMany();
}

async downloadBuildsPerDay(options: { days: number; offset: number }): Promise<{ day: string; count: string }[]> {
async buildsPerDay(options: { days: number; offset: number }): Promise<{ day: string; count: string }[]> {
return await this.buildRepository
.createQueryBuilder("build")
.select("DATE_TRUNC('day', build.timestamp) AS day")
Expand Down
1 change: 1 addition & 0 deletions backend/src/interfaces/repo-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ export interface NamcapAnalysis {
"libdepends-by-namcap-sight": string[];
"libdepends-detected-not-included": string[];
"libprovides-by-namcap-sight": string[];
"library-no-package-associated": string[];
"link-level-dependence": string[];
}
35 changes: 27 additions & 8 deletions backend/src/repo-manager/repo-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export class RepoManagerService {
"libdepends-by-namcap-sight": [],
"libdepends-detected-not-included": [],
"libprovides-by-namcap-sight": [],
"library-no-package-associated": [],
"link-level-dependence": [],
};
const relevantRules: string[] = Object.keys(finalAnalysis);
Expand Down Expand Up @@ -331,6 +332,11 @@ export class RepoManagerService {
if (key) finalAnalysis[rule].push(key);
break;
}
case "library-no-package-associated": {
const key = result.split(" ")[0];
if (key) finalAnalysis[rule].push(key);
break;
}
}
}

Expand All @@ -342,22 +348,24 @@ export class RepoManagerService {
}
}

async readNamcap() {
/**
* Helper function for quickly filling the database with namcap analysis.
*/
async readNamcap(): Promise<void> {
try {
const initialMemory = process.memoryUsage();
Logger.log(initialMemory, "RepoManager");
fs.readdir("/namcap", "utf8", async (err, files) => {
Logger.log(files.length, "RepoManager");
for (const file of files) {
const fileContent = fs.readFileSync(`/namcap/${file}`, "utf8");
const namcapLines = fileContent.split("\n");
const fileContent: string = fs.readFileSync(`/namcap/${file}`, "utf8");
const namcapLines: string[] = fileContent.split("\n");
const namcapAnalysis: Partial<NamcapAnalysis> = {
"dependency-detected-satisfied": [],
"dependency-implicitly-satisfied": [],
"depends-by-namcap-sight": [],
"libdepends-by-namcap-sight": [],
"libdepends-detected-not-included": [],
"libprovides-by-namcap-sight": [],
"library-no-package-associated": [],
"link-level-dependence": [],
};
const relevantRules: string[] = Object.keys(namcapAnalysis);
Expand Down Expand Up @@ -391,14 +399,14 @@ export class RepoManagerService {
case "depends-by-namcap-sight": {
const depends = result.split(" ")[0];
const depsText = depends.match(/(?<=\()[^)]+(?=\))/);
if (!depsText) break;
if (!depsText) continue;
namcapAnalysis[rule] = depsText[0].split(" ");
break;
}
case "libdepends-by-namcap-sight": {
const libDepends = result.split(" ")[0];
const libDepsText = libDepends.match(/(?<=\()[^)]+(?=\))/);
if (!libDepsText) break;
if (!libDepsText) continue;
namcapAnalysis[rule] = libDepsText[0].split(" ");
break;
}
Expand All @@ -412,13 +420,24 @@ export class RepoManagerService {
const libProvidesText = libProvides.match(/(?<=\()[^)]+(?=\))/);
if (!libProvidesText) break;
namcapAnalysis[rule] = libProvidesText[0].split(" ");
break;
}
case "link-level-dependence": {
const key = result.split(" ")[0];
if (key) namcapAnalysis[rule].push(key);
break;
}
case "library-no-package-associated": {
const key = result.split(" ")[0];
if (key) namcapAnalysis[rule].push(key);
break;
}
}
}

if (!pkg) continue;
pkg.namcapAnalysis = namcapAnalysis;
this.packageRepository.save(pkg);
void this.packageRepository.save(pkg);
}
});
} catch (err) {
Expand Down

0 comments on commit 7a47b9c

Please sign in to comment.