fix(app/metrics): action inputs parser [skip ci]

This commit is contained in:
lowlighter
2022-01-25 21:44:11 -05:00
parent 2096473939
commit 80dd8eee30

View File

@@ -238,8 +238,17 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
//Build query object from inputs //Build query object from inputs
const q = {} const q = {}
for (const key of Object.keys(inputs)) { for (const key of Object.keys(inputs)) {
const unspecified = process.env[`INPUT_${key.replace(/ /g, "_").toUpperCase()}`] === "<default-value>" //Parse input
let value let value = `${core.getInput(key)}`.trim()
try {
value = decodeURIComponent(value)
}
catch {
console.debug(`metrics/inputs > failed to decode uri for ${key}`)
logger(`metrics/inputs > failed to decode uri for ${key}: ${value}`)
value = "<default-value>"
}
const unspecified = value === "<default-value>"
//From presets //From presets
if ((key in preset)&&(unspecified)) { if ((key in preset)&&(unspecified)) {
console.debug(`metrics/inputs > ${key} has been set by preset value`) console.debug(`metrics/inputs > ${key} has been set by preset value`)
@@ -249,19 +258,12 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
//From defaults //From defaults
else if (unspecified) { else if (unspecified) {
console.debug(`metrics/inputs > ${key} has been set by default value`) console.debug(`metrics/inputs > ${key} has been set by default value`)
value = metadata.inputs[key]?.default q[key] = metadata.inputs[key]?.default
continue
} }
//From user //From user
else { else {
console.debug(`metrics/inputs > ${key} has been set by user`) console.debug(`metrics/inputs > ${key} has been set by user`)
value = `${core.getInput(key)}`.trim()
}
try {
q[key] = decodeURIComponent(value)
}
catch {
console.debug(`metrics/inputs > failed to decode uri for ${key}`)
logger(`metrics/inputs > failed to decode uri for ${key}: ${value}`)
q[key] = value q[key] = value
} }
} }
@@ -427,7 +429,7 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
} }
/**Metadata extractor for templates */ /**Metadata extractor for templates */
metadata.template = async function({__templates, name, plugins, logger}) { metadata.template = async function({__templates, name, plugins}) {
try { try {
//Load meta descriptor //Load meta descriptor
const raw = fs.existsSync(path.join(__templates, name, "metadata.yml")) ? `${await fs.promises.readFile(path.join(__templates, name, "metadata.yml"), "utf-8")}` : "" const raw = fs.existsSync(path.join(__templates, name, "metadata.yml")) ? `${await fs.promises.readFile(path.join(__templates, name, "metadata.yml"), "utf-8")}` : ""