UNPKG

flow-helper

Version:

Universal tool to simplify commit messages building

94 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const child_process_1 = require("child_process"); const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.on('close', function () { console.log('\nBYE BYE !!!'); process.exit(0); }); function execCommand(command, showCmd = true) { return new Promise((res, rej) => { showCmd && console.log(command); child_process_1.exec(command, (error, stdout, stderr) => { if (error) { console.error('Err: ', error); rej(error); return; } if (stderr) { showCmd && console.log(stderr); res(''); return; } if (stdout) { showCmd && console.log(stdout); res(stdout); return; } res(''); }); }); } function ask(question, defaultValue) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((res, rej) => { try { rl.question(question, function (answer) { res(answer); }); if (defaultValue) { rl.write(defaultValue); } } catch (e) { rej(e); } }); }); } const workTypes = ['FIX', 'FEATURE', 'REFACTOR']; const workStates = ['In progress', 'Peer review']; (() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { try { const currentBr = yield execCommand('git rev-parse --abbrev-ref HEAD', false); const currentBranch = currentBr.slice(0, -1); const prevComment = yield execCommand('git log -1 | grep -o "[A-Z]: [A-Za-z ]*[^ #]" | cut -c 4-', false); let targetBranch = 'dev'; let stateIndex = '1'; const comment = yield ask('Comment: ', prevComment.slice(0, -1)); const spent = yield ask('Spent time (30m|h): ', ''); const typeIndex = yield ask('Work type (0 - FIX, 1 - FEATURE, 2 - REFACTOR): ', '1'); const type = workTypes[Number(typeIndex)] || workTypes[1]; stateIndex = yield ask('State (0 - In progress, 1 - Peer review): ', stateIndex); const state = workStates[Number(stateIndex)] || workStates[1]; const branch = yield ask('Current branch: ', currentBranch); targetBranch = yield ask('Target branch: ', targetBranch); const mrTitle = yield ask('MR title (fill if need create a new request or update an exist): ', ''); if (targetBranch != currentBranch && branch != currentBranch) { yield execCommand('git pull'); yield execCommand(`git stash`); yield execCommand(`git checkout ${targetBranch}`); yield execCommand(`git stash apply`); } if (currentBranch != branch) { yield execCommand(`git checkout -b ${branch} || git checkout ${branch}`); } yield execCommand(`git commit -a -m"${type}: ${comment} #${branch} State ${state} work Development ${spent}"`); if (!mrTitle) { yield execCommand(`git push --set-upstream origin ${branch}`); } else { yield execCommand(`git push -o merge_request.create -o merge_request.title="#${branch}: ${mrTitle}" -o merge_request.target=${targetBranch} --set-upstream origin ${branch}`); } } catch (e) { console.log('Something went wrong', e); } rl.close(); }))(); //# sourceMappingURL=index.js.map