UNPKG

2.24 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.default = SEMVER;
14/** Given two labels determine the next SEMVER bump. */
15function getHigherSemverTag(left, right) {
16 if (left === SEMVER.major || right === SEMVER.major) {
17 return SEMVER.major;
18 }
19 if (left === SEMVER.minor || right === SEMVER.minor) {
20 return SEMVER.minor;
21 }
22 return SEMVER.patch;
23}
24exports.getHigherSemverTag = getHigherSemverTag;
25/**
26 * Determine the version bump from the labels on merged PRs.
27 * Respects skip-release labels and the "onlyPublishWithReleaseLabel"
28 * strategy.
29 */
30function calculateSemVerBump(labels, labelMap, { onlyPublishWithReleaseLabel } = {}) {
31 const labelSet = new Set();
32 const skipReleaseLabels = labelMap.get('skip') || [];
33 labels.forEach(pr => {
34 pr.forEach(label => {
35 const userLabel = [...labelMap.entries()].find(pair => pair[1].includes(label));
36 if (userLabel) {
37 labelSet.add(userLabel[0]);
38 }
39 });
40 });
41 let skipRelease = false;
42 if (labels.length > 0 && labels[0].length > 0) {
43 const releaseLabels = labelMap.get('release') || [];
44 skipRelease = onlyPublishWithReleaseLabel
45 ? !labels[0].some(label => releaseLabels.includes(label))
46 : labels[0].some(label => skipReleaseLabels.includes(label));
47 }
48 // If PRs only have none or skip labels, skip the release
49 const onlyNoReleaseLabels = [...labelSet].reduce((condition, releaseType) => condition && (releaseType === 'none' || releaseType === 'skip'), true);
50 if (labelSet.size > 0 && onlyNoReleaseLabels) {
51 return SEMVER.noVersion;
52 }
53 const version = [...labelSet].reduce(getHigherSemverTag, SEMVER.patch);
54 if (skipRelease) {
55 return SEMVER.noVersion;
56 }
57 return version;
58}
59exports.calculateSemVerBump = calculateSemVerBump;
60//# sourceMappingURL=semver.js.map
\No newline at end of file