Repository: semantic-release/semantic-release
Pull request #992 (2018-11-19 23:26:32)

Minor refactoring and typos
I made several minor refactoring / typo fix in #991.
For clarity I moved them in their own commits.


Patch:
diff --git a/index.js b/index.js
index 1baeb7a..0bbfa08 100644
--- a/index.js
+++ b/index.js
@@ -13,7 +13,7 @@ const getLastRelease = require('./lib/get-last-release');
 const {extractErrors} = require('./lib/utils');
 const getGitAuthUrl = require('./lib/get-git-auth-url');
 const getLogger = require('./lib/get-logger');
-const {fetch, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
+const {fetch, verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git');
 const getError = require('./lib/get-error');
 const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
 
diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js
index c171b97..adb07ee 100644
--- a/lib/definitions/plugins.js
+++ b/lib/definitions/plugins.js
@@ -1,5 +1,5 @@
 const {isString, isPlainObject} = require('lodash');
-const {gitHead} = require('../git');
+const {getGitHead} = require('../git');
 const hideSensitive = require('../hide-sensitive');
 const {hideSensitiveValues} = require('../utils');
 const {RELEASE_TYPE, RELEASE_NOTES_SEPARATOR} = require('./constants');
@@ -52,7 +52,7 @@ module.exports = {
     dryRun: false,
     pipelineConfig: ({generateNotes}) => ({
       getNextInput: async context => {
-        const newGitHead = await gitHead({cwd: context.cwd});
+        const newGitHead = await getGitHead({cwd: context.cwd});
         // If previous prepare plugin has created a commit (gitHead changed)
         if (context.nextRelease.gitHead !== newGitHead) {
           context.nextRelease.gitHead = newGitHead;
diff --git a/lib/get-last-release.js b/lib/get-last-release.js
index 77da1dd..7ec1417 100644
--- a/lib/get-last-release.js
+++ b/lib/get-last-release.js
@@ -2,7 +2,7 @@ const {escapeRegExp, template} = require('lodash');
 const semver = require('semver');
 const pLocate = require('p-locate');
 const debug = require('debug')('semantic-release:get-last-release');
-const {gitTags, isRefInHistory, gitTagHead} = require('./git');
+const {getTags, isRefInHistory, getTagHead} = require('./git');
 
 /**
  * Last release.
@@ -30,7 +30,7 @@ module.exports = async ({cwd, env, options: {tagFormat}, logger}) => {
   // The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
   // so it's guaranteed to no be present in the `tagFormat`.
   const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`;
-  const tags = (await gitTags({cwd, env}))
+  const tags = (await getTags({cwd, env}))
     .map(tag => ({gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1]}))
     .filter(
       tag => tag.version && semver.valid(semver.clean(tag.version)) && !semver.prerelease(semver.clean(tag.version))
@@ -43,7 +43,7 @@ module.exports = async ({cwd, env, options: {tagFormat}, logger}) => {
 
   if (tag) {
     logger.log(`Found git tag ${tag.gitTag} associated with version ${tag.version}`);
-    return {gitHead: await gitTagHead(tag.gitTag, {cwd, env}), ...tag};
+    return {gitHead: await getTagHead(tag.gitTag, {cwd, env}), ...tag};
   }
 
   logger.log('No git tag version found');
diff --git a/lib/git.js b/lib/git.js
index 9ecd9dc..77931be 100644
--- a/lib/git.js
+++ b/lib/git.js
@@ -4,12 +4,12 @@ const debug = require('debug')('semantic-release:git');
 /**
  * Get the commit sha for a given tag.
  *
- * @param {string} tagName Tag name for which to retrieve the commit sha.
+ * @param {String} tagName Tag name for which to retrieve the commit sha.
  * @param {Object} [execaOpts] Options to pass to `execa`.
  *
  * @return {string} The commit sha of the tag in parameter or `null`.
  */
-async function gitTagHead(tagName, execaOpts) {
+async function getTagHead(tagName, execaOpts) {
   try {
     return await execa.stdout('git', ['rev-list', '-1', tagName], execaOpts);
   } catch (error) {
@@ -25,20 +25,20 @@ async function gitTagHead(tagName, execaOpts) {
  * @return {Array<String>} List of git tags.
  * @throws {Error} If the `git` command fails.
  */
-async function gitTags(execaOpts) {
+async function getTags(execaOpts) {
   return (await execa.stdout('git', ['tag'], execaOpts))
     .split('\n')
     .map(tag => tag.trim())
-    .filter(tag => Boolean(tag));
+    .filter(Boolean);
 }
 
 /**
  * Verify if the `ref` is in the direct history of the current branch.
  *
- * @param {string} ref The reference to look for.
+ * @param {String} ref The reference to look for.
  * @param {Object} [execaOpts] Options to pass to `execa`.
  *
- * @return {boolean} `true` if the reference is in the history of the current branch, falsy otherwise.
+ * @return {Boolean} `true` if the reference is in the history of the current branch, falsy otherwise.
  */
 async function isRefInHistory(ref, execaOpts) {
   try {
@@ -73,9 +73,9 @@ async function fetch(repositoryUrl, execaOpts) {
  *
  * @param {Object} [execaOpts] Options to pass to `execa`.
  *
- * @return {string} the sha of the HEAD commit.
+ * @return {String} the sha of the HEAD commit.
  */
-function gitHead(execaOpts) {
+function getGitHead(execaOpts) {
   return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
 }
 
@@ -155,10 +155,10 @@ async function push(repositoryUrl, branch, execaOpts) {
 /**
  * Verify a tag name is a valid Git reference.
  *
- * @param {string} tagName the tag name to verify.
+ * @param {String} tagName the tag name to verify.
  * @param {Object} [execaOpts] Options to pass to `execa`.
  *
- * @return {boolean} `true` if valid, falsy otherwise.
+ * @return {Boolean} `true` if valid, falsy otherwise.
  */
 async function verifyTagName(tagName, execaOpts) {
   try {
@@ -186,11 +186,11 @@ async function isBranchUpToDate(branch, execaOpts) {
 }
 
 module.exports = {
-  gitTagHead,
-  gitTags,
+  getTagHead,
+  getTags,
   isRefInHistory,
   fetch,
-  gitHead,
+  getGitHead,
   repoUrl,
   isGitRepo,
   verifyAuth,


Test patch:
diff --git a/test/cli.test.js b/test/cli.test.js
index 07778dc..bad7efa 100644
--- a/test/cli.test.js
+++ b/test/cli.test.js
@@ -186,7 +186,7 @@ test.serial('Display help', async t => {
   t.is(exitCode, 0);
 });
 
-test.serial('Returns error code and prints help if called with a command', async t => {
+test.serial('Return error code and prints help if called with a command', async t => {
   const run = stub().resolves(true);
   const argv = ['', '', 'pre'];
   const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
diff --git a/test/git.test.js b/test/git.test.js
index 6ca26fd..0be62de 100644
--- a/test/git.test.js
+++ b/test/git.test.js
@@ -1,14 +1,14 @@
 import test from 'ava';
 import tempy from 'tempy';
 import {
-  gitTagHead,
+  getTagHead,
   isRefInHistory,
   fetch,
-  gitHead,
+  getGitHead,
   repoUrl,
   tag,
   push,
-  gitTags,
+  getTags,
   isGitRepo,
   verifyTagName,
   isBranchUpToDate,
@@ -33,7 +33,7 @@ test('Get the last commit sha', async t => {
   // Add commits to the master branch
   const commits = await gitCommits(['First'], {cwd});
 
-  const result = await gitHead({cwd});
+  const result = await getGitHead({cwd});
 
   t.is(result, commits[0].hash);
 });
@@ -42,7 +42,7 @@ test('Throw error if the last commit sha cannot be found', async t => {
   // Create a git repository, set the current working directory at the root of the repo
   const {cwd} = await gitRepo();
 
-  await t.throws(gitHead({cwd}), Error);
+  await t.throws(getGitHead({cwd}), Error);
 });
 
 test('Unshallow and fetch repository', async t => {
@@ -84,7 +84,7 @@ test('Fetch all tags on a detached head repository', async t => {
 
   await fetch(repositoryUrl, {cwd});
 
-  t.deepEqual((await gitTags({cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
+  t.deepEqual((await getTags({cwd})).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort());
 });
 
 test('Verify if the commit `sha` is in the direct history of the current branch', async t => {
@@ -111,8 +111,8 @@ test('Get the commit sha for a given tag or falsy if the tag does not exists', a
   // Create the tag corresponding to version 1.0.0
   await gitTagVersion('v1.0.0', undefined, {cwd});
 
-  t.is(await gitTagHead('v1.0.0', {cwd}), commits[0].hash);
-  t.falsy(await gitTagHead('missing_tag', {cwd}));
+  t.is(await getTagHead('v1.0.0', {cwd}), commits[0].hash);
+  t.falsy(await getTagHead('missing_tag', {cwd}));
 });
 
 test('Return git remote repository url from config', async t => {
@@ -192,7 +192,7 @@ test('Return falsy for invalid tag names', async t => {
 test('Throws error if obtaining the tags fails', async t => {
   const cwd = tempy.directory();
 
-  await t.throws(gitTags({cwd}));
+  await t.throws(getTags({cwd}));
 });
 
 test('Return "true" if repository is up to date', async t => {
diff --git a/test/helpers/git-utils.js b/test/helpers/git-utils.js
index fedbb6a..38b464b 100644
--- a/test/helpers/git-utils.js
+++ b/test/helpers/git-utils.js
@@ -26,7 +26,7 @@ import getStream from 'get-stream';
 export async function gitRepo(withRemote, branch = 'master') {
   let cwd = tempy.directory();
 
-  await execa('git', ['init'].concat(withRemote ? ['--bare'] : []), {cwd});
+  await execa('git', ['init', ...(withRemote ? ['--bare'] : [])], {cwd});
 
   const repositoryUrl = fileUrl(cwd);
   if (withRemote) {
diff --git a/test/integration.test.js b/test/integration.test.js
index 08eea93..ecbf704 100644
--- a/test/integration.test.js
+++ b/test/integration.test.js
@@ -6,7 +6,7 @@ import {writeJson, readJson} from 'fs-extra';
 import execa from 'execa';
 import {WritableStreamBuffer} from 'stream-buffers';
 import {SECRET_REPLACEMENT} from '../lib/definitions/constants';
-import {gitHead as getGitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead, gitPush} from './helpers/git-utils';
+import {gitHead, gitTagHead, gitRepo, gitCommits, gitRemoteTagHead, gitPush} from './helpers/git-utils';
 import gitbox from './helpers/gitbox';
 import mockServer from './helpers/mockserver';
 import npmRegistry from './helpers/npm-registry';
@@ -108,12 +108,12 @@ test('Release patch, minor and major versions', async t => {
   let [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
     (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
   );
-  let gitHead = await getGitHead({cwd});
+  let head = await gitHead({cwd});
   t.is(releasedVersion, version);
-  t.is(releasedGitHead, gitHead);
-  t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
-  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
-  t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
+  t.is(releasedGitHead, head);
+  t.is(await gitTagHead(`v${version}`, {cwd}), head);
+  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
+  t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
 
   await mockServer.verify(verifyMock);
   await mockServer.verify(createReleaseMock);
@@ -150,12 +150,12 @@ test('Release patch, minor and major versions', async t => {
   [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
     (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
   );
-  gitHead = await getGitHead({cwd});
+  head = await gitHead({cwd});
   t.is(releasedVersion, version);
-  t.is(releasedGitHead, gitHead);
-  t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
-  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
-  t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
+  t.is(releasedGitHead, head);
+  t.is(await gitTagHead(`v${version}`, {cwd}), head);
+  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
+  t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
 
   await mockServer.verify(verifyMock);
   await mockServer.verify(createReleaseMock);
@@ -192,12 +192,12 @@ test('Release patch, minor and major versions', async t => {
   [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
     (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
   );
-  gitHead = await getGitHead({cwd});
+  head = await gitHead({cwd});
   t.is(releasedVersion, version);
-  t.is(releasedGitHead, gitHead);
-  t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
-  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
-  t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
+  t.is(releasedGitHead, head);
+  t.is(await gitTagHead(`v${version}`, {cwd}), head);
+  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
+  t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
 
   await mockServer.verify(verifyMock);
   await mockServer.verify(createReleaseMock);
@@ -234,12 +234,12 @@ test('Release patch, minor and major versions', async t => {
   [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
     (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
   );
-  gitHead = await getGitHead({cwd});
+  head = await gitHead({cwd});
   t.is(releasedVersion, version);
-  t.is(releasedGitHead, gitHead);
-  t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
-  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
-  t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
+  t.is(releasedGitHead, head);
+  t.is(await gitTagHead(`v${version}`, {cwd}), head);
+  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
+  t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
 
   await mockServer.verify(verifyMock);
   await mockServer.verify(createReleaseMock);
@@ -388,12 +388,12 @@ test('Allow local releases with "noCi" option', async t => {
     (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
   );
 
-  const gitHead = await getGitHead({cwd});
+  const head = await gitHead({cwd});
   t.is(releasedVersion, version);
-  t.is(releasedGitHead, gitHead);
-  t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
-  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
-  t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
+  t.is(releasedGitHead, head);
+  t.is(await gitTagHead(`v${version}`, {cwd}), head);
+  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
+  t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
 
   await mockServer.verify(verifyMock);
   await mockServer.verify(createReleaseMock);
@@ -442,12 +442,12 @@ test('Pass options via CLI arguments', async t => {
   const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
     (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
   );
-  const gitHead = await getGitHead({cwd});
+  const head = await gitHead({cwd});
   t.is(releasedVersion, version);
-  t.is(releasedGitHead, gitHead);
-  t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
-  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
-  t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
+  t.is(releasedGitHead, head);
+  t.is(await gitTagHead(`v${version}`, {cwd}), head);
+  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
+  t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
 });
 
 test('Run via JS API', async t => {
@@ -500,12 +500,12 @@ test('Run via JS API', async t => {
   const [, releasedVersion, releasedGitHead] = /^version = '(.+)'\s+gitHead = '(.+)'$/.exec(
     (await execa('npm', ['show', packageName, 'version', 'gitHead'], {env: testEnv, cwd})).stdout
   );
-  const gitHead = await getGitHead({cwd});
+  const head = await gitHead({cwd});
   t.is(releasedVersion, version);
-  t.is(releasedGitHead, gitHead);
-  t.is(await gitTagHead(`v${version}`, {cwd}), gitHead);
-  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), gitHead);
-  t.log(`+ released ${releasedVersion} with gitHead ${releasedGitHead}`);
+  t.is(releasedGitHead, head);
+  t.is(await gitTagHead(`v${version}`, {cwd}), head);
+  t.is(await gitRemoteTagHead(authUrl, `v${version}`, {cwd}), head);
+  t.log(`+ released ${releasedVersion} with head ${releasedGitHead}`);
 
   await mockServer.verify(verifyMock);
   await mockServer.verify(createReleaseMock);
diff --git a/test/verify.test.js b/test/verify.test.js
index 4f6e8ce..3bf1e10 100644
--- a/test/verify.test.js
+++ b/test/verify.test.js
@@ -11,10 +11,16 @@ test('Throw a AggregateError', async t => {
 
   t.is(errors[0].name, 'SemanticReleaseError');
   t.is(errors[0].code, 'ENOREPOURL');
+  t.truthy(errors[0].message);
+  t.truthy(errors[0].details);
   t.is(errors[1].name, 'SemanticReleaseError');
   t.is(errors[1].code, 'EINVALIDTAGFORMAT');
+  t.truthy(errors[1].message);
+  t.truthy(errors[1].details);
   t.is(errors[2].name, 'SemanticReleaseError');
   t.is(errors[2].code, 'ETAGNOVERSION');
+  t.truthy(errors[2].message);
+  t.truthy(errors[2].details);
 });
 
 test('Throw a SemanticReleaseError if does not run on a git repository', async t => {
@@ -25,6 +31,8 @@ test('Throw a SemanticReleaseError if does not run on a git repository', async t
 
   t.is(errors[0].name, 'SemanticReleaseError');
   t.is(errors[0].code, 'ENOGITREPO');
+  t.truthy(errors[0].message);
+  t.truthy(errors[0].details);
 });
 
 test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async t => {
@@ -35,6 +43,8 @@ test('Throw a SemanticReleaseError if the "tagFormat" is not valid', async t =>
 
   t.is(errors[0].name, 'SemanticReleaseError');
   t.is(errors[0].code, 'EINVALIDTAGFORMAT');
+  t.truthy(errors[0].message);
+  t.truthy(errors[0].details);
 });
 
 test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "version" variable', async t => {
@@ -45,6 +55,8 @@ test('Throw a SemanticReleaseError if the "tagFormat" does not contains the "ver
 
   t.is(errors[0].name, 'SemanticReleaseError');
   t.is(errors[0].code, 'ETAGNOVERSION');
+  t.truthy(errors[0].message);
+  t.truthy(errors[0].details);
 });
 
 test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version" variables', async t => {
@@ -55,6 +67,8 @@ test('Throw a SemanticReleaseError if the "tagFormat" contains multiple "version
 
   t.is(errors[0].name, 'SemanticReleaseError');
   t.is(errors[0].code, 'ETAGNOVERSION');
+  t.truthy(errors[0].message);
+  t.truthy(errors[0].details);
 });
 
 test('Return "true" if all verification pass', async t => {