Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

27 linesCodeBlameRaw
1import type { GuardrailSettings, RunKind } from "@g1t/contracts";
2
3/** A number from a field; empty means inherit. Not a number is kept, to be refused. */
4function amount(value: FormDataEntryValue | null): number | null {
5 const text = String(value ?? "")
6 .trim()
7 .replace(/^\$/, "");
8 if (!text) return null;
9 const number = Number(text);
10 return Number.isFinite(number) ? number : Number.NaN;
11}
12
13/** The kinds of run that still use a sandbox: checks, the merge queue and merge checks. */
14export const SANDBOX_RUN_KINDS = ["checks", "queue", "mergecheck"] as const satisfies readonly RunKind[];
15
16/**
17 * What one level's form says, as the settings that level keeps: a time cap
18 * for each kind of run it sets, the rest inherited.
19 */
20export function settingsFromForm(form: FormData, catalog: { kinds: readonly RunKind[] }): GuardrailSettings {
21 const minutes: Record<string, number> = {};
22 for (const kind of catalog.kinds) {
23 const cap = amount(form.get(`minutes:${kind}`));
24 if (cap != null) minutes[kind] = Number.isNaN(cap) ? 0 : Math.trunc(cap);
25 }
26 return { minutes };
27}