Files
mesh-catalog/modules/gitea/mainrules.ts
T
jschoubben 77f33d317f Keep main's rules only when the setting keep-main-rules is true (default false)
The operator, 2026-10-23: "disable the gitea branch protection reset thing". The 10-minute tick and the start-time
ensureMainMerges, and the repositories sync's changes to existing repositories' main rules, now run only when the new
setting is true; new repositories are still made. The sync says in its outcome that rules were left.
2026-10-23 15:53:30 +02:00

33 lines
1.5 KiB
TypeScript

// 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<string, unknown>)["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<string[]>, say: (line: string) => void): () => Promise<void> {
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;
};
}