Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
nnobelis committed May 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7b86165 commit 1ece1bb
Showing 4 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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].
@@ -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.
10 changes: 10 additions & 0 deletions plugins/scanners/fossid/src/main/kotlin/FossIdScanResults.kt
Original file line number Diff line number Diff line change
@@ -202,6 +202,16 @@ internal suspend fun mapSnippetFindings(
}
}

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.
Original file line number Diff line number Diff line change
@@ -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" {
@@ -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" {
@@ -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."
}
}
}
})

0 comments on commit 1ece1bb

Please sign in to comment.