@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
57 lines • 1.82 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCwdGitRemoteUrlHash = getCwdGitRemoteUrlHash;
const child_process_1 = require("child_process");
const sha_js_1 = __importDefault(require("sha.js"));
function azureGetGitRemoteUrl() {
if (process.env.BUILD_REPOSITORY_URI) {
return process.env.BUILD_REPOSITORY_URI;
}
else {
throw Error();
}
}
function getGitRemoteUrl(configPath) {
try {
return (0, child_process_1.execSync)("git config --get remote.origin.url", {
cwd: configPath, // Run the command in the configPath directory to support absolute path execution
stdio: ["pipe", "pipe", "ignore"] // Ignore stderr
})
.toString()
.trim();
}
catch (error) {
// Intentionally left blank
}
try {
return azureGetGitRemoteUrl();
}
catch (error) {
// Intentionally left blank
}
throw Error();
}
function getCwdGitRemoteUrlHash() {
const FALLBACK_NO_GIT_ORIGIN_REMOTE = "FALLBACK_NO_GIT_ORIGIN_REMOTE";
const FALLBACK_HASHING_FAILED = "FALLBACK_HASHING_FAILED";
try {
if (!process.env.CONFIG_PATH) {
throw Error();
}
const remoteUrl = getGitRemoteUrl(process.env.CONFIG_PATH);
try {
const remoteUrlHash = (0, sha_js_1.default)("sha256").update(remoteUrl).digest("hex");
return remoteUrlHash;
}
catch (error) {
return FALLBACK_HASHING_FAILED;
}
}
catch (error) {
return FALLBACK_NO_GIT_ORIGIN_REMOTE;
}
}
//# sourceMappingURL=getRepositoryInformation.js.map