Skip to content

Commit

Permalink
refactor: harmonize git utils function names
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Nov 19, 2018
1 parent e594638 commit 9f5645c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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');

Expand Down
4 changes: 2 additions & 2 deletions 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');
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lib/get-last-release.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand All @@ -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');
Expand Down
12 changes: 6 additions & 6 deletions lib/git.js
Expand Up @@ -9,7 +9,7 @@ const debug = require('debug')('semantic-release:git');
*
* @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) {
Expand All @@ -25,7 +25,7 @@ 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())
Expand Down Expand Up @@ -75,7 +75,7 @@ async function fetch(repositoryUrl, execaOpts) {
*
* @return {string} the sha of the HEAD commit.
*/
function gitHead(execaOpts) {
function getGitHead(execaOpts) {
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
}

Expand Down Expand Up @@ -186,11 +186,11 @@ async function isBranchUpToDate(branch, execaOpts) {
}

module.exports = {
gitTagHead,
gitTags,
getTagHead,
getTags,
isRefInHistory,
fetch,
gitHead,
getGitHead,
repoUrl,
isGitRepo,
verifyAuth,
Expand Down
18 changes: 9 additions & 9 deletions 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,
Expand All @@ -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);
});
Expand All @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down
72 changes: 36 additions & 36 deletions test/integration.test.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9f5645c

Please sign in to comment.