Public/Test-CCRepoSettings.ps1
|
function Test-CCRepoSettings { <# .SYNOPSIS Validates GitHub repository settings (description, topics, merge config, etc.). .PARAMETER Repository GitHub repository in format "owner/repo". Auto-detected if not specified. .PARAMETER Token GitHub token. Falls back to GITHUB_TOKEN, GH_TOKEN, or gh CLI. .PARAMETER Standard Standard tier: core, active, minimal. Default: core. .PARAMETER Config Path to per-repo config file for overrides. .OUTPUTS [PSCustomObject[]] Array of check results. .EXAMPLE Test-CCRepoSettings -Repository 'The-Code-Kitchen/PowerCraft.Secrets' #> [CmdletBinding()] [OutputType([PSCustomObject[]])] param( [Parameter()] [string]$Repository, [Parameter()] [string]$Token, [Parameter()] [ValidateSet('core', 'active', 'minimal')] [string]$Standard = 'core', [Parameter()] [string]$Config ) $results = [System.Collections.ArrayList]::new() $token = Resolve-CCToken -Token $Token if (-not $token) { throw "No GitHub token available. Set GITHUB_TOKEN or run 'gh auth login'." } $repo = Resolve-CCRepository -Repository $Repository if (-not $repo) { throw "Cannot determine repository. Specify -Repository 'owner/repo'." } $stdConfig = (Get-CCStandardConfig -Standard $Standard -ConfigPath $Config).settings $repoInfo = Invoke-CCGitHubApi -Endpoint "repos/$repo" -Token $token # GH-SET-001: Has description if ($stdConfig.require_description) { if ($repoInfo.description -and $repoInfo.description.Trim().Length -gt 0) { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-001' -Category 'Repository Settings' -Item 'Description' ` -Status 'Pass' -Severity 'Info' -Message "Description: $($repoInfo.description)")) } else { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-001' -Category 'Repository Settings' -Item 'Description' ` -Status 'Fail' -Severity 'Warning' ` -Message 'Repository has no description' ` -FixAvailable $true -FixId 'SetDescription' -Current $null -Expected 'A meaningful description')) } } # GH-SET-002: Has topics if ($stdConfig.require_topics) { if ($repoInfo.topics -and $repoInfo.topics.Count -gt 0) { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-002' -Category 'Repository Settings' -Item 'Topics' ` -Status 'Pass' -Severity 'Info' -Message "Topics: $($repoInfo.topics -join ', ')")) } else { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-002' -Category 'Repository Settings' -Item 'Topics' ` -Status 'Fail' -Severity 'Warning' ` -Message 'Repository has no topics/tags for discoverability' ` -FixAvailable $false -Current $null -Expected 'At least one topic')) } } # GH-SET-003: Issues enabled if ($stdConfig.issues_enabled) { if ($repoInfo.has_issues) { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-003' -Category 'Repository Settings' -Item 'Issues' ` -Status 'Pass' -Severity 'Info' -Message 'Issues enabled')) } else { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-003' -Category 'Repository Settings' -Item 'Issues' ` -Status 'Fail' -Severity 'Warning' ` -Message 'Issues are disabled' ` -FixAvailable $true -FixId 'EnableIssues' -Current $false -Expected $true)) } } # GH-SET-004: Default branch name if ($stdConfig.default_branch_name) { if ($repoInfo.default_branch -eq $stdConfig.default_branch_name) { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-004' -Category 'Repository Settings' -Item 'Default Branch' ` -Status 'Pass' -Severity 'Info' -Message "Default branch is '$($repoInfo.default_branch)'")) } else { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-004' -Category 'Repository Settings' -Item 'Default Branch' ` -Status 'Warning' -Severity 'Warning' ` -Message "Default branch is '$($repoInfo.default_branch)', expected '$($stdConfig.default_branch_name)'" ` -Current $repoInfo.default_branch -Expected $stdConfig.default_branch_name)) } } # GH-SET-005: Delete branch on merge if ($stdConfig.delete_branch_on_merge) { if ($repoInfo.delete_branch_on_merge) { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-005' -Category 'Repository Settings' -Item 'Delete on Merge' ` -Status 'Pass' -Severity 'Info' -Message 'Branches auto-deleted after merge')) } else { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-005' -Category 'Repository Settings' -Item 'Delete on Merge' ` -Status 'Fail' -Severity 'Warning' ` -Message 'Branches not auto-deleted after merge' ` -FixAvailable $true -FixId 'EnableDeleteOnMerge' -Current $false -Expected $true)) } } # GH-SET-006: Squash merge allowed if ($stdConfig.allow_squash_merge) { if ($repoInfo.allow_squash_merge) { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-006' -Category 'Repository Settings' -Item 'Squash Merge' ` -Status 'Pass' -Severity 'Info' -Message 'Squash merge allowed')) } else { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-006' -Category 'Repository Settings' -Item 'Squash Merge' ` -Status 'Warning' -Severity 'Info' ` -Message 'Squash merge not allowed' ` -Current $false -Expected $true)) } } # GH-SET-008: Wiki disabled (unless intentionally used) if ($stdConfig.wiki_disabled) { if (-not $repoInfo.has_wiki) { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-008' -Category 'Repository Settings' -Item 'Wiki' ` -Status 'Pass' -Severity 'Info' -Message 'Wiki disabled (docs should live in repo)')) } else { [void]$results.Add((New-CCCheckResult -CheckId 'GH-SET-008' -Category 'Repository Settings' -Item 'Wiki' ` -Status 'Warning' -Severity 'Info' ` -Message 'Wiki is enabled — consider using in-repo docs instead' ` -FixAvailable $true -FixId 'DisableWiki' -Current $true -Expected $false)) } } return $results.ToArray() } |