UNPKG

2.55 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var SEMVER;
4(function (SEMVER) {
5 SEMVER["major"] = "major";
6 SEMVER["premajor"] = "premajor";
7 SEMVER["minor"] = "minor";
8 SEMVER["preminor"] = "preminor";
9 SEMVER["patch"] = "patch";
10 SEMVER["prepatch"] = "prepatch";
11 SEMVER["noVersion"] = "";
12})(SEMVER || (SEMVER = {}));
13exports.preVersionMap = new Map([
14 [SEMVER.major, SEMVER.premajor],
15 [SEMVER.minor, SEMVER.preminor],
16 [SEMVER.patch, SEMVER.prepatch],
17]);
18exports.default = SEMVER;
19/** Given two labels determine the next SEMVER bump. */
20function getHigherSemverTag(left, right) {
21 if (left === SEMVER.major || right === SEMVER.major) {
22 return SEMVER.major;
23 }
24 if (left === SEMVER.minor || right === SEMVER.minor) {
25 return SEMVER.minor;
26 }
27 return SEMVER.patch;
28}
29exports.getHigherSemverTag = getHigherSemverTag;
30/**
31 * Determine the version bump from the labels on merged PRs.
32 * Respects skip-release labels and the "onlyPublishWithReleaseLabel"
33 * strategy.
34 */
35function calculateSemVerBump(labels, labelMap, { onlyPublishWithReleaseLabel } = {}) {
36 const labelSet = new Set();
37 const skipReleaseLabels = labelMap.get("skip") || [];
38 labels.forEach((pr, index) => {
39 // If the head pr has no labels we default to a patch
40 if (pr.length === 0 && index === 0) {
41 labelSet.add(SEMVER.patch);
42 }
43 pr.forEach((label) => {
44 const userLabel = [...labelMap.entries()].find((pair) => pair[1].includes(label));
45 if (userLabel) {
46 labelSet.add(userLabel[0]);
47 }
48 });
49 });
50 const lastMergedCommitLabels = labels[0] || [];
51 const releaseLabels = labelMap.get("release") || [];
52 const skipRelease = onlyPublishWithReleaseLabel
53 ? !lastMergedCommitLabels.some((label) => releaseLabels.includes(label))
54 : lastMergedCommitLabels.some((label) => skipReleaseLabels.includes(label));
55 // If PRs only have none or skip labels, skip the release
56 const onlyNoReleaseLabels = [...labelSet].reduce((condition, releaseType) => condition && (releaseType === "none" || releaseType === "skip"), true);
57 if (labelSet.size > 0 && onlyNoReleaseLabels) {
58 return SEMVER.noVersion;
59 }
60 const version = [...labelSet].reduce(getHigherSemverTag, SEMVER.patch);
61 if (skipRelease) {
62 return SEMVER.noVersion;
63 }
64 return version;
65}
66exports.calculateSemVerBump = calculateSemVerBump;
67//# sourceMappingURL=semver.js.map
\No newline at end of file