1 | const {isString, remove, omit, mapValues, template} = require('lodash');
|
2 | const micromatch = require('micromatch');
|
3 | const {getBranches} = require('../git');
|
4 |
|
5 | module.exports = async (repositoryUrl, {cwd}, branches) => {
|
6 | const gitBranches = await getBranches(repositoryUrl, {cwd});
|
7 |
|
8 | return branches.reduce(
|
9 | (branches, branch) => [
|
10 | ...branches,
|
11 | ...remove(gitBranches, (name) => micromatch(gitBranches, branch.name).includes(name)).map((name) => ({
|
12 | name,
|
13 | ...mapValues(omit(branch, 'name'), (value) => (isString(value) ? template(value)({name}) : value)),
|
14 | })),
|
15 | ],
|
16 | []
|
17 | );
|
18 | };
|