chore(package): update xo to version 0.28.1

Closes #1488
This commit is contained in:
greenkeeper[bot] 2020-03-26 12:27:57 +00:00 committed by Pierre Vanduynslager
parent b5488ae7a5
commit f899fa9a7c
14 changed files with 120 additions and 112 deletions

6
cli.js
View File

@ -41,18 +41,18 @@ Usage:
.exitProcess(false); .exitProcess(false);
try { try {
const {help, version, ...opts} = cli.parse(argv.slice(2)); const {help, version, ...options} = cli.parse(argv.slice(2));
if (Boolean(help) || Boolean(version)) { if (Boolean(help) || Boolean(version)) {
return 0; return 0;
} }
if (opts.debug) { if (options.debug) {
// Debug must be enabled before other requires in order to work // Debug must be enabled before other requires in order to work
require('debug').enable('semantic-release:*'); require('debug').enable('semantic-release:*');
} }
await require('.')(opts); await require('.')(options);
return 0; return 0;
} catch (error) { } catch (error) {
if (error.name !== 'YError') { if (error.name !== 'YError') {

View File

@ -238,7 +238,7 @@ async function callFail(context, plugins, err) {
} }
} }
module.exports = async (opts = {}, {cwd = process.cwd(), env = process.env, stdout, stderr} = {}) => { module.exports = async (cliOptions = {}, {cwd = process.cwd(), env = process.env, stdout, stderr} = {}) => {
const {unhook} = hookStd( const {unhook} = hookStd(
{silent: false, streams: [process.stdout, process.stderr, stdout, stderr].filter(Boolean)}, {silent: false, streams: [process.stdout, process.stderr, stdout, stderr].filter(Boolean)},
hideSensitive(env) hideSensitive(env)
@ -253,7 +253,7 @@ module.exports = async (opts = {}, {cwd = process.cwd(), env = process.env, stdo
context.logger = getLogger(context); context.logger = getLogger(context);
context.logger.log(`Running ${pkg.name} version ${pkg.version}`); context.logger.log(`Running ${pkg.name} version ${pkg.version}`);
try { try {
const {plugins, options} = await getConfig(context, opts); const {plugins, options} = await getConfig(context, cliOptions);
context.options = options; context.options = options;
try { try {
const result = await run(context, plugins); const result = await run(context, plugins);

View File

@ -50,7 +50,7 @@ module.exports = async (repositoryUrl, ciBranch, context) => {
const duplicates = [...branches] const duplicates = [...branches]
.map(branch => branch.name) .map(branch => branch.name)
.sort() .sort()
.filter((_, idx, arr) => arr[idx] === arr[idx + 1] && arr[idx] !== arr[idx - 1]); .filter((_, idx, array) => array[idx] === array[idx + 1] && array[idx] !== array[idx - 1]);
if (duplicates.length > 0) { if (duplicates.length > 0) {
errors.push(getError('EDUPLICATEBRANCHES', {duplicates})); errors.push(getError('EDUPLICATEBRANCHES', {duplicates}));

View File

@ -4,7 +4,8 @@ const pkg = require('../../package.json');
const {RELEASE_TYPE} = require('./constants'); const {RELEASE_TYPE} = require('./constants');
const [homepage] = pkg.homepage.split('#'); const [homepage] = pkg.homepage.split('#');
const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5})); const stringify = object =>
isString(object) ? object : inspect(object, {breakLength: Infinity, depth: 2, maxArrayLength: 5});
const linkify = file => `${homepage}/blob/master/${file}`; const linkify = file => `${homepage}/blob/master/${file}`;
const wordsList = words => const wordsList = words =>
`${words.slice(0, -1).join(', ')}${words.length > 1 ? ` or ${words[words.length - 1]}` : trim(words[0])}`; `${words.slice(0, -1).join(', ')}${words.length > 1 ? ` or ${words[words.length - 1]}` : trim(words[0])}`;

View File

@ -19,7 +19,7 @@ module.exports = {
outputValidator: output => !output || RELEASE_TYPE.includes(output), outputValidator: output => !output || RELEASE_TYPE.includes(output),
preprocess: ({commits, ...inputs}) => ({ preprocess: ({commits, ...inputs}) => ({
...inputs, ...inputs,
commits: commits.filter(commit => !/\[skip\s+release\]|\[release\s+skip\]/i.test(commit.message)), commits: commits.filter(commit => !/\[skip\s+release]|\[release\s+skip]/i.test(commit.message)),
}), }),
postprocess: results => postprocess: results =>
RELEASE_TYPE[ RELEASE_TYPE[

View File

@ -19,14 +19,14 @@ const CONFIG_FILES = [
`${CONFIG_NAME}.config.js`, `${CONFIG_NAME}.config.js`,
]; ];
module.exports = async (context, opts) => { module.exports = async (context, cliOptions) => {
const {cwd, env} = context; const {cwd, env} = context;
const {config, filepath} = (await cosmiconfig(CONFIG_NAME, {searchPlaces: CONFIG_FILES}).search(cwd)) || {}; const {config, filepath} = (await cosmiconfig(CONFIG_NAME, {searchPlaces: CONFIG_FILES}).search(cwd)) || {};
debug('load config from: %s', filepath); debug('load config from: %s', filepath);
// Merge config file options and CLI/API options // Merge config file options and CLI/API options
let options = {...config, ...opts}; let options = {...config, ...cliOptions};
if (options.ci === false) { if (options.ci === false) {
options.noCi = true; options.noCi = true;
} }
@ -38,11 +38,11 @@ module.exports = async (context, opts) => {
// If `extends` is defined, load and merge each shareable config with `options` // If `extends` is defined, load and merge each shareable config with `options`
options = { options = {
...castArray(extendPaths).reduce((result, extendPath) => { ...castArray(extendPaths).reduce((result, extendPath) => {
const extendsOpts = require(resolveFrom.silent(__dirname, extendPath) || resolveFrom(cwd, extendPath)); const extendsOptions = require(resolveFrom.silent(__dirname, extendPath) || resolveFrom(cwd, extendPath));
// For each plugin defined in a shareable config, save in `pluginsPath` the extendable config path, // For each plugin defined in a shareable config, save in `pluginsPath` the extendable config path,
// so those plugin will be loaded relatively to the config file // so those plugin will be loaded relatively to the config file
Object.entries(extendsOpts) Object.entries(extendsOptions)
.filter(([, value]) => Boolean(value)) .filter(([, value]) => Boolean(value))
.reduce((pluginsPath, [option, value]) => { .reduce((pluginsPath, [option, value]) => {
castArray(value).forEach(plugin => { castArray(value).forEach(plugin => {
@ -58,7 +58,7 @@ module.exports = async (context, opts) => {
return pluginsPath; return pluginsPath;
}, pluginsPath); }, pluginsPath);
return {...result, ...extendsOpts}; return {...result, ...extendsOptions};
}, {}), }, {}),
...options, ...options,
}; };
@ -92,7 +92,7 @@ module.exports = async (context, opts) => {
return {options, plugins: await plugins({...context, options}, pluginsPath)}; return {options, plugins: await plugins({...context, options}, pluginsPath)};
}; };
async function pkgRepoUrl(opts) { async function pkgRepoUrl(options) {
const {packageJson} = (await readPkgUp(opts)) || {}; const {packageJson} = (await readPkgUp(options)) || {};
return packageJson && (isPlainObject(packageJson.repository) ? packageJson.repository.url : packageJson.repository); return packageJson && (isPlainObject(packageJson.repository) ? packageJson.repository.url : packageJson.repository);
} }

View File

@ -14,8 +14,8 @@ Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', commi
* *
* @return {String} The commit sha of the tag in parameter or `null`. * @return {String} The commit sha of the tag in parameter or `null`.
*/ */
async function getTagHead(tagName, execaOpts) { async function getTagHead(tagName, execaOptions) {
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout; return (await execa('git', ['rev-list', '-1', tagName], execaOptions)).stdout;
} }
/** /**
@ -27,8 +27,8 @@ async function getTagHead(tagName, execaOpts) {
* @return {Array<String>} List of git tags. * @return {Array<String>} List of git tags.
* @throws {Error} If the `git` command fails. * @throws {Error} If the `git` command fails.
*/ */
async function getTags(branch, execaOpts) { async function getTags(branch, execaOptions) {
return (await execa('git', ['tag', '--merged', branch], execaOpts)).stdout return (await execa('git', ['tag', '--merged', branch], execaOptions)).stdout
.split('\n') .split('\n')
.map(tag => tag.trim()) .map(tag => tag.trim())
.filter(Boolean); .filter(Boolean);
@ -42,12 +42,12 @@ async function getTags(branch, execaOpts) {
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
* @return {Promise<Array<Object>>} The list of commits between `from` and `to`. * @return {Promise<Array<Object>>} The list of commits between `from` and `to`.
*/ */
async function getCommits(from, to, execaOpts) { async function getCommits(from, to, execaOptions) {
return ( return (
await getStream.array( await getStream.array(
gitLogParser.parse( gitLogParser.parse(
{_: `${from ? from + '..' : ''}${to}`}, {_: `${from ? from + '..' : ''}${to}`},
{cwd: execaOpts.cwd, env: {...process.env, ...execaOpts.env}} {cwd: execaOptions.cwd, env: {...process.env, ...execaOptions.env}}
) )
) )
).map(({message, gitTags, ...commit}) => ({...commit, message: message.trim(), gitTags: gitTags.trim()})); ).map(({message, gitTags, ...commit}) => ({...commit, message: message.trim(), gitTags: gitTags.trim()}));
@ -62,8 +62,8 @@ async function getCommits(from, to, execaOpts) {
* @return {Array<String>} List of git branches. * @return {Array<String>} List of git branches.
* @throws {Error} If the `git` command fails. * @throws {Error} If the `git` command fails.
*/ */
async function getBranches(repositoryUrl, execaOpts) { async function getBranches(repositoryUrl, execaOptions) {
return (await execa('git', ['ls-remote', '--heads', repositoryUrl], execaOpts)).stdout return (await execa('git', ['ls-remote', '--heads', repositoryUrl], execaOptions)).stdout
.split('\n') .split('\n')
.filter(Boolean) .filter(Boolean)
.map(branch => branch.match(/^.+refs\/heads\/(?<branch>.+)$/)[1]); .map(branch => branch.match(/^.+refs\/heads\/(?<branch>.+)$/)[1]);
@ -77,9 +77,9 @@ async function getBranches(repositoryUrl, execaOpts) {
* *
* @return {Boolean} `true` if the reference exists, falsy otherwise. * @return {Boolean} `true` if the reference exists, falsy otherwise.
*/ */
async function isRefExists(ref, execaOpts) { async function isRefExists(ref, execaOptions) {
try { try {
return (await execa('git', ['rev-parse', '--verify', ref], execaOpts)).exitCode === 0; return (await execa('git', ['rev-parse', '--verify', ref], execaOptions)).exitCode === 0;
} catch (error) { } catch (error) {
debug(error); debug(error);
} }
@ -99,9 +99,9 @@ async function isRefExists(ref, execaOpts) {
* @param {String} branch The repository branch to fetch. * @param {String} branch The repository branch to fetch.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function fetch(repositoryUrl, branch, ciBranch, execaOpts) { async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
const isDetachedHead = const isDetachedHead =
(await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {...execaOpts, reject: false})).stdout === 'HEAD'; (await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {...execaOptions, reject: false})).stdout === 'HEAD';
try { try {
await execa( await execa(
@ -114,7 +114,7 @@ async function fetch(repositoryUrl, branch, ciBranch, execaOpts) {
? [repositoryUrl] ? [repositoryUrl]
: ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), : ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
], ],
execaOpts execaOptions
); );
} catch (_) { } catch (_) {
await execa( await execa(
@ -126,7 +126,7 @@ async function fetch(repositoryUrl, branch, ciBranch, execaOpts) {
? [repositoryUrl] ? [repositoryUrl]
: ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]), : ['--update-head-ok', repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
], ],
execaOpts execaOptions
); );
} }
} }
@ -137,16 +137,16 @@ async function fetch(repositoryUrl, branch, ciBranch, execaOpts) {
* @param {String} repositoryUrl The remote repository URL. * @param {String} repositoryUrl The remote repository URL.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function fetchNotes(repositoryUrl, execaOpts) { async function fetchNotes(repositoryUrl, execaOptions) {
try { try {
await execa( await execa(
'git', 'git',
['fetch', '--unshallow', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`], ['fetch', '--unshallow', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`],
execaOpts execaOptions
); );
} catch (_) { } catch (_) {
await execa('git', ['fetch', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`], { await execa('git', ['fetch', repositoryUrl, `+refs/notes/${GIT_NOTE_REF}:refs/notes/${GIT_NOTE_REF}`], {
...execaOpts, ...execaOptions,
reject: false, reject: false,
}); });
} }
@ -159,8 +159,8 @@ async function fetchNotes(repositoryUrl, execaOpts) {
* *
* @return {String} the sha of the HEAD commit. * @return {String} the sha of the HEAD commit.
*/ */
async function getGitHead(execaOpts) { async function getGitHead(execaOptions) {
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout; return (await execa('git', ['rev-parse', 'HEAD'], execaOptions)).stdout;
} }
/** /**
@ -170,9 +170,9 @@ async function getGitHead(execaOpts) {
* *
* @return {string} The value of the remote git URL. * @return {string} The value of the remote git URL.
*/ */
async function repoUrl(execaOpts) { async function repoUrl(execaOptions) {
try { try {
return (await execa('git', ['config', '--get', 'remote.origin.url'], execaOpts)).stdout; return (await execa('git', ['config', '--get', 'remote.origin.url'], execaOptions)).stdout;
} catch (error) { } catch (error) {
debug(error); debug(error);
} }
@ -185,9 +185,9 @@ async function repoUrl(execaOpts) {
* *
* @return {Boolean} `true` if the current working directory is in a git repository, falsy otherwise. * @return {Boolean} `true` if the current working directory is in a git repository, falsy otherwise.
*/ */
async function isGitRepo(execaOpts) { async function isGitRepo(execaOptions) {
try { try {
return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).exitCode === 0; return (await execa('git', ['rev-parse', '--git-dir'], execaOptions)).exitCode === 0;
} catch (error) { } catch (error) {
debug(error); debug(error);
} }
@ -202,9 +202,9 @@ async function isGitRepo(execaOpts) {
* *
* @throws {Error} if not authorized to push. * @throws {Error} if not authorized to push.
*/ */
async function verifyAuth(repositoryUrl, branch, execaOpts) { async function verifyAuth(repositoryUrl, branch, execaOptions) {
try { try {
await execa('git', ['push', '--dry-run', '--no-verify', repositoryUrl, `HEAD:${branch}`], execaOpts); await execa('git', ['push', '--dry-run', '--no-verify', repositoryUrl, `HEAD:${branch}`], execaOptions);
} catch (error) { } catch (error) {
debug(error); debug(error);
throw error; throw error;
@ -220,8 +220,8 @@ async function verifyAuth(repositoryUrl, branch, execaOpts) {
* *
* @throws {Error} if the tag creation failed. * @throws {Error} if the tag creation failed.
*/ */
async function tag(tagName, ref, execaOpts) { async function tag(tagName, ref, execaOptions) {
await execa('git', ['tag', tagName, ref], execaOpts); await execa('git', ['tag', tagName, ref], execaOptions);
} }
/** /**
@ -232,8 +232,8 @@ async function tag(tagName, ref, execaOpts) {
* *
* @throws {Error} if the push failed. * @throws {Error} if the push failed.
*/ */
async function push(repositoryUrl, execaOpts) { async function push(repositoryUrl, execaOptions) {
await execa('git', ['push', '--tags', repositoryUrl], execaOpts); await execa('git', ['push', '--tags', repositoryUrl], execaOptions);
} }
/** /**
@ -244,8 +244,8 @@ async function push(repositoryUrl, execaOpts) {
* *
* @throws {Error} if the push failed. * @throws {Error} if the push failed.
*/ */
async function pushNotes(repositoryUrl, execaOpts) { async function pushNotes(repositoryUrl, execaOptions) {
await execa('git', ['push', repositoryUrl, `refs/notes/${GIT_NOTE_REF}`], execaOpts); await execa('git', ['push', repositoryUrl, `refs/notes/${GIT_NOTE_REF}`], execaOptions);
} }
/** /**
@ -256,9 +256,9 @@ async function pushNotes(repositoryUrl, execaOpts) {
* *
* @return {Boolean} `true` if valid, falsy otherwise. * @return {Boolean} `true` if valid, falsy otherwise.
*/ */
async function verifyTagName(tagName, execaOpts) { async function verifyTagName(tagName, execaOptions) {
try { try {
return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOpts)).exitCode === 0; return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOptions)).exitCode === 0;
} catch (error) { } catch (error) {
debug(error); debug(error);
} }
@ -272,9 +272,9 @@ async function verifyTagName(tagName, execaOpts) {
* *
* @return {Boolean} `true` if valid, falsy otherwise. * @return {Boolean} `true` if valid, falsy otherwise.
*/ */
async function verifyBranchName(branch, execaOpts) { async function verifyBranchName(branch, execaOptions) {
try { try {
return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOpts)).exitCode === 0; return (await execa('git', ['check-ref-format', `refs/heads/${branch}`], execaOptions)).exitCode === 0;
} catch (error) { } catch (error) {
debug(error); debug(error);
} }
@ -289,10 +289,10 @@ async function verifyBranchName(branch, execaOpts) {
* *
* @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise. * @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
*/ */
async function isBranchUpToDate(repositoryUrl, branch, execaOpts) { async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
return ( return (
(await getGitHead(execaOpts)) === (await getGitHead(execaOptions)) ===
(await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts)).stdout.match(/^(?<ref>\w+)?/)[1] (await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOptions)).stdout.match(/^(?<ref>\w+)?/)[1]
); );
} }
@ -304,9 +304,9 @@ async function isBranchUpToDate(repositoryUrl, branch, execaOpts) {
* *
* @return {Object} the parsed JSON note if there is one, an empty object otherwise. * @return {Object} the parsed JSON note if there is one, an empty object otherwise.
*/ */
async function getNote(ref, execaOpts) { async function getNote(ref, execaOptions) {
try { try {
return JSON.parse((await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOpts)).stdout); return JSON.parse((await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOptions)).stdout);
} catch (error) { } catch (error) {
if (error.exitCode === 1) { if (error.exitCode === 1) {
return {}; return {};
@ -324,8 +324,8 @@ async function getNote(ref, execaOpts) {
* @param {String} ref The Git reference to add the note to. * @param {String} ref The Git reference to add the note to.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function addNote(note, ref, execaOpts) { async function addNote(note, ref, execaOptions) {
await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-f', '-m', JSON.stringify(note), ref], execaOpts); await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-f', '-m', JSON.stringify(note), ref], execaOptions);
} }
module.exports = { module.exports = {

View File

@ -46,10 +46,10 @@ module.exports = (context, pluginsPath) => {
const pluginsConf = Object.entries(PLUGINS_DEFINITIONS).reduce( const pluginsConf = Object.entries(PLUGINS_DEFINITIONS).reduce(
(pluginsConf, [type, {required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]) => { (pluginsConf, [type, {required, default: def, pipelineConfig, postprocess = identity, preprocess = identity}]) => {
let pluginOpts; let pluginOptions;
if (isNil(options[type]) && def) { if (isNil(options[type]) && def) {
pluginOpts = def; pluginOptions = def;
} else { } else {
// If an object is passed and the path is missing, merge it with step options // If an object is passed and the path is missing, merge it with step options
if (isPlainObject(options[type]) && !options[type].path) { if (isPlainObject(options[type]) && !options[type].path) {
@ -63,10 +63,10 @@ module.exports = (context, pluginsPath) => {
return pluginsConf; return pluginsConf;
} }
pluginOpts = options[type]; pluginOptions = options[type];
} }
const steps = castArray(pluginOpts).map(pluginOpt => const steps = castArray(pluginOptions).map(pluginOpt =>
normalize( normalize(
{...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), 'plugins')}, {...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), 'plugins')},
type, type,

View File

@ -8,13 +8,13 @@ function extractErrors(err) {
function hideSensitiveValues(env, objs) { function hideSensitiveValues(env, objs) {
const hideFunction = hideSensitive(env); const hideFunction = hideSensitive(env);
return objs.map(obj => { return objs.map(object => {
Object.getOwnPropertyNames(obj).forEach(prop => { Object.getOwnPropertyNames(object).forEach(prop => {
if (obj[prop]) { if (object[prop]) {
obj[prop] = hideFunction(obj[prop]); object[prop] = hideFunction(object[prop]);
} }
}); });
return obj; return object;
}); });
} }

View File

@ -67,7 +67,7 @@
"sinon": "^9.0.0", "sinon": "^9.0.0",
"stream-buffers": "^3.0.2", "stream-buffers": "^3.0.2",
"tempy": "^0.5.0", "tempy": "^0.5.0",
"xo": "^0.27.0" "xo": "^0.28.1"
}, },
"engines": { "engines": {
"node": ">=10.18" "node": ">=10.18"
@ -126,6 +126,9 @@
}, },
"xo": { "xo": {
"prettier": true, "prettier": true,
"space": true "space": true,
"rules": {
"unicorn/string-content": "off"
}
} }
} }

View File

@ -7,11 +7,11 @@ const {SECRET_REPLACEMENT} = require('../lib/definitions/constants');
test.beforeEach(t => { test.beforeEach(t => {
t.context.logs = ''; t.context.logs = '';
t.context.errors = ''; t.context.errors = '';
t.context.stdout = stub(process.stdout, 'write').callsFake(val => { t.context.stdout = stub(process.stdout, 'write').callsFake(value => {
t.context.logs += val.toString(); t.context.logs += value.toString();
}); });
t.context.stderr = stub(process.stderr, 'write').callsFake(val => { t.context.stderr = stub(process.stderr, 'write').callsFake(value => {
t.context.errors += val.toString(); t.context.errors += value.toString();
}); });
}); });

View File

@ -250,9 +250,9 @@ test('Push tag to remote repository with remote branch ahead', async t => {
const {cwd, repositoryUrl} = await gitRepo(true); const {cwd, repositoryUrl} = await gitRepo(true);
const commits = await gitCommits(['First'], {cwd}); const commits = await gitCommits(['First'], {cwd});
await gitPush(repositoryUrl, 'master', {cwd}); await gitPush(repositoryUrl, 'master', {cwd});
const tmpRepo = await gitShallowClone(repositoryUrl); const temporaryRepo = await gitShallowClone(repositoryUrl);
await gitCommits(['Second'], {cwd: tmpRepo}); await gitCommits(['Second'], {cwd: temporaryRepo});
await gitPush('origin', 'master', {cwd: tmpRepo}); await gitPush('origin', 'master', {cwd: temporaryRepo});
await tag('tag_name', 'HEAD', {cwd}); await tag('tag_name', 'HEAD', {cwd});
await push(repositoryUrl, {cwd}); await push(repositoryUrl, {cwd});
@ -309,9 +309,9 @@ test('Return falsy if repository is not up to date', async t => {
t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd}));
const tmpRepo = await gitShallowClone(repositoryUrl); const temporaryRepo = await gitShallowClone(repositoryUrl);
await gitCommits(['Third'], {cwd: tmpRepo}); await gitCommits(['Third'], {cwd: temporaryRepo});
await gitPush('origin', 'master', {cwd: tmpRepo}); await gitPush('origin', 'master', {cwd: temporaryRepo});
t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd}));
}); });

View File

@ -82,12 +82,13 @@ async function initBareRepo(repositoryUrl, branch = 'master') {
* *
* @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order). * @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order).
*/ */
async function gitCommits(messages, execaOpts) { async function gitCommits(messages, execaOptions) {
await pEachSeries( await pEachSeries(
messages, messages,
async message => (await execa('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)).stdout async message =>
(await execa('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOptions)).stdout
); );
return (await gitGetCommits(undefined, execaOpts)).slice(0, messages.length); return (await gitGetCommits(undefined, execaOptions)).slice(0, messages.length);
} }
/** /**
@ -98,11 +99,14 @@ async function gitCommits(messages, execaOpts) {
* *
* @return {Array<Object>} The list of parsed commits. * @return {Array<Object>} The list of parsed commits.
*/ */
async function gitGetCommits(from, execaOpts) { async function gitGetCommits(from, execaOptions) {
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}}); Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
return ( return (
await getStream.array( await getStream.array(
gitLogParser.parse({_: `${from ? from + '..' : ''}HEAD`}, {...execaOpts, env: {...process.env, ...execaOpts.env}}) gitLogParser.parse(
{_: `${from ? from + '..' : ''}HEAD`},
{...execaOptions, env: {...process.env, ...execaOptions.env}}
)
) )
).map(commit => { ).map(commit => {
commit.message = commit.message.trim(); commit.message = commit.message.trim();
@ -118,8 +122,8 @@ async function gitGetCommits(from, execaOpts) {
* @param {Boolean} create to create the branch, `false` to checkout an existing branch. * @param {Boolean} create to create the branch, `false` to checkout an existing branch.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function gitCheckout(branch, create, execaOpts) { async function gitCheckout(branch, create, execaOptions) {
await execa('git', create ? ['checkout', '-b', branch] : ['checkout', branch], execaOpts); await execa('git', create ? ['checkout', '-b', branch] : ['checkout', branch], execaOptions);
} }
/** /**
@ -128,8 +132,8 @@ async function gitCheckout(branch, create, execaOpts) {
* @param {String} repositoryUrl The repository remote URL. * @param {String} repositoryUrl The repository remote URL.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function gitFetch(repositoryUrl, execaOpts) { async function gitFetch(repositoryUrl, execaOptions) {
await execa('git', ['fetch', repositoryUrl], execaOpts); await execa('git', ['fetch', repositoryUrl], execaOptions);
} }
/** /**
@ -139,8 +143,8 @@ async function gitFetch(repositoryUrl, execaOpts) {
* *
* @return {String} The sha of the head commit in the current git repository. * @return {String} The sha of the head commit in the current git repository.
*/ */
async function gitHead(execaOpts) { async function gitHead(execaOptions) {
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout; return (await execa('git', ['rev-parse', 'HEAD'], execaOptions)).stdout;
} }
/** /**
@ -150,8 +154,8 @@ async function gitHead(execaOpts) {
* @param {String} [sha] The commit on which to create the tag. If undefined the tag is created on the last commit. * @param {String} [sha] The commit on which to create the tag. If undefined the tag is created on the last commit.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function gitTagVersion(tagName, sha, execaOpts) { async function gitTagVersion(tagName, sha, execaOptions) {
await execa('git', sha ? ['tag', '-f', tagName, sha] : ['tag', tagName], execaOpts); await execa('git', sha ? ['tag', '-f', tagName, sha] : ['tag', tagName], execaOptions);
} }
/** /**
@ -207,8 +211,8 @@ async function gitDetachedHeadFromBranch(repositoryUrl, branch, head) {
* @param {String} value Config value. * @param {String} value Config value.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function gitAddConfig(name, value, execaOpts) { async function gitAddConfig(name, value, execaOptions) {
await execa('git', ['config', '--add', name, value], execaOpts); await execa('git', ['config', '--add', name, value], execaOptions);
} }
/** /**
@ -219,8 +223,8 @@ async function gitAddConfig(name, value, execaOpts) {
* *
* @return {String} The sha of the commit associated with `tagName` on the local repository. * @return {String} The sha of the commit associated with `tagName` on the local repository.
*/ */
async function gitTagHead(tagName, execaOpts) { async function gitTagHead(tagName, execaOptions) {
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout; return (await execa('git', ['rev-list', '-1', tagName], execaOptions)).stdout;
} }
/** /**
@ -232,8 +236,8 @@ async function gitTagHead(tagName, execaOpts) {
* *
* @return {String} The sha of the commit associated with `tagName` on the remote repository. * @return {String} The sha of the commit associated with `tagName` on the remote repository.
*/ */
async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) { async function gitRemoteTagHead(repositoryUrl, tagName, execaOptions) {
return (await execa('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)).stdout return (await execa('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOptions)).stdout
.split('\n') .split('\n')
.filter(tag => Boolean(tag)) .filter(tag => Boolean(tag))
.map(tag => tag.match(/^(?<tag>\S+)/)[1])[0]; .map(tag => tag.match(/^(?<tag>\S+)/)[1])[0];
@ -247,8 +251,8 @@ async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) {
* *
* @return {String} The tag associatedwith the sha in parameter or `null`. * @return {String} The tag associatedwith the sha in parameter or `null`.
*/ */
async function gitCommitTag(gitHead, execaOpts) { async function gitCommitTag(gitHead, execaOptions) {
return (await execa('git', ['describe', '--tags', '--exact-match', gitHead], execaOpts)).stdout; return (await execa('git', ['describe', '--tags', '--exact-match', gitHead], execaOptions)).stdout;
} }
/** /**
@ -260,8 +264,8 @@ async function gitCommitTag(gitHead, execaOpts) {
* *
* @throws {Error} if the push failed. * @throws {Error} if the push failed.
*/ */
async function gitPush(repositoryUrl, branch, execaOpts) { async function gitPush(repositoryUrl, branch, execaOptions) {
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOpts); await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOptions);
} }
/** /**
@ -270,8 +274,8 @@ async function gitPush(repositoryUrl, branch, execaOpts) {
* @param {String} ref The ref to merge. * @param {String} ref The ref to merge.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function merge(ref, execaOpts) { async function merge(ref, execaOptions) {
await execa('git', ['merge', '--no-ff', ref], execaOpts); await execa('git', ['merge', '--no-ff', ref], execaOptions);
} }
/** /**
@ -280,8 +284,8 @@ async function merge(ref, execaOpts) {
* @param {String} ref The ref to merge. * @param {String} ref The ref to merge.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function mergeFf(ref, execaOpts) { async function mergeFf(ref, execaOptions) {
await execa('git', ['merge', '--ff', ref], execaOpts); await execa('git', ['merge', '--ff', ref], execaOptions);
} }
/** /**
@ -290,8 +294,8 @@ async function mergeFf(ref, execaOpts) {
* @param {String} ref The ref to merge. * @param {String} ref The ref to merge.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function rebase(ref, execaOpts) { async function rebase(ref, execaOptions) {
await execa('git', ['rebase', ref], execaOpts); await execa('git', ['rebase', ref], execaOptions);
} }
/** /**
@ -301,8 +305,8 @@ async function rebase(ref, execaOpts) {
* @param {String} ref The ref to add the note to. * @param {String} ref The ref to add the note to.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function gitAddNote(note, ref, execaOpts) { async function gitAddNote(note, ref, execaOptions) {
await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-m', note, ref], execaOpts); await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'add', '-m', note, ref], execaOptions);
} }
/** /**
@ -311,8 +315,8 @@ async function gitAddNote(note, ref, execaOpts) {
* @param {String} ref The ref to get the note from. * @param {String} ref The ref to get the note from.
* @param {Object} [execaOpts] Options to pass to `execa`. * @param {Object} [execaOpts] Options to pass to `execa`.
*/ */
async function gitGetNote(ref, execaOpts) { async function gitGetNote(ref, execaOptions) {
return (await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOpts)).stdout; return (await execa('git', ['notes', '--ref', GIT_NOTE_REF, 'show', ref], execaOptions)).stdout;
} }
module.exports = { module.exports = {

View File

@ -161,7 +161,7 @@ test('Execute each function in series passing a transformed input even if a step
const step2 = stub().rejects(error2); const step2 = stub().rejects(error2);
const step3 = stub().rejects(error3); const step3 = stub().rejects(error3);
const step4 = stub().resolves(4); const step4 = stub().resolves(4);
const getNextInput = (prevResult, result) => prevResult + result; const getNextInput = (previousResult, result) => previousResult + result;
const errors = await t.throwsAsync(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0)); const errors = await t.throwsAsync(pipeline([step1, step2, step3, step4], {settleAll: true, getNextInput})(0));