Refactor: Extract another method and test with real data
This commit is contained in:
@@ -68,14 +68,17 @@ export default class ComponentDetection {
|
||||
|
||||
public static async getManifestsFromResults(): Promise<Manifest[] | undefined> {
|
||||
core.info("Getting manifests from results");
|
||||
const results = await fs.readFileSync(this.outputPath, 'utf8');
|
||||
var json: any = JSON.parse(results);
|
||||
return this.processComponentsToManifests(json.componentsFound);
|
||||
}
|
||||
|
||||
public static processComponentsToManifests(componentsFound: any[]): Manifest[] {
|
||||
// Parse the result file and add the packages to the package cache
|
||||
const packageCache = new PackageCache();
|
||||
const packages: Array<ComponentDetectionPackage> = [];
|
||||
|
||||
const results = await fs.readFileSync(this.outputPath, 'utf8');
|
||||
|
||||
var json: any = JSON.parse(results);
|
||||
json.componentsFound.forEach(async (component: any) => {
|
||||
componentsFound.forEach(async (component: any) => {
|
||||
// Skip components without packageUrl
|
||||
if (!component.component.packageUrl) {
|
||||
core.debug(`Skipping component detected without packageUrl: ${JSON.stringify({
|
||||
@@ -113,6 +116,7 @@ export default class ComponentDetection {
|
||||
}
|
||||
|
||||
const referrerUrl = ComponentDetection.makePackageUrl(referrer.packageUrl);
|
||||
referrer.packageUrlString = referrerUrl
|
||||
|
||||
// Skip if the generated packageUrl is empty
|
||||
if (!referrerUrl) {
|
||||
@@ -140,9 +144,9 @@ export default class ComponentDetection {
|
||||
return manifests;
|
||||
}
|
||||
|
||||
public static addPackagesToManifests(packages: Array<ComponentDetectionPackage>, manifests: Array<Manifest>): void {
|
||||
packages.forEach(async (pkg: ComponentDetectionPackage) => {
|
||||
pkg.locationsFoundAt.forEach(async (location: any) => {
|
||||
private static addPackagesToManifests(packages: Array<ComponentDetectionPackage>, manifests: Array<Manifest>): void {
|
||||
packages.forEach((pkg: ComponentDetectionPackage) => {
|
||||
pkg.locationsFoundAt.forEach((location: any) => {
|
||||
if (!manifests.find((manifest: Manifest) => manifest.name == location)) {
|
||||
const manifest = new Manifest(location, location);
|
||||
manifests.push(manifest);
|
||||
@@ -150,9 +154,8 @@ export default class ComponentDetection {
|
||||
|
||||
// Filter out self-references from topLevelReferrers
|
||||
const nonSelfReferrers = pkg.topLevelReferrers.filter((referrer: any) => {
|
||||
if (!referrer.packageUrl) return false;
|
||||
const referrerUrl = ComponentDetection.makePackageUrl(referrer.packageUrl);
|
||||
return referrerUrl !== pkg.packageUrl;
|
||||
if (!referrer.packageUrlString) return false;
|
||||
return referrer.packageUrlString !== pkg.packageUrlString;
|
||||
});
|
||||
|
||||
if (nonSelfReferrers.length == 0) {
|
||||
@@ -249,10 +252,12 @@ export default class ComponentDetection {
|
||||
}
|
||||
|
||||
class ComponentDetectionPackage extends Package {
|
||||
public packageUrlString: string;
|
||||
|
||||
constructor(packageUrl: string, public id: string, public isDevelopmentDependency: boolean, public topLevelReferrers: [],
|
||||
public locationsFoundAt: [], public containerDetailIds: [], public containerLayerIds: []) {
|
||||
super(packageUrl);
|
||||
this.packageUrlString = packageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user