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) {
290
290
291
291
private fun merge (inputs : List <Path >) {
292
292
log(" Parsing ${inputs.size} sarif files" )
293
+ val parsed = loadSarifs(inputs)
293
294
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
+ }
296
301
log(" Writing merged sarif to $outputFile " )
297
302
prepareOutput()
298
303
outputFile.writeText(SarifSerializer .toJson(mergedSarif))
Original file line number Diff line number Diff line change @@ -116,9 +116,9 @@ internal fun List<SarifSchema210>.merge(
116
116
removeUriPrefixes : Boolean = false,
117
117
log : (String ) -> Unit ,
118
118
): SarifSchema210 {
119
+ check(isNotEmpty()) { " Must have at least one sarif file to merge!" }
120
+
119
121
log(" Merging $size sarif files" )
120
- val sortedMergedRules =
121
- flatMap { it.runs.single().tool.driver.rules.orEmpty() }.associateBy { it.id }.toSortedMap()
122
122
val mergedResults =
123
123
flatMap { it.runs.single().results.orEmpty() }
124
124
// Some projects produce multiple reports for different variants, so we need to
@@ -127,6 +127,14 @@ internal fun List<SarifSchema210>.merge(
127
127
.distinctBy { it.shallowHash }
128
128
.also { log(" Merged ${it.size} results" ) }
129
129
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
+
130
138
// Update rule.ruleIndex to match the index in rulesToAdd
131
139
val ruleIndicesById =
132
140
sortedMergedRules.entries.withIndex().associate { (index, entry) -> entry.key to index }
You can’t perform that action at this time.
0 commit comments