1 | const {uniqBy, intersection} = require('lodash');
|
2 | const semver = require('semver');
|
3 | const semverDiff = require('semver-diff');
|
4 | const getLastRelease = require('./get-last-release');
|
5 | const {makeTag, getLowerBound} = require('./utils');
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = (context) => {
|
15 | const {
|
16 | branch,
|
17 | branches,
|
18 | options: {tagFormat},
|
19 | } = context;
|
20 |
|
21 | const higherChannels = branches
|
22 |
|
23 | .slice(branches.findIndex(({name}) => name === branch.name) + 1)
|
24 |
|
25 | .filter(({type}) => type !== 'prerelease')
|
26 | .map(({channel}) => channel || null);
|
27 |
|
28 | const versiontoAdd = uniqBy(
|
29 | branch.tags.filter(
|
30 | ({channels, version}) =>
|
31 | !channels.includes(branch.channel || null) &&
|
32 | intersection(channels, higherChannels).length > 0 &&
|
33 | (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange)))
|
34 | ),
|
35 | 'version'
|
36 | ).sort((a, b) => semver.compare(b.version, a.version))[0];
|
37 |
|
38 | if (versiontoAdd) {
|
39 | const {version, gitTag, channels} = versiontoAdd;
|
40 | const lastRelease = getLastRelease(context, {before: version});
|
41 | if (semver.gt(getLastRelease(context).version, version)) {
|
42 | return;
|
43 | }
|
44 |
|
45 | const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major';
|
46 | const name = makeTag(tagFormat, version);
|
47 | return {
|
48 | lastRelease,
|
49 | currentRelease: {type, version, channels, gitTag, name, gitHead: gitTag},
|
50 | nextRelease: {
|
51 | type,
|
52 | version,
|
53 | channel: branch.channel || null,
|
54 | gitTag: makeTag(tagFormat, version),
|
55 | name,
|
56 | gitHead: gitTag,
|
57 | },
|
58 | };
|
59 | }
|
60 | };
|