This repository was archived by the owner on Oct 14, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
src/main/kotlin/slack/cli/sarif Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -290,9 +290,14 @@ public class MergeSarifReports : CliktCommand(help = DESCRIPTION) {
290290
291291 private fun merge (inputs : List <Path >) {
292292 log(" Parsing ${inputs.size} sarif files" )
293+ val parsed = loadSarifs(inputs)
293294 val mergedSarif =
294- loadSarifs(inputs)
295- .merge(levelOverride = level, removeUriPrefixes = removeUriPrefixes, log = ::log)
295+ when (parsed.size) {
296+ 0 -> error(" No sarif files parsed. Consider using --allow-empty" )
297+ 1 -> parsed[0 ]
298+ else ->
299+ parsed.merge(levelOverride = level, removeUriPrefixes = removeUriPrefixes, log = ::log)
300+ }
296301 log(" Writing merged sarif to $outputFile " )
297302 prepareOutput()
298303 outputFile.writeText(SarifSerializer .toJson(mergedSarif))
Original file line number Diff line number Diff line change @@ -116,9 +116,9 @@ internal fun List<SarifSchema210>.merge(
116116 removeUriPrefixes : Boolean = false,
117117 log : (String ) -> Unit ,
118118): SarifSchema210 {
119+ check(isNotEmpty()) { " Must have at least one sarif file to merge!" }
120+
119121 log(" Merging $size sarif files" )
120- val sortedMergedRules =
121- flatMap { it.runs.single().tool.driver.rules.orEmpty() }.associateBy { it.id }.toSortedMap()
122122 val mergedResults =
123123 flatMap { it.runs.single().results.orEmpty() }
124124 // Some projects produce multiple reports for different variants, so we need to
@@ -127,6 +127,14 @@ internal fun List<SarifSchema210>.merge(
127127 .distinctBy { it.shallowHash }
128128 .also { log(" Merged ${it.size} results" ) }
129129
130+ if (mergedResults.isEmpty()) {
131+ // Nothing to do here, just return the first
132+ return this [0 ]
133+ }
134+
135+ val sortedMergedRules =
136+ flatMap { it.runs.single().tool.driver.rules.orEmpty() }.associateBy { it.id }.toSortedMap()
137+
130138 // Update rule.ruleIndex to match the index in rulesToAdd
131139 val ruleIndicesById =
132140 sortedMergedRules.entries.withIndex().associate { (index, entry) -> entry.key to index }
You can’t perform that action at this time.
0 commit comments