UNPKG

@secustor/backstage-plugin-renovate-backend

Version:
95 lines (89 loc) 3.16 kB
'use strict'; var is = require('@sindresorhus/is'); var index = require('../config/index.cjs.js'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; } var is__default = /*#__PURE__*/_interopDefaultCompat(is); async function extractReport(opts) { const { logStream, logger } = opts; return new Promise((resolve, reject) => { let uncompletedText = ""; logStream.on("data", (chunk) => { const text = uncompletedText.concat(chunk.toString()); const logLines = text.split("\n"); uncompletedText = logLines.pop() ?? ""; for (const logLine of logLines) { const log = JSON.parse(logLine); if (log.report) { const report = log.report; resolve(report); continue; } const meta = {}; for (const [key, value] of Object.entries(log)) { if (["msg", "logContext", "report"].includes(key)) { continue; } meta[key] = JSON.stringify(value); } const msg = is__default.default.string(log.msg) ? log.msg : JSON.stringify(log.msg); logger.debug(msg, meta); } }); logStream.on("end", () => { if (uncompletedText) { logger.warn("Uncompleted log line found", { uncompletedText }); reject( "Premature exit of Renovate. Uncompleted log line found in log stream after end of stream" ); } reject("No report found in log stream"); }); }); } function getCacheEnvs(config, logger) { const cacheEnabled = index.getPluginConfig(config).getOptionalBoolean("cache.enabled") ?? true; if (!cacheEnabled) { logger.debug("Cache has been disabled in plugin configuration"); return {}; } const cacheConfig = config.getOptionalConfig("backend.cache"); if (is__default.default.nullOrUndefined(cacheConfig)) { logger.debug("No cache configured"); return {}; } const store = cacheConfig.getString("store"); if (store !== "redis") { logger.debug(`Unsupported cache store '${store}' detected`); return {}; } const connection = cacheConfig.getOptionalString("connection"); if (is__default.default.nullOrUndefined(connection)) { logger.debug("No connection string for redis cache configured in backend"); return {}; } logger.debug("Injecting Redis cache into Renovate"); return { RENOVATE_REDIS_PREFIX: "renovate_", RENOVATE_REDIS_URL: connection }; } function getPassthroughEnvs(config, logger) { const env = {}; const passthroughEnvs = index.getPluginConfig(config).getOptionalConfigArray("runtime.environment") ?? []; for (const e of passthroughEnvs) { const name = e.getString("name"); const value = e.getOptionalString("value") ?? process.env[name]; if (value) { env[name] = value; } else { logger.debug( `utils::getPassthroughEnvs - no value found for environment variable ${name}` ); } } return env; } exports.extractReport = extractReport; exports.getCacheEnvs = getCacheEnvs; exports.getPassthroughEnvs = getPassthroughEnvs; //# sourceMappingURL=utils.cjs.js.map