ReviewOS

also looking at this

stacks/buddy

fix(reports): honour reports.enabled and reports.period, drop the key nothing could read

#1429
Merged glennmichael123 wants to merge fix/reports-config into main
7 files +118 -9
bin/cli.tsmodified+15-1
Changes to bin/cli.ts
@@ -3172,6 +3172,7 @@ cli
31723172 .option('--format <name>', 'Output format: markdown|json', { default: 'markdown' })
31733173 .option('--prompt <focus>', 'Focus for the AI narrative, when a provider is configured')
31743174 .option('--publish', 'Publish to the repository\'s report issue')
3175 .option('--scheduled', 'This is the workflow\'s scheduled run; honour reports.enabled')
31753176 .option('--verbose, -v', 'Enable verbose logging')
31763177 .example('buddy report --period 7d')
31773178 .example('buddy report --prompt "focus on security posture" --publish')
@@ -3180,6 +3181,7 @@ cli
31803181 format?: string
31813182 prompt?: string
31823183 publish?: boolean
3184 scheduled?: boolean
31833185 }) => {
31843186 const quiet = options.format === 'json'
31853187 const logger = options.verbose ? Logger.verbose() : quiet ? Logger.silent() : Logger.quiet()
@@ -3199,7 +3201,9 @@ cli
31993201 withNarrative,
32003202 } = await import('../src/reports')
32013203
3202 const period = (options.period ?? '30d') as '7d' | '30d' | '90d'
3204 // The flag wins, then config, then the default. `reports.period` was
3205 // documented, defaulted and never consulted — only the flag was.
3206 const period = (options.period ?? config.reports?.period ?? '30d') as '7d' | '30d' | '90d'
32033207 if (!REPORT_PERIODS.includes(period)) {
32043208 logger.error(`❌ Unknown period '${period}'. Expected one of ${REPORT_PERIODS.join(', ')}.`)
32053209 process.exit(1)
@@ -3267,6 +3271,16 @@ cli
32673271 logger,
32683272 )
32693273
3274 // The generated workflow passes --scheduled, so this is where the
3275 // documented "default: false" is actually enforced. It cannot be
3276 // enforced in the workflow: a cron trigger cannot read the config.
3277 const { shouldPublishReport } = await import('../src/reports')
3278 const gate = shouldPublishReport({ scheduled: Boolean(options.scheduled), enabled: config.reports?.enabled })
3279 if (options.publish && !gate.publish) {
3280 logger.info(`ℹ️ Not publishing: ${gate.reason}`)
3281 return
3282 }
3283
32703284 if (!options.publish) {
32713285 process.stdout.write(`${report}\n`)
32723286 return