Skip to content
Source
Sign inSign up
Open History to see the last commit

pullRequestChangeBreakdown.ts

21 lines755 Bytes

1import type { PullRequestChangeBreakdown } from "@t3tools/contracts";
2import { classifyChangedFile } from "@t3tools/shared/changedFileKind";
3import type { ProviderFileStats } from "@t3tools/source-control-core/server/PullRequestProvider";
4​
5export function toChangeBreakdown(stats: ProviderFileStats): PullRequestChangeBreakdown {
6 if (stats.truncated) return null;
7 const empty = () => ({ additions: 0, deletions: 0 });
8 const breakdown = {
9 code: empty(),
10 tests: empty(),
11 mocks: empty(),
12 generated: empty(),
13 docs: empty(),
14 };
15 for (const file of stats.files) {
16 const bucket = breakdown[classifyChangedFile(file.path)];
17 bucket.additions += file.additions;
18 bucket.deletions += file.deletions;
19 }
20 return breakdown;