Skip to main content

How to Fix Text Provider

The reporter.how-to-fix-text-provider.kts file enables the injection of how-to-fix texts in Markdown format for ORT issues into the reports.

You can use the example how-to-fix-text-provider as the base script file to create your custom how-to-fix messages in the generated reports.

Command Line​

To use a *.how-to-fix-text-provider.kts file, put it to $ORT_CONFIG_DIR/reporter.how-to-fix-text-provider.kts or pass it via the --how-to-fix-text-provider-script option to the reporter:

cli/build/install/ort/bin/ort report
-i [evaluator-output-dir]/evaluation-result.yml
-o [reporter-output-dir]
--report-formats StaticHtml,WebApp
--how-to-fix-text-provider-script example.how-to-fix-text-provider.kts

Example​

example.how-to-fix-text-provider.kts
object : HowToFixTextProvider {
fun Issue.matchesMessage(pattern: String): Boolean = pattern.toRegex().matches(message)

fun buildFossIdScanUrl(serverUrl: String, scanId: String): String =
"${if (serverUrl.endsWith('/')) serverUrl else "$serverUrl/"}?form=main_interface&action=scanview&sid=$scanId"

fun findScanResultAdditionalData(issue: Issue): Map<String, String>? =
ortResult.getScanResults().values
.flatten()
.firstOrNull { issue in it.summary.issues }
?.additionalData

override fun getHowToFixText(issue: Issue): String? {
// How-to-fix instruction Markdown for scan timeout errors.
if (issue.matchesMessage("ERROR: Timeout after .* seconds while scanning file.*")) {
return """
| To fix this issue please proceed with the following steps:
|
|1. Manually verify that the file does not contain any license information.
|2. File an error resolution in the resolutions file of your configuration directory with a comment
| stating that the file does not contain any license information.
| ```
|
""".trimIndent()
}

if (issue.source == "FossId" && issue.matchesMessage(".*pending identification in FossID.*")) {
val additionalData = findScanResultAdditionalData(issue).orEmpty()
val scanId = additionalData["scanid"]
val serverUrl = additionalData["serverurl"]

if (!scanId.isNullOrBlank() && !serverUrl.isNullOrBlank()) {
val scanUrl = buildFossIdScanUrl(serverUrl, scanId)

return """
| This scan still has file(s) pending identification in FossID.
| Please review and resolve them at: $scanUrl
|
""".trimIndent()
}
}

return null
}
}