Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(vulnerable-code): Add more details to an issue message #8210

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package org.ossreviewtoolkit.plugins.advisors.vulnerablecode
import java.net.URI
import java.time.Instant

import org.apache.logging.log4j.kotlin.logger

import org.ossreviewtoolkit.advisor.AdviceProvider
import org.ossreviewtoolkit.advisor.AdviceProviderFactory
import org.ossreviewtoolkit.clients.vulnerablecode.VulnerableCodeService
Expand Down Expand Up @@ -90,11 +92,12 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
val startTime = Instant.now()

val purls = packages.mapNotNull { pkg -> pkg.purl.takeUnless { it.isEmpty() } }
val chunks = purls.chunked(BULK_REQUEST_SIZE)

val allVulnerabilities = mutableMapOf<String, List<VulnerableCodeService.Vulnerability>>()
val issues = mutableListOf<Issue>()

purls.chunked(BULK_REQUEST_SIZE).forEach { chunk ->
chunks.forEachIndexed { index, chunk ->
runCatching {
val chunkVulnerabilities = service.getPackageVulnerabilities(PackagesWrapper(chunk)).filter {
it.affectedByVulnerabilities.isNotEmpty()
Expand All @@ -107,6 +110,12 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
allVulnerabilities += chunk.associateWith { emptyList() }

issues += Issue(source = providerName, message = it.collectMessages())

logger.error {
"The request of chunk ${index + 1} of ${chunks.size} failed for the following ${chunk.size} " +
"PURL(s):"
}
chunk.forEach(logger::error)
}
}

Expand Down
Loading