UNPKG

@featurevisor/core

Version:

Core package of Featurevisor for Node.js usage

48 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRepoDetails = getRepoDetails; const child_process_1 = require("child_process"); const getOwnerAndRepoFromUrl_1 = require("./getOwnerAndRepoFromUrl"); function getRepoDetails() { try { const topLevelPathOutput = (0, child_process_1.execSync)(`git rev-parse --show-toplevel`); const topLevelPath = topLevelPathOutput.toString().trim(); const remoteUrlOutput = (0, child_process_1.execSync)(`git remote get-url origin`); const remoteUrl = remoteUrlOutput.toString().trim(); const branchOutput = (0, child_process_1.execSync)(`git rev-parse --abbrev-ref HEAD`); const branch = branchOutput.toString().trim(); if (!remoteUrl || !branch) { return; } const { owner, repo } = (0, getOwnerAndRepoFromUrl_1.getOwnerAndRepoFromUrl)(remoteUrl); if (!owner || !repo) { return; } let blobUrl; let commitUrl; if (remoteUrl.indexOf("github.com") > -1) { blobUrl = `https://github.com/${owner}/${repo}/blob/${branch}/{{blobPath}}`; commitUrl = `https://github.com/${owner}/${repo}/commit/{{hash}}`; } else if (remoteUrl.indexOf("bitbucket.org") > -1) { blobUrl = `https://bitbucket.org/${owner}/${repo}/src/${branch}/{{blobPath}}`; commitUrl = `https://bitbucket.org/${owner}/${repo}/commits/{{hash}}`; } if (!blobUrl || !commitUrl) { return; } return { branch, remoteUrl, blobUrl, commitUrl, topLevelPath, }; } catch (e) { console.error(e); return; } return; } //# sourceMappingURL=getRepoDetails.js.map