ReviewOS

also looking at this

stacks/buddy

fix(dashboard): read the include toggles and the enabled switch

#1430
Merged glennmichael123 wants to merge fix/dashboard-toggles into main
5 files +100 -2

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

bin/cli.tsmodified+12-0
Changes to bin/cli.ts
@@ -793,6 +793,16 @@ cli
793793 const logger = options.verbose ? Logger.verbose() : Logger.quiet()
794794 const config = await resolveConfig(options.config)
795795
796 // Explicit `false` only. Unset stays on: the setting was documented as
797 // defaulting to false and was read by nothing, and enforcing that
798 // literally would switch off the dashboard for every repository that
799 // never wrote a `dashboard` block — the same trap `ai.review.enabled`
800 // set, and the same reading that avoids it.
801 if (config.dashboard?.enabled === false) {
802 logger.info('ℹ️ Dashboard is disabled by config (dashboard.enabled: false)')
803 return
804 }
805
796806 try {
797807 logger.info('Creating or updating dependency dashboard...')
798808
@@ -3151,6 +3161,8 @@ cli
31513161 // Supplied here because refreshing means a full scan, which is
31523162 // `Buddy`'s job rather than the gate module's.
31533163 refreshDashboard: async () => {
3164 if (config.dashboard?.enabled === false)
3165 throw new Error('dashboard.enabled is false')
31543166 await new Buddy(config).createOrUpdateDashboard()
31553167 },
31563168 })
docs/features/dependency-dashboard.mdmodified+1-1
Changes to docs/features/dependency-dashboard.md
@@ -62,7 +62,7 @@ export default {
6262
6363| Option | Type | Default | Description |
6464|--------|------|---------|-------------|
65| `enabled` | `boolean` | `false` | Enable dependency dashboard |
65| `enabled` | `boolean` | `true` | Set to `false` to stop the dashboard being created or refreshed |
6666| `title` | `string` | `'Dependency Dashboard'` | Custom dashboard title |
6767| `labels` | `string[]` | `['dependencies', 'dashboard']` | Labels to add to the issue |
6868| `assignees` | `string[]` | `[]` | Users to assign to the issue |
src/buddy.tsmodified+3-0
Changes to src/buddy.ts
@@ -3289,6 +3289,9 @@ export class Buddy {
32893289 showOpenPRs: dashboardConfig.showOpenPRs ?? true,
32903290 showDetectedDependencies: dashboardConfig.showDetectedDependencies ?? true,
32913291 showDeprecatedDependencies: dashboardConfig.showDeprecatedDependencies ?? true,
3292 includePackageJson: dashboardConfig.includePackageJson ?? true,
3293 includeDependencyFiles: dashboardConfig.includeDependencyFiles ?? true,
3294 includeGitHubActions: dashboardConfig.includeGitHubActions ?? true,
32923295 bodyTemplate: dashboardConfig.bodyTemplate,
32933296 })
32943297
src/dashboard/dashboard-generator.tsmodified+14-1
Changes to src/dashboard/dashboard-generator.ts
@@ -18,6 +18,10 @@ export class DashboardGenerator {
1818 showDetectedDependencies?: boolean
1919 showDeprecatedDependencies?: boolean
2020 showVulnerableDependencies?: boolean
21 /** Per-ecosystem toggles within the detected-dependencies section */
22 includePackageJson?: boolean
23 includeDependencyFiles?: boolean
24 includeGitHubActions?: boolean
2125 bodyTemplate?: string
2226 } = {}): { title: string, body: string } {
2327 const {
@@ -25,6 +29,9 @@ export class DashboardGenerator {
2529 showDetectedDependencies = true,
2630 showDeprecatedDependencies = true,
2731 showVulnerableDependencies = true,
32 includePackageJson = true,
33 includeDependencyFiles = true,
34 includeGitHubActions = true,
2835 bodyTemplate,
2936 } = options
3037
@@ -61,7 +68,13 @@ export class DashboardGenerator {
6168 }
6269
6370 if (showDetectedDependencies) {
64 body += this.generateDetectedDependenciesSection(data.detectedDependencies)
71 // The three `include*` toggles were declared, documented in the defaults
72 // table, and read by nothing — every ecosystem was always listed.
73 body += this.generateDetectedDependenciesSection({
74 packageJson: includePackageJson ? data.detectedDependencies.packageJson : [],
75 dependencyFiles: includeDependencyFiles ? data.detectedDependencies.dependencyFiles : [],
76 githubActions: includeGitHubActions ? data.detectedDependencies.githubActions : [],
77 })
6578 }
6679
6780 body += this.generateFooter()
test/dashboard-generator.test.tsmodified+70-0
Changes to test/dashboard-generator.test.ts
@@ -855,3 +855,73 @@ Dependency files:
855855 expect(result.body).toContain('<!-- rebase-branch=renovate/symfony-console-7.x -->')
856856 })
857857})
858
859/**
860 * `includePackageJson`, `includeDependencyFiles` and `includeGitHubActions`
861 * were declared, documented in the defaults table as `true`, and read by
862 * nothing — every ecosystem was always listed whatever the config said.
863 */
864describe('per-ecosystem include toggles', () => {
865 const generator = new DashboardGenerator()
866
867 function file(path: string, type: PackageFile['type'], depType: PackageFile['dependencies'][number]['type']): PackageFile {
868 return {
869 path,
870 type,
871 content: '',
872 dependencies: [{ name: `dep-in-${path}`, currentVersion: '1.0.0', type: depType, file: path }],
873 }
874 }
875
876 const data: DashboardData = {
877 repository: { owner: 'o', name: 'r', provider: 'github' },
878 openPRs: [],
879 detectedDependencies: {
880 packageJson: [file('package.json', 'package.json', 'dependencies')],
881 dependencyFiles: [file('deps.yaml', 'deps.yaml', 'dependencies')],
882 githubActions: [file('.github/workflows/ci.yml', 'github-actions', 'github-actions')],
883 },
884 lastUpdated: new Date('2024-01-01T00:00:00Z'),
885 }
886
887 it('success case - everything is listed by default', () => {
888 const { body } = generator.generateDashboard(data)
889
890 expect(body).toContain('<summary>npm</summary>')
891 expect(body).toContain('<summary>github-actions</summary>')
892 expect(body).toContain('<summary>dependency-files</summary>')
893 })
894
895 it('success case - includePackageJson: false drops the npm section only', () => {
896 const { body } = generator.generateDashboard(data, { includePackageJson: false })
897
898 expect(body).not.toContain('<summary>npm</summary>')
899 expect(body).toContain('<summary>github-actions</summary>')
900 expect(body).toContain('<summary>dependency-files</summary>')
901 })
902
903 it('success case - includeGitHubActions: false drops the actions section only', () => {
904 const { body } = generator.generateDashboard(data, { includeGitHubActions: false })
905
906 expect(body).not.toContain('<summary>github-actions</summary>')
907 expect(body).toContain('<summary>npm</summary>')
908 })
909
910 it('success case - includeDependencyFiles: false drops the dependency-files section only', () => {
911 const { body } = generator.generateDashboard(data, { includeDependencyFiles: false })
912
913 expect(body).not.toContain('<summary>dependency-files</summary>')
914 expect(body).toContain('<summary>npm</summary>')
915 })
916
917 it('edge case - all three off leaves the heading and nothing under it', () => {
918 const { body } = generator.generateDashboard(data, {
919 includePackageJson: false,
920 includeDependencyFiles: false,
921 includeGitHubActions: false,
922 })
923
924 expect(body).toContain('## Detected dependencies')
925 expect(body).not.toContain('<summary>')
926 })
927})