danger
Version:
Unit tests for Team Culture
40 lines • 1.74 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRepoSlug = void 0;
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var ini_1 = __importDefault(require("ini"));
var parse_github_url_1 = __importDefault(require("parse-github-url"));
var getRepoSlug = function () {
try {
var gitConfigPath = path_1.default.join(process.cwd(), ".git", "config");
if (!fs_1.default.existsSync(gitConfigPath)) {
return null;
}
var configContent = fs_1.default.readFileSync(gitConfigPath, "utf8");
var parsedConfig = ini_1.default.parse(configContent);
var remotes_1 = {};
for (var key in parsedConfig) {
if (key.startsWith('remote "')) {
var remoteName = key.substring(8, key.length - 1);
remotes_1[remoteName] = parsedConfig[key];
}
}
var possibleRemoteNames = ["upstream", "origin"];
var possibleRemotes = possibleRemoteNames.map(function (name) { return remotes_1[name]; }).filter(function (remote) { return remote && remote.url; });
if (possibleRemotes.length === 0) {
return null;
}
var ghData = possibleRemotes.map(function (r) { return (0, parse_github_url_1.default)(r.url); });
return ghData.length && ghData[0] ? ghData[0].repo : undefined;
}
catch (error) {
console.error("Error reading git config:", error);
return null;
}
};
exports.getRepoSlug = getRepoSlug;
//# sourceMappingURL=get-repo-slug.js.map
;