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
src/reports/publish-gate.tsadded+35-0
Changes to src/reports/publish-gate.ts
@@ -0,0 +1,35 @@
1/**
2 * Whether a report run should publish.
3 *
4 * `reports.enabled` was documented as the opt-in for scheduled reports and
5 * defaulted to `false`, and nothing read it — the generated workflow published
6 * every week regardless. A person at a terminal typing `--publish` has already
7 * decided; the setting exists to govern the run nobody typed.
8 *
9 * @param options - Whether this is the scheduled run, and what config says
10 * @returns Whether to publish, and why not when not
11 * @example
12 * ```ts
13 * shouldPublishReport({ scheduled: true, enabled: undefined })
14 * // { publish: false, reason: 'reports.enabled is not set' }
15 * ```
16 */
17export function shouldPublishReport(options: {
18 /** The run came from the generated workflow's schedule, not a person */
19 scheduled: boolean
20 /** `reports.enabled` from config */
21 enabled: boolean | undefined
22}): { publish: boolean, reason?: string } {
23 if (!options.scheduled)
24 return { publish: true }
25
26 if (options.enabled === true)
27 return { publish: true }
28
29 return {
30 publish: false,
31 reason: options.enabled === false
32 ? 'reports.enabled is false'
33 : 'reports.enabled is not set — scheduled reports are opt-in',
34 }
35}