Class: Zwischen::Reporter::Terminal
- Inherits:
-
Object
- Object
- Zwischen::Reporter::Terminal
- Defined in:
- lib/zwischen/reporter/terminal.rb
Constant Summary collapse
- SEVERITY_COLORS =
{ "critical" => :red, "high" => :red, "medium" => :yellow, "low" => :blue, "info" => :cyan }.freeze
- SEVERITY_BADGES =
{ "critical" => "🔴 CRITICAL", "high" => "🔴 HIGH", "medium" => "🟡 MEDIUM", "low" => "🔵 LOW", "info" => "ℹ️ INFO" }.freeze
Class Method Summary collapse
- .report(aggregated_results, config: nil, ai_enabled: false) ⇒ Object
- .report_compact(aggregated_results, config:, ai_enabled: false) ⇒ Object
Instance Method Summary collapse
-
#display_path(path) ⇒ Object
Show paths relative to the working directory when they live under it.
-
#initialize(aggregated_results, ai_enabled: false, config: nil) ⇒ Terminal
constructor
A new instance of Terminal.
- #report ⇒ Object
- #report_compact ⇒ Object
Constructor Details
#initialize(aggregated_results, ai_enabled: false, config: nil) ⇒ Terminal
Returns a new instance of Terminal.
33 34 35 36 37 |
# File 'lib/zwischen/reporter/terminal.rb', line 33 def initialize(aggregated_results, ai_enabled: false, config: nil) @results = aggregated_results @ai_enabled = ai_enabled @config = config end |
Class Method Details
.report(aggregated_results, config: nil, ai_enabled: false) ⇒ Object
25 26 27 |
# File 'lib/zwischen/reporter/terminal.rb', line 25 def self.report(aggregated_results, config: nil, ai_enabled: false) new(aggregated_results, ai_enabled: ai_enabled, config: config).report end |
.report_compact(aggregated_results, config:, ai_enabled: false) ⇒ Object
29 30 31 |
# File 'lib/zwischen/reporter/terminal.rb', line 29 def self.report_compact(aggregated_results, config:, ai_enabled: false) new(aggregated_results, ai_enabled: ai_enabled, config: config).report_compact end |
Instance Method Details
#display_path(path) ⇒ Object
Show paths relative to the working directory when they live under it. Scanners may emit symlink-resolved absolute paths (/tmp vs /private/tmp on macOS), so compare against the resolved cwd too.
42 43 44 45 46 47 48 |
# File 'lib/zwischen/reporter/terminal.rb', line 42 def display_path(path) = File.(path.to_s) [Dir.pwd, (File.realpath(Dir.pwd) rescue Dir.pwd)].uniq.each do |root| return .delete_prefix("#{root}/") if .start_with?("#{root}/") end path.to_s end |
#report ⇒ Object
50 51 52 53 54 |
# File 'lib/zwischen/reporter/terminal.rb', line 50 def report print_summary print_findings exit_code end |
#report_compact ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/zwischen/reporter/terminal.rb', line 56 def report_compact blocking_severity = @config&.blocking_severity || "high" findings = @results[:findings] # Filter to only blocking findings blocking_findings = findings.select { |f| should_block?(f, blocking_severity) } # If no blocking findings, exit silently (exit code 0) return 0 if blocking_findings.empty? # Show compact output for blocking findings puts "🛡️ Zwischen: #{blocking_findings.length} issue#{blocking_findings.length == 1 ? '' : 's'} found\n\n" blocking_findings.each do |finding| severity_color = SEVERITY_COLORS[finding.severity] || :white severity_label = finding.severity.upcase puts " #{severity_label}".colorize(severity_color) + " #{display_path(finding.file)}:#{finding.line || '?'}" puts " #{finding.}" # Show fix suggestion if available if @ai_enabled && finding.raw_data["ai_fix_suggestion"] puts " → #{finding.raw_data['ai_fix_suggestion']}" end puts "" end puts "Push blocked. Fix issues above or:" puts " • Run 'zwischen scan' for full report" puts " • Run 'git push --no-verify' to skip (not recommended)" 1 # Exit code 1 = push blocked end |