|
| 1 | +import type { ReportData, ReportOptions } from './types.js' |
| 2 | +import { generateSummary } from './summary.js' |
| 3 | +import { |
| 4 | + generatePrioritySection, |
| 5 | + generateDuplicatesSection, |
| 6 | + generateClustersSection, |
| 7 | + generateFlaggedSection, |
| 8 | + generateCategorySection, |
| 9 | + generateTopBugsSection, |
| 10 | + generateQuickWinsSection, |
| 11 | + generateNeedsAttentionSection, |
| 12 | + generateEasyFixesSection, |
| 13 | +} from './sections.js' |
| 14 | +import { groupByCategory } from './utils.js' |
| 15 | + |
| 16 | +export function generateReport( |
| 17 | + data: ReportData, |
| 18 | + options: ReportOptions = { variant: 'full' }, |
| 19 | +): string { |
| 20 | + const sections: string[] = [] |
| 21 | + |
| 22 | + // Always include summary |
| 23 | + sections.push(generateSummary(data)) |
| 24 | + |
| 25 | + switch (options.variant) { |
| 26 | + case 'full': |
| 27 | + return generateFullReport(data, sections) |
| 28 | + |
| 29 | + case 'priority': |
| 30 | + return generatePriorityReport(data, sections, options) |
| 31 | + |
| 32 | + case 'category': |
| 33 | + return generateCategoryReport(data, sections, options) |
| 34 | + |
| 35 | + default: |
| 36 | + return generateFullReport(data, sections) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +function generateFullReport(data: ReportData, sections: string[]): string { |
| 41 | + // Priority issues |
| 42 | + sections.push(generatePrioritySection(data.issues, 20)) |
| 43 | + |
| 44 | + // Top bugs (NEW) |
| 45 | + sections.push(generateTopBugsSection(data.issues, 20)) |
| 46 | + |
| 47 | + // Quick wins (NEW) |
| 48 | + sections.push(generateQuickWinsSection(data.issues, 15)) |
| 49 | + |
| 50 | + // Urgent bugs |
| 51 | + sections.push( |
| 52 | + generateFlaggedSection( |
| 53 | + data.issues, |
| 54 | + 'isUrgent', |
| 55 | + '🚨 Urgent Bugs', |
| 56 | + 'Critical bugs that need immediate attention.', |
| 57 | + ), |
| 58 | + ) |
| 59 | + |
| 60 | + // Easy fixes (IMPROVED) |
| 61 | + sections.push(generateEasyFixesSection(data.issues)) |
| 62 | + |
| 63 | + // Needs attention (NEW) |
| 64 | + sections.push(generateNeedsAttentionSection(data.issues, 10)) |
| 65 | + |
| 66 | + // Duplicates |
| 67 | + sections.push(generateDuplicatesSection(data.duplicates)) |
| 68 | + |
| 69 | + // Work clusters (with improved reasoning) |
| 70 | + sections.push(generateClustersSection(data.clusters)) |
| 71 | + |
| 72 | + // Category breakdown |
| 73 | + const byCategory = groupByCategory(data.issues) |
| 74 | + sections.push('## 📂 All Categories') |
| 75 | + sections.push('') |
| 76 | + |
| 77 | + for (const [category, _issues] of Object.entries(byCategory).sort( |
| 78 | + (a, b) => b[1].length - a[1].length, |
| 79 | + )) { |
| 80 | + sections.push(generateCategorySection(data.issues, category)) |
| 81 | + } |
| 82 | + |
| 83 | + return sections.join('\n') |
| 84 | +} |
| 85 | + |
| 86 | +function generatePriorityReport( |
| 87 | + data: ReportData, |
| 88 | + sections: string[], |
| 89 | + options: ReportOptions, |
| 90 | +): string { |
| 91 | + const maxItems = options.maxIssuesPerSection || 50 |
| 92 | + |
| 93 | + sections.push(generatePrioritySection(data.issues, maxItems)) |
| 94 | + sections.push(generateTopBugsSection(data.issues, 15)) |
| 95 | + sections.push(generateQuickWinsSection(data.issues, 10)) |
| 96 | + sections.push( |
| 97 | + generateFlaggedSection( |
| 98 | + data.issues, |
| 99 | + 'isUrgent', |
| 100 | + '🚨 Urgent Bugs', |
| 101 | + 'Critical bugs.', |
| 102 | + ), |
| 103 | + ) |
| 104 | + sections.push(generateClustersSection(data.clusters.slice(0, 5))) |
| 105 | + |
| 106 | + return sections.join('\n') |
| 107 | +} |
| 108 | + |
| 109 | +function generateCategoryReport( |
| 110 | + data: ReportData, |
| 111 | + sections: string[], |
| 112 | + options: ReportOptions, |
| 113 | +): string { |
| 114 | + if (!options.category) { |
| 115 | + throw new Error('Category must be specified for category report variant') |
| 116 | + } |
| 117 | + |
| 118 | + sections.push(generateCategorySection(data.issues, options.category)) |
| 119 | + |
| 120 | + // Include relevant clusters |
| 121 | + const relevantClusters = data.clusters.filter( |
| 122 | + (c) => c.category === options.category, |
| 123 | + ) |
| 124 | + if (relevantClusters.length > 0) { |
| 125 | + sections.push(generateClustersSection(relevantClusters)) |
| 126 | + } |
| 127 | + |
| 128 | + return sections.join('\n') |
| 129 | +} |
0 commit comments