UNPKG

code-story

Version:

Get your code activity log for standup from git

29 lines (28 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var constants_1 = require("src/constants"); /** * Get breach name from source by commit hash */ var getBranchInfoByCommitHash = function (commitHash, gitLogData) { var reflogRecords = gitLogData.split(constants_1.LINE_BREAK_CHAR); var logRecord = reflogRecords.filter(function (logRecord) { return logRecord.indexOf(commitHash) === 0; })[0]; var result = logRecord === null || logRecord === void 0 ? void 0 : logRecord.match(/^.{0,}refs\/(heads|remotes\/origin|tags)\/([^\s\t\n]+)/); var refResult = result && result[1]; var refType; if (refResult === 'heads') { refType = 'head'; } else if (refResult === 'tags') { refType = 'tag'; } else { refType = 'remote'; } var branchName = result && result[2]; return { name: branchName || "[Don't detect source branch]", refType: refType, }; }; exports.default = getBranchInfoByCommitHash;