Skip to content

Commit

Permalink
feat(fossid-webapp): Add an issue when the snippet limit has been rea…
Browse files Browse the repository at this point in the history
…ched

Also display this issue in the FossID snippet report.
In case the limit has been exactly reached when listing the snippets of a
pending file, adding an issue is the only possibility for the user to know
that there may be other snippets beyond the limit, requiring some snippet
choices and a second scanner run.
A strict comparison could be used instead but deciding to create the issue
would then require peeking the next snippet results, which would defeat the
optimization brought by the introduction of the limit.

Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
  • Loading branch information
nnobelis authored and oheger-bosch committed May 15, 2024
1 parent 9223e90 commit bee55e3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ List of all the provenances with their files and snippets.

[#if scanResult.scanner.name != "FossId"] [#continue] [/#if]

[#assign snippetsLimitIssue = helper.getSnippetsLimitIssue()]

[#if snippetsLimitIssue??]
[WARNING]
====
${snippetsLimitIssue}
====
[/#if]

[#if scanResult.provenance.vcsInfo??]
[#assign url = scanResult.provenance.vcsInfo.url]
[#else]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class FreemarkerTemplateProcessor(
/**
* A collection of helper functions for the Freemarker templates.
*/
@Suppress("TooManyFunctions")
class TemplateHelper(private val input: ReporterInput) {
/**
* Return only those [packages] that are a dependency of at least one of the provided [projects][projectIds].
Expand Down Expand Up @@ -277,6 +278,18 @@ class FreemarkerTemplateProcessor(
fun hasUnresolvedIssues(threshold: Severity = input.ortConfig.severeIssueThreshold) =
input.ortResult.getOpenIssues(minSeverity = threshold).isNotEmpty()

/**
* If there are any issue caused by reaching the snippets limit, return the text of the issue. Otherwise reuturn
* 'null'.
*/
@Suppress("UNUSED") // This function is used in the templates.
fun getSnippetsLimitIssue() =
input.ortResult.scanner?.scanResults?.flatMap { result ->
result.summary.issues
}?.firstOrNull {
it.message.contains("snippets limit")
}?.message

/**
* Return `true` if there are any unresolved and non-excluded [RuleViolation]s whose severity is equal to or
* greater than the [threshold], or `false` otherwise.
Expand Down
10 changes: 10 additions & 0 deletions plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ internal suspend fun mapSnippetFindings(
results += mappedSnippets
}

if (runningSnippetCount >= snippetsLimit) {
issues += Issue(
source = "FossId",
message = "The snippets limit of $snippetsLimit has been reached. To see the possible remaining " +
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
"rerun the scan.",
severity = Severity.HINT
)
}

return results.also {
remainingSnippetChoices.forEach { snippetChoice ->
// The issue is created only if the chosen snippet does not correspond to a file marked by a previous run.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,12 @@ class FossIdSnippetChoiceTest : WordSpec({
}

summary.snippetFindings.flatMap { it.snippets } shouldHaveSize 2
// todo + test issue

summary.issues.forAtLeastOne {
it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " +
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
"rerun the scan."
}
}

"list all the snippets of a file even if if goes over the snippets limit" {
Expand Down Expand Up @@ -796,6 +801,12 @@ class FossIdSnippetChoiceTest : WordSpec({

summary.snippetFindings shouldHaveSize 2
summary.snippetFindings.flatMap { it.snippets } shouldHaveSize 3

summary.issues.forAtLeastOne {
it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " +
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
"rerun the scan."
}
}

"not count the chosen snippet when enforcing the snippet limits" {
Expand Down Expand Up @@ -840,6 +851,12 @@ class FossIdSnippetChoiceTest : WordSpec({
summary.snippetFindings.drop(1).forEach {
it.sourceLocation.path shouldBe FILE_2
}

summary.issues.forAtLeastOne {
it.message shouldBe "The snippets limit of 2 has been reached. To see the possible remaining " +
"snippets, please perform a snippet choice for the snippets presents in the snippet report an " +
"rerun the scan."
}
}
}
})
Expand Down

0 comments on commit bee55e3

Please sign in to comment.