parseAndDisplayZizmorOutput parses zizmor JSON output and displays it in the desired format Returns the total number of warnings found
(stdout, stderr string, verbose bool)
| 176 | // parseAndDisplayZizmorOutput parses zizmor JSON output and displays it in the desired format |
| 177 | // Returns the total number of warnings found |
| 178 | func parseAndDisplayZizmorOutput(stdout, stderr string, verbose bool) (int, error) { |
| 179 | // Map findings to files for detailed display |
| 180 | fileFindings := make(map[string][]zizmorFinding) |
| 181 | |
| 182 | // Parse stderr for "completed" messages to get list of files |
| 183 | completedFiles := []string{} |
| 184 | scanner := bufio.NewScanner(strings.NewReader(stderr)) |
| 185 | for scanner.Scan() { |
| 186 | line := scanner.Text() |
| 187 | // Look for lines like: " INFO audit: zizmor: 🌈 completed ./.github/workflows/pdf-summary.lock.yml" |
| 188 | if strings.Contains(line, "INFO audit: zizmor: 🌈 completed") { |
| 189 | parts := strings.Split(line, "completed ") |
| 190 | if len(parts) == 2 { |
| 191 | filePath := strings.TrimSpace(parts[1]) |
| 192 | completedFiles = append(completedFiles, filePath) |
| 193 | // Initialize empty findings slice |
| 194 | if _, exists := fileFindings[filePath]; !exists { |
| 195 | fileFindings[filePath] = []zizmorFinding{} |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // Parse JSON findings from stdout |
| 202 | var findings []zizmorFinding |
| 203 | totalWarnings := 0 |
| 204 | if stdout != "" && strings.HasPrefix(strings.TrimSpace(stdout), "[") { |
| 205 | if err := json.Unmarshal([]byte(stdout), &findings); err != nil { |
| 206 | return 0, fmt.Errorf("failed to parse zizmor JSON output: %w", err) |
| 207 | } |
| 208 | |
| 209 | // Organize findings by file |
| 210 | for _, finding := range findings { |
| 211 | // Track which files this finding affects (avoid duplicates) |
| 212 | affectedFiles := make(map[string]struct { |
| 213 | }) |
| 214 | for _, location := range finding.Locations { |
| 215 | filePath := location.Symbolic.Key.Local.GivenPath |
| 216 | if filePath != "" && !setutil.Contains(affectedFiles, filePath) { |
| 217 | affectedFiles[filePath] = struct { |
| 218 | }{} |
| 219 | fileFindings[filePath] = append(fileFindings[filePath], finding) |
| 220 | totalWarnings++ |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Display reformatted output for each completed file |
| 227 | for _, filePath := range completedFiles { |
| 228 | findings := fileFindings[filePath] |
| 229 | count := len(findings) |
| 230 | |
| 231 | // Skip files with 0 warnings |
| 232 | if count == 0 { |
| 233 | continue |
| 234 | } |
| 235 |