pivotal-flow
Version:
🔀 A command-line tool that helps you manage & automate your workflow to use with PivotalTracker.
72 lines (71 loc) • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const console_1 = require("./console");
const git_1 = require("./git");
const common_1 = require("./pivotal/common");
/**
* Parse params of hooks based on environment variable name provided
* via the commander options.
*/
exports.parseHookParams = (envName) => {
const params = (process.env[envName] || '').trim();
if (!params) {
throw new TypeError(`Missing hook parameters. Try running the hook via husky or any other hook-runner.`);
}
return params.split(' ');
};
/**
* Skip the check in certain situations:-
* - when checking out a file
* - when checking out to a SHA
*/
exports.shouldSkipBranchCheck = (
/* checkout out from */
_prevHead,
/* checkout out to */
_currentHead,
/* checkoutType is 0 when it's a file checkout */
checkoutType) => {
console_1.debugLogObject('shouldSkipBranchCheck', { _prevHead, _currentHead, checkoutType });
if (checkoutType !== '1') {
console_1.debugLog('skipped due to checkoutType');
return true;
}
// if we're in a detached head state (eg. submodule checkout or rebase)
const detachedState = git_1.inDetachedHeadState();
console_1.debugLogObject('inDetachedHeadState', { detachedState });
return detachedState;
};
/**
* Skip the hook when
* - source is a commit (eg. amend)
* @example shouldSkipPrepareCommitMessage('.git/COMMIT_EDITMSG', 'message') => false
* @example shouldSkipPrepareCommitMessage('.git/COMMIT_EDITMSG', 'commit') => true // git amend
*/
exports.shouldSkipPrepareCommitMessage = (
/** Path to commit-msg file */
_,
/** 'commit' | 'message' */
source) => source == 'commit';
/**
* * Append story id to given commit message.
*/
exports.appendStoryIdToCommitMessage = (
/** Original Commit Message */
message,
/** Story id extracted from the branch. */
storyId) => {
const { found: foundInOriginalMessage, formatted: existingStoryId } = common_1.getStoryId(message);
if (foundInOriginalMessage) {
console_1.debugLogObject('skipping - story id already present', {
foundInOriginalMessage,
message,
storyId,
existingStoryId,
});
return message;
}
const messageWithId = [message, '---', `[${storyId}]`].join('\n');
console_1.debugLogObject('appended to the commit message', { message: messageWithId });
return messageWithId;
};