@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
62 lines • 2.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigurationHash = getConfigurationHash;
const child_process_1 = require("child_process");
const sha_js_1 = __importDefault(require("sha.js"));
const path_1 = __importDefault(require("path"));
function azureGetGitRoot() {
if (process.env.BUILD_REPOSITORY_LOCALPATH) {
return process.env.BUILD_REPOSITORY_LOCALPATH;
}
else {
throw Error();
}
}
function getGitRoot(configPath) {
try {
return (0, child_process_1.execSync)("git rev-parse --show-toplevel", {
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 azureGetGitRoot();
}
catch (error) {
// Intentionally left blank
}
throw Error();
}
function getConfigurationHash() {
const FALLBACK_NO_CONFIG_HASH = "FALLBACK_NO_CONFIG_HASH";
const FALLBACK_NO_GIT_PATH = "FALLBACK_NO_GIT_PATH";
const FALLBACK_HASHING_FAILED = "FALLBACK_HASHING_FAILED";
if (process.env.CONFIG_PATH) {
const configPath = process.env.CONFIG_PATH;
try {
const gitRoot = getGitRoot(configPath);
const relativePath = path_1.default.relative(gitRoot, configPath);
try {
return (0, sha_js_1.default)("sha256").update(relativePath).digest("hex");
}
catch (error) {
return FALLBACK_HASHING_FAILED;
}
}
catch (error) {
return FALLBACK_NO_GIT_PATH;
}
}
else {
return FALLBACK_NO_CONFIG_HASH;
}
}
//# sourceMappingURL=getConfigurationInformation.js.map