UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

43 lines (38 loc) 1.26 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var slash_slash = require('../slash/slash.js'); var rmFirstAndLastSlash = slash_slash.removeFirstAndLastSlash; function getGitCodeLink(_ref) { var domain = _ref.domain, repo = _ref.repo, branch = _ref.branch, localFile = _ref.localFile, line = _ref.line; var pwd = process.cwd(); var file = localFile.replace(new RegExp("^".concat(pwd)), ''); var pDomain = rmFirstAndLastSlash(domain); var pRepo = rmFirstAndLastSlash(repo); var pBranch = rmFirstAndLastSlash(branch); var pFile = rmFirstAndLastSlash(file); var link = [pDomain, pRepo, 'blob', pBranch, pFile].join('/'); if (line) { return "".concat(link, "#L").concat(line); } return link; } function getGitMRLink(_ref2) { var domain = _ref2.domain, repo = _ref2.repo, _ref2$id = _ref2.id, id = _ref2$id === void 0 ? '' : _ref2$id; var pDomain = rmFirstAndLastSlash(domain); var pRepo = rmFirstAndLastSlash(repo); var list = [pDomain, pRepo]; if (id) { list.push.apply(list, ['merge_requests', id]); } return list.join('/'); } exports.getGitCodeLink = getGitCodeLink; exports.getGitMRLink = getGitMRLink; exports.rmFirstAndLastSlash = rmFirstAndLastSlash;