Skip to content

Commit

Permalink
Set invocation result in SARIF.
Browse files Browse the repository at this point in the history
  • Loading branch information
hybloid committed Oct 17, 2023
1 parent 0971ba4 commit ed2e0f3
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions baseline-cli/src/main/kotlin/BaselineCli.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.google.gson.JsonSyntaxException
import com.jetbrains.qodana.sarif.SarifUtil
import com.jetbrains.qodana.sarif.baseline.BaselineCalculation
import com.jetbrains.qodana.sarif.model.Invocation
import com.jetbrains.qodana.sarif.model.Run
import com.jetbrains.qodana.sarif.model.SarifReport
import java.net.URI
Expand Down Expand Up @@ -36,7 +37,7 @@ object BaselineCli {
errPrinter
)
} else {
compareThreshold(sarifReport, failThreshold, printer, cliPrinter, errPrinter)
compareThreshold(sarifReport, Paths.get(sarifPath), failThreshold, printer, cliPrinter, errPrinter)
}
}

Expand All @@ -45,29 +46,38 @@ object BaselineCli {
failThreshold: Int?,
cliPrinter: (String) -> Unit,
errPrinter: (String) -> Unit
): Int {
): Invocation {
if (size > 0) {
errPrinter("Found $size new problems according to the checks applied")
} else {
cliPrinter("It seems all right \uD83D\uDC4C No new problems found according to the checks applied")
}
if (failThreshold != null && size > failThreshold) {
errPrinter("New problems count $size is greater than the threshold $failThreshold")
return THRESHOLD_EXIT
return Invocation().apply {
exitCode = THRESHOLD_EXIT
exitCodeDescription = "Qodana reached failThreshold"
}
}
return Invocation().apply {
exitCode = 0
}
return 0
}

private fun compareThreshold(
sarifReport: SarifReport,
sarifPath: Path,
failThreshold: Int?,
printer: CommandLineResultsPrinter,
cliPrinter: (String) -> Unit,
errPrinter: (String) -> Unit
): Int {
val results = sarifReport.runs.first().results
printer.printResults(results, "Qodana - Detailed summary")
return processResultCount(results.size, failThreshold, cliPrinter, errPrinter)
val invocation = processResultCount(results.size, failThreshold, cliPrinter, errPrinter)
sarifReport.runs.first().invocations = listOf(invocation)
SarifUtil.writeReport(sarifPath, sarifReport)
return invocation.exitCode
}

private fun compareBaselineThreshold(
Expand All @@ -91,9 +101,11 @@ object BaselineCli {
return ERROR_EXIT
}
val baselineCalculation = BaselineCalculation.compare(sarifReport, baseline, BaselineCalculation.Options())
SarifUtil.writeReport(sarifPath, sarifReport)
printer.printResultsWithBaselineState(sarifReport.runs.first().results, false)
return processResultCount(baselineCalculation.newResults, failThreshold, cliPrinter, errPrinter)
val invocation = processResultCount(baselineCalculation.newResults, failThreshold, cliPrinter, errPrinter)
sarifReport.runs.first().invocations = listOf(invocation)
SarifUtil.writeReport(sarifPath, sarifReport)
return invocation.exitCode
}

private fun createSarifReport(runs: List<Run>): SarifReport {
Expand Down

0 comments on commit ed2e0f3

Please sign in to comment.