-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectVersionBump.ts
More file actions
44 lines (37 loc) · 1.13 KB
/
detectVersionBump.ts
File metadata and controls
44 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { classifyChange } from "./classifyChange.js";
import type { SpecChangeSet } from "./diffChangeSet.js";
export type VersionBump = "major" | "minor" | "patch" | "none";
export type VersionBumpResult = {
recommendedBump: VersionBump;
isBreaking: boolean;
reasons: string[];
};
export function detectVersionBump<K>(
changeSet: SpecChangeSet<K>,
): VersionBumpResult {
if (changeSet.changes.length === 0) {
return {
recommendedBump: "none",
isBreaking: false,
reasons: [],
};
}
const reasons: string[] = [];
let maxBump: VersionBump = "none";
for (const change of changeSet.changes) {
const bump = classifyChange(change);
if (bump.level === "major") {
maxBump = "major";
} else if (bump.level === "minor" && maxBump !== "major") {
maxBump = "minor";
} else if (bump.level === "patch" && maxBump === "none") {
maxBump = "patch";
}
reasons.push(bump.reason);
}
return {
recommendedBump: maxBump,
isBreaking: maxBump === "major",
reasons,
};
}