UNPKG

pivotal-flow

Version:

🔀 A command-line tool that helps you manage & automate your workflow to use with PivotalTracker.

80 lines (79 loc) 2.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fast_memoize_1 = __importDefault(require("fast-memoize")); const regex_1 = require("../../regex"); const types_1 = require("./types"); const string_1 = require("../string"); const git_1 = require("../git"); exports.getStoryTypeIcon = (type) => { switch (type) { case types_1.StoryType.Feature: return `⭐️ `; case types_1.StoryType.Bug: return `🐞 `; case types_1.StoryType.Chore: return `⚙️ `; case types_1.StoryType.Release: return `🏁 `; default: return ''; } }; exports.getStoryTypeLabel = (type) => `${exports.getStoryTypeIcon(type)} ${type}`; exports.getStoryTypeChoices = () => Object.values(types_1.StoryType).map(type => ({ value: type, name: exports.getStoryTypeLabel(type), })); /** * Get the branch prefix based on story type. * @example * getBranchPrefix('bug') => 'bugfix' * getBranchPrefix('feature') => 'feature' * getBranchPrefix('chore') => 'chore' * getBranchPrefix('release') => 'release' */ const getBranchPrefix = ( /** Type of story eg 'feature' / 'bug' etc. */ type) => { return type === 'bug' ? 'bugfix' : type; }; /** * Get branch name in the format `<story_type>/<slugified_story_name>_<story_id>` */ exports.getStoryBranchName = fast_memoize_1.default(( /** Story name or branch name as input by the user */ name, /** Type of the story */ type, /** Story ID */ id) => { const prefix = getBranchPrefix(type); const slugifiedName = string_1.slugifyName(name); return `${prefix}/${slugifiedName}_${id}`; }); /** * Get the Pivotal story id details from any input string. */ exports.getStoryId = ( /** any string input to search for story id In */ input) => { const matches = input.match(regex_1.PIVOTAL_ID_IN_STRING) || ['']; const [matched] = matches; const storyId = matched.startsWith('#') ? matched.substring(1) : matched; const formatted = `#${storyId}`; const found = Boolean(storyId); return { found, id: storyId, formatted }; }; /** * Get the Pivotal story id (if it exists) details from the current branch name. */ exports.getStoryIfFromCurrentBranch = () => { if (git_1.inDetachedHeadState()) { return { found: false, id: '', formatted: '' }; } const branch = git_1.getCurrentBranch() || ''; return exports.getStoryId(branch); };