Skip to content

Commit

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

Also display this issue in the FossID snippet report.

Signed-off-by: Nicolas Nobelis <[email protected]>
  • Loading branch information
nnobelis committed May 8, 2024
1 parent 2e506d7 commit af9b0a2
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 @@ -191,6 +191,16 @@ internal 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 af9b0a2

Please sign in to comment.