export type Branch = {
name: string;
owner: string;
agent: boolean;
head: string;
subject: string;
pushedAt: string;
// Commits relative to the default branch.
ahead: number;
behind: number;
pull: number | null;
merged: boolean;
};
export type Rule = { pattern: string; rules: string[]; checks: string[] };
export type BranchGroup = 'protected' | 'active' | 'stale' | 'merged';
const staleMs = 30 * 86_400_000;
// The default branch is the protected one: it takes merges only, under the repository's merge rules.
export const groupOf = (b: Branch, defaultBranch: string): BranchGroup =>
b.name === defaultBranch ? 'protected' : b.merged ? 'merged' : Date.now() - new Date(b.pushedAt).getTime() > staleMs ? 'stale' : 'active';