refactor(sbom): reuse Go module records for graph coverage (#17451)

This commit is contained in:
Vincent Koc
2026-12-06 16:21:38 +08:00
committed by GitHub
parent 0f9389858a
commit d01a315e31
+11 -16
View File
@@ -546,12 +546,12 @@ const projectGoCycloneDx = (
"Go parent subject must identify the report's exact artifact.",
);
if (!subject.ok) return subject;
const info = report.build_info;
const modules = [
...(info?.module.main === null || info === null ? [] : [info.module.main]),
...(info?.module.dependencies ?? []),
];
const published = modules.map(publishedGoModule);
const recorded = report.build_info?.module;
const main = recorded?.main;
const dependencyModules = recorded?.dependencies ?? [];
const published = (
main == null ? dependencyModules : [main, ...dependencyModules]
).map(publishedGoModule);
const minimumBytes = documentBytesAtLeast(0, published, goComponentBytes);
if (minimumBytes > CYCLONEDX_DOCUMENT_BYTE_LIMIT)
return documentAllowanceExceeded(minimumBytes, "lower_bound");
@@ -572,27 +572,22 @@ const projectGoCycloneDx = (
goComponentProperties(item),
);
});
const mainRef =
info?.module.main === null || info === null ? undefined : refs[0];
const dependencyRefs = mainRef === undefined ? [] : refs.slice(1);
const mainRef = main == null ? undefined : refs[0];
// Empty dependsOn claims absence. That claim is valid only when every module line parsed.
const dependencies =
mainRef === undefined ||
(info?.module.complete === false && dependencyRefs.length === 0)
(recorded?.complete === false && dependencyModules.length === 0)
? undefined
: [
{
ref: mainRef,
dependsOn: uniqueRefs(dependencyRefs),
dependsOn: uniqueRefs(refs.slice(1)),
},
];
const moduleRecordDecoded =
info !== null &&
(info.module.main !== null || info.module.dependencies.length > 0);
const sourceCoverage: SourceCoverage =
info === null || (info.module.complete && !moduleRecordDecoded)
recorded === undefined || (recorded.complete && published.length === 0)
? { aggregate: "unknown", records: "absent" }
: info.module.complete
: recorded.complete
? { aggregate: "unknown", records: "present" }
: { aggregate: "incomplete", records: "partial" };
const reportedUnknowns = goBinaryUnknowns(report);