// The setting keep-main-rules (the operator, 2026-10-23: "disable the gitea branch protection reset thing"): only when it // is true does the module put main's rule right in every repository of the organisation (client.ts ensureMainMerges). // False, the default, leaves every repository's branch protection as people set it at the forge. import { readFileSync } from "node:fs"; export const LEFT_AS_SET = "[gitea] main's rules are left as set at the forge (keep-main-rules is false)"; /** The setting from the settings-merged config file the mesh delivers; absent, unreadable or not true is false. */ export function keepMainRules(env: NodeJS.ProcessEnv = process.env): boolean { const file = env.MESH_GITEA_CONFIG_FILE; if (!file) return false; try { const v = (JSON.parse(readFileSync(file, "utf8")) as Record)["keep-main-rules"]; return v === true || v === "true"; } catch { return false; } } /** The 10-minute step: puts the rules right only when kept; else says once that they are left and writes nothing. */ export function mainRulesStep(keep: boolean, put: () => Promise, say: (line: string) => void): () => Promise { let said = false; let touched = -1; return async () => { if (!keep) { if (!said) say(LEFT_AS_SET); said = true; return; } const repos = await put(); if (repos.length !== touched) say(`[gitea] main's rule is right in ${repos.length} repositories`); touched = repos.length; }; }