Module: Sharekit::Cli::Reporter
- Defined in:
- lib/sharekit/cli/reporter.rb
Overview
Formats findings for terminal output and gates high-severity secrets.
Constant Summary collapse
- GREEN =
"\e[32m"- YELLOW =
"\e[33m"- RESET =
"\e[0m"
Class Method Summary collapse
-
.format_line(finding) ⇒ Object
Data.define objects deconstruct into a Hash for free, so
incan match directly on the fields we care about — no case/when + manual field access. - .gate!(findings, force:) ⇒ Object
- .report(findings, force: false) ⇒ Object
Class Method Details
.format_line(finding) ⇒ Object
Data.define objects deconstruct into a Hash for free, so in can match
directly on the fields we care about — no case/when + manual field access.
28 29 30 31 32 33 |
# File 'lib/sharekit/cli/reporter.rb', line 28 def format_line(finding) case finding in { file:, line:, rule:, preview: } "#{file}:#{line} [#{rule}] #{preview}" end end |
.gate!(findings, force:) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/sharekit/cli/reporter.rb', line 35 def gate!(findings, force:) high = findings.select(&:high?) return if high.empty? || force raise Error, "Secrets export blocked: #{high.size} high-severity finding(s) detected. " \ "Review and remove secrets, or re-run with --force to override." end |
.report(findings, force: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sharekit/cli/reporter.rb', line 13 def report(findings, force: false) if findings.empty? puts "#{GREEN} ✓ No secrets detected.\n#{RESET}" return end puts "#{YELLOW}\n ⚠ Secret patterns detected:#{RESET}" findings.each { |finding| puts "#{YELLOW} #{format_line(finding)}#{RESET}" } puts "#{YELLOW}\n ⚠ Review and redact secrets before pushing to a public repository.\n#{RESET}" gate!(findings, force:) end |