DevelopOther
@holtkeeper/branches
The branches analyzer and analysis kind: lists the branches of a repository that are worth deleting — merged but left behind, abandoned after a closed merge request, or without commits for a long time — with who last committed to each, so everyone can see what to clean up after themselves. It only reports; it never deletes a branch.
Public API
Section titled “Public API”branchesAnalyzer—Analyzer<BranchesData, BranchesOptions>, kindbranches, scoperepo, needsforge.createBranchesAnalyzer({ now? })makes one with another clock. Options (branchesOptionsSchema):staleDays: number(--stale-days) — default 90: days without commits after which a branch is stale.ignore: string[](--ignore, comma-separated) — glob patterns of branch names never reported, e.g.release/*.includeProtected: boolean(--include-protected) — default false: judge protected branches too.
branchesAnalysis— theAnalysisKind(schema: branchesDataSchema,metrics: branchesMetrics,summarize,toReport(current, previous));branchesReport(data, { previous?, ref?, compareTo? })builds the report directly.branchesMetrics(data),branchesMetricsSchema,branchAuthors(data),BRANCHES_METRICS_LIMITS— see Metrics.analyzeBranches({ forge, repo, now, staleDays, ignore?, includeProtected?, log? }): Promise<BranchesData>— reads through the forge, then classifies. Throws when the forge has nolistBranches.classifyBranches(branches, mergeRequests, { defaultBranch, now, staleDays, ignore?, includeProtected? }): BranchesData— the pure classification.
How branches are judged
Section titled “How branches are judged”The forge’s listBranches gives every branch with its head commit; listMergeRequests (when the forge has it) gives the merge requests updated since the oldest branch commit. The default branch, ignore matches and protected branches (unless includeProtected) are never judged. A branch with an open merge request is in review and never a candidate. Of the rest, the first reason that holds wins:
- merged — the forge reports the head as reachable from the default branch, or the branch’s newest merged merge request points at the branch’s head (squash and rebase merges leave the head unreachable). When the merge request carries no head commit, it counts when it was merged at or after the branch’s last commit.
- closed — the branch’s newest merge request was closed without merging and the branch gained no commits since.
- stale — no commits for
staleDays.
Ages are whole days from the head commit’s date to the run. Without merge request reads only the first half of merged and stale apply.
The default branches-weekly schedule (@holtkeeper/managed-config) runs it on Tuesday nights.
interface BranchesData { defaultBranch: string staleDays: number checkedAt: string // ISO 8601, ages count up to it total: number // branches judged open: number // of them, with an open merge request candidates: { name: string reason: 'merged' | 'closed' | 'stale' committedAt: string ageDays: number author?: string // head commit author protected?: true webUrl?: string // http(s) only mergeRequest?: { id: number state: 'open' | 'merged' | 'closed' title: string author: string webUrl: string // http(s) only } }[] // merged, then closed, then stale; oldest first within each}Report
Section titled “Report”- Metrics — branches to clean up, merged not deleted, closed merge request, stale (all
better: 'down'; merged and closed are warnings above zero), branches judged. - To clean up — up to 200 candidates with why, last commit, age, author and merge request.
- By author — candidates per head commit author, split by reason, with the oldest age.
- Changes (with a previous analysis) — branches cleaned up and new candidates since then.
The web panel shows it in Quality › Branches (/quality/branches).
Metrics
Section titled “Metrics”branchesMetrics(data) is the kind’s metrics, stored with every record as BranchesMetrics: branches judged (total), those with an open merge request (open), branches to clean up (cleanup) and per reason (merged, closed, stale), oldestDays, the age of the oldest one to clean up, defaultBranch, staleDays, authors (per head commit author, as branchAuthors(data): cleanup, merged, closed, stale, oldestDays; most first, at most 50) and branches (the candidates oldest first, at most 20, with their merge request’s id, state, title and link; cleanup counts them all). BRANCHES_METRICS_LIMITS holds both caps.
branchesMetricsSchema parses stored metrics; fields added after a record was stored are absent from it. The server’s Quality › Branches (GET /api/branches) reads only these metrics: each repository’s newest record and its change against the run before it.