1 | const {template, escapeRegExp} = require('lodash');
|
2 | const semver = require('semver');
|
3 | const pReduce = require('p-reduce');
|
4 | const debug = require('debug')('semantic-release:get-tags');
|
5 | const {getTags, getNote} = require('../../lib/git');
|
6 |
|
7 | module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`;
|
13 |
|
14 | return pReduce(
|
15 | branches,
|
16 | async (branches, branch) => {
|
17 | const branchTags = await pReduce(
|
18 | await getTags(branch.name, {cwd, env}),
|
19 | async (branchTags, tag) => {
|
20 | const [, version] = tag.match(tagRegexp) || [];
|
21 | return version && semver.valid(semver.clean(version))
|
22 | ? [...branchTags, {gitTag: tag, version, channels: (await getNote(tag, {cwd, env})).channels || [null]}]
|
23 | : branchTags;
|
24 | },
|
25 | []
|
26 | );
|
27 |
|
28 | debug('found tags for branch %s: %o', branch.name, branchTags);
|
29 | return [...branches, {...branch, tags: branchTags}];
|
30 | },
|
31 | []
|
32 | );
|
33 | };
|