Skip to content

Commit 6cf9067

Browse files
committed
Improve package URL validation and skip components with invalid URLs
1 parent 5cef7e7 commit 6cf9067

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

componentDetection.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,17 @@ export default class ComponentDetection {
8282
name: component.component.name || 'unnamed',
8383
type: component.component.type || 'unknown'
8484
}, null, 2)}`);
85+
// Skip components without packageUrl
86+
return;
8587
}
8688

8789
const packageUrl = ComponentDetection.makePackageUrl(component.component.packageUrl);
90+
91+
// Skip if the packageUrl is empty (indicates an invalid or missing packageUrl)
92+
if (!packageUrl) {
93+
core.debug(`Skipping component with invalid packageUrl: ${component.component.id}`);
94+
return;
95+
}
8896

8997
if (!packageCache.hasPackage(packageUrl)) {
9098
const pkg = new ComponentDetectionPackage(packageUrl, component.component.id,
@@ -98,9 +106,27 @@ export default class ComponentDetection {
98106
core.debug("Sorting out transitive dependencies");
99107
packages.forEach(async (pkg: ComponentDetectionPackage) => {
100108
pkg.topLevelReferrers.forEach(async (referrer: any) => {
101-
const referrerPackage = packageCache.lookupPackage(ComponentDetection.makePackageUrl(referrer.packageUrl));
102-
if (referrerPackage) {
103-
referrerPackage.dependsOn(pkg);
109+
// Skip if referrer doesn't have a valid packageUrl
110+
if (!referrer.packageUrl) {
111+
core.debug(`Skipping referrer without packageUrl for component: ${pkg.id}`);
112+
return;
113+
}
114+
115+
const referrerUrl = ComponentDetection.makePackageUrl(referrer.packageUrl);
116+
117+
// Skip if the generated packageUrl is empty
118+
if (!referrerUrl) {
119+
core.debug(`Skipping referrer with invalid packageUrl for component: ${pkg.id}`);
120+
return;
121+
}
122+
123+
try {
124+
const referrerPackage = packageCache.lookupPackage(referrerUrl);
125+
if (referrerPackage) {
126+
referrerPackage.dependsOn(pkg);
127+
}
128+
} catch (error) {
129+
core.debug(`Error looking up referrer package: ${error}`);
104130
}
105131
});
106132
});

dist/index.js

Lines changed: 26 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)