Public/Get-CCGitHubReport.ps1
|
function Get-CCGitHubReport { <# .SYNOPSIS Generates a formatted compliance report from audit results. .PARAMETER Repository GitHub repository in format "owner/repo". Auto-detected if not specified. .PARAMETER Token GitHub token. .PARAMETER Standard Standard tier: core, active, minimal. Default: core. .PARAMETER Format Output format: Markdown, Json, or Summary. Default: Markdown. .OUTPUTS [string] Formatted report. .EXAMPLE Get-CCGitHubReport -Repository 'The-Code-Kitchen/LeadForge' -Format Markdown .EXAMPLE Get-CCGitHubReport | Set-Content ./compliance-report.md #> [CmdletBinding()] [OutputType([string])] param( [Parameter()] [string]$Repository, [Parameter()] [string]$Token, [Parameter()] [ValidateSet('core', 'active', 'minimal')] [string]$Standard = 'core', [Parameter()] [ValidateSet('Markdown', 'Json', 'Summary')] [string]$Format = 'Markdown' ) $token = Resolve-CCToken -Token $Token if (-not $token) { throw "No GitHub token available." } $repo = Resolve-CCRepository -Repository $Repository if (-not $repo) { throw "Cannot determine repository." } $results = Test-CCGitHub -Repository $repo -Token $token -Standard $Standard -OutputFormat Quiet $passed = @($results | Where-Object Status -eq 'Pass').Count $failed = @($results | Where-Object Status -eq 'Fail').Count $warnings = @($results | Where-Object Status -eq 'Warning').Count $total = $results.Count switch ($Format) { 'Json' { return ([PSCustomObject]@{ repository = $repo standard = $Standard timestamp = (Get-Date -Format 'o') summary = [PSCustomObject]@{ total = $total; pass = $passed; fail = $failed; warning = $warnings } results = $results } | ConvertTo-Json -Depth 5) } 'Summary' { return "[$repo] Standard: $Standard | Pass: $passed | Fail: $failed | Warning: $warnings | Total: $total" } 'Markdown' { $sb = [System.Text.StringBuilder]::new() [void]$sb.AppendLine("# GitHub Compliance Report") [void]$sb.AppendLine("") [void]$sb.AppendLine("| Field | Value |") [void]$sb.AppendLine("|-------|-------|") [void]$sb.AppendLine("| Repository | ``$repo`` |") [void]$sb.AppendLine("| Standard | $Standard |") [void]$sb.AppendLine("| Date | $(Get-Date -Format 'yyyy-MM-dd HH:mm') |") [void]$sb.AppendLine("| Pass | $passed |") [void]$sb.AppendLine("| Fail | $failed |") [void]$sb.AppendLine("| Warning | $warnings |") [void]$sb.AppendLine("") $categories = $results | Group-Object Category foreach ($cat in $categories) { [void]$sb.AppendLine("## $($cat.Name)") [void]$sb.AppendLine("") [void]$sb.AppendLine("| Check | Status | Message |") [void]$sb.AppendLine("|-------|--------|---------|") foreach ($r in $cat.Group) { $icon = switch ($r.Status) { 'Pass' { '✅' } 'Fail' { '❌' } 'Warning' { '⚠️' } 'Skipped' { '⏭️' } } [void]$sb.AppendLine("| $($r.CheckId) | $icon $($r.Status) | $($r.Message) |") } [void]$sb.AppendLine("") } # Fixable issues $fixable = $results | Where-Object { $_.FixAvailable -and $_.Status -in @('Fail', 'Warning') } if ($fixable.Count -gt 0) { [void]$sb.AppendLine("## Auto-Fixable Issues") [void]$sb.AppendLine("") [void]$sb.AppendLine('Run `Repair-CCGitHub` to fix these automatically:') [void]$sb.AppendLine("") foreach ($f in $fixable) { [void]$sb.AppendLine("- **$($f.FixId)**: $($f.Message)") } } return $sb.ToString() } } } |