@codechecks/client
Version:
Open source platform for code review automation
29 lines • 998 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = require("path");
const errors_1 = require("./errors");
const REMOTE_URL_REGEXP = /^(?:(?:git\@)|(?:https?:\/\/))github\.com(?::|\/)(.+)$/;
function findRootGitRepository(path) {
const gitDirPath = path_1.join(path, ".git");
const parentDir = path_1.join(path, "..");
if (path === "/" || !path) {
return undefined;
}
if (fs_1.existsSync(gitDirPath)) {
return path;
}
else {
return findRootGitRepository(parentDir);
}
}
exports.findRootGitRepository = findRootGitRepository;
function fullNameFromRemoteUrl(remoteUrl) {
const matches = remoteUrl.match(REMOTE_URL_REGEXP);
if (!matches || !matches[1]) {
throw errors_1.crash(`Can't get project slug from ${remoteUrl}`);
}
return matches[1].replace(/(.git)$/, "");
}
exports.fullNameFromRemoteUrl = fullNameFromRemoteUrl;
//# sourceMappingURL=git.js.map