|
| 1 | +import type { ScanResult } from "./scanner.js"; |
| 2 | + |
| 3 | +const RED = "\x1b[0;31m"; |
| 4 | +const GREEN = "\x1b[0;32m"; |
| 5 | +const YELLOW = "\x1b[1;33m"; |
| 6 | +const CYAN = "\x1b[0;36m"; |
| 7 | +const BOLD = "\x1b[1m"; |
| 8 | +const RESET = "\x1b[0m"; |
| 9 | + |
| 10 | +export function printChangedFiles(files: string[]): void { |
| 11 | + console.log(`${CYAN}${BOLD}Changed files:${RESET}`); |
| 12 | + for (const f of files) console.log(f); |
| 13 | + console.log(); |
| 14 | +} |
| 15 | + |
| 16 | +export function printScanHeader(file: string): void { |
| 17 | + console.log(`${CYAN}--- Scanning: ${file} ---${RESET}`); |
| 18 | +} |
| 19 | + |
| 20 | +export function printSummary(results: ScanResult[]): void { |
| 21 | + const passed = results.filter(r => r.passed); |
| 22 | + const failed = results.filter(r => !r.passed); |
| 23 | + |
| 24 | + console.log(); |
| 25 | + console.log(`${BOLD}========== Scan Summary ==========${RESET}`); |
| 26 | + |
| 27 | + if (passed.length > 0) { |
| 28 | + console.log(`${GREEN}${BOLD}PASSED (${passed.length}):${RESET}`); |
| 29 | + for (const r of passed) console.log(` ${GREEN}✔ ${r.file}${RESET}`); |
| 30 | + } |
| 31 | + |
| 32 | + const unauthorized = results.filter(r => r.unauthorized); |
| 33 | + |
| 34 | + if (unauthorized.length > 0) { |
| 35 | + console.log(`${YELLOW}${BOLD}UNAUTHORIZED (${unauthorized.length}):${RESET}`); |
| 36 | + for (const r of unauthorized) console.log(` ${YELLOW}⚠ ${r.file}${RESET}`); |
| 37 | + console.log(`${YELLOW}${BOLD}SNYK_TOKEN is invalid or missing. Scan results are incomplete.${RESET}`); |
| 38 | + process.exit(1); |
| 39 | + } |
| 40 | + |
| 41 | + if (failed.length > 0) { |
| 42 | + console.log(`${RED}${BOLD}FAILED (${failed.length}):${RESET}`); |
| 43 | + for (const r of failed) { |
| 44 | + console.log(` ${RED}✘ ${r.file}${RESET}`); |
| 45 | + console.log(r.output.trimEnd()); |
| 46 | + console.log(); |
| 47 | + } |
| 48 | + console.log(`${RED}${BOLD}Job failed due to security findings in the files above.${RESET}`); |
| 49 | + process.exit(1); |
| 50 | + } |
| 51 | + |
| 52 | + console.log(`${GREEN}${BOLD}All scans passed.${RESET}`); |
| 53 | +} |
0 commit comments