feat(app/action): add presets (#817) [skip ci]
This commit is contained in:
475
action.yml
generated
475
action.yml
generated
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ import sgit from "simple-git"
|
|||||||
import mocks from "../../../tests/mocks/index.mjs"
|
import mocks from "../../../tests/mocks/index.mjs"
|
||||||
import metrics from "../metrics/index.mjs"
|
import metrics from "../metrics/index.mjs"
|
||||||
import setup from "../metrics/setup.mjs"
|
import setup from "../metrics/setup.mjs"
|
||||||
|
import presets from "../metrics/presets.mjs"
|
||||||
process.on("unhandledRejection", error => {
|
process.on("unhandledRejection", error => {
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
@@ -17,6 +18,9 @@ process.on("unhandledRejection", error => {
|
|||||||
let DEBUG = true
|
let DEBUG = true
|
||||||
const debugged = []
|
const debugged = []
|
||||||
|
|
||||||
|
//Preset
|
||||||
|
const preset = {}
|
||||||
|
|
||||||
//Info logger
|
//Info logger
|
||||||
const info = (left, right, {token = false} = {}) => console.log(`${`${left}`.padEnd(63 + 9 * (/0m$/.test(left)))} │ ${
|
const info = (left, right, {token = false} = {}) => console.log(`${`${left}`.padEnd(63 + 9 * (/0m$/.test(left)))} │ ${
|
||||||
Array.isArray(right)
|
Array.isArray(right)
|
||||||
@@ -33,7 +37,7 @@ info.section = (left = "", right = " ") => info(`\x1b[36m${left}\x1b[0m`, right)
|
|||||||
info.group = ({metadata, name, inputs}) => {
|
info.group = ({metadata, name, inputs}) => {
|
||||||
info.section(metadata.plugins[name]?.name?.match(/(?<section>[\w\s]+)/i)?.groups?.section?.trim(), " ")
|
info.section(metadata.plugins[name]?.name?.match(/(?<section>[\w\s]+)/i)?.groups?.section?.trim(), " ")
|
||||||
for (const [input, value] of Object.entries(inputs))
|
for (const [input, value] of Object.entries(inputs))
|
||||||
info(metadata.plugins[name]?.inputs[input]?.description?.split("\n")[0] ?? metadata.plugins[name]?.inputs[input]?.description ?? input, value, {token:metadata.plugins[name]?.inputs[input]?.type === "token"})
|
info(metadata.plugins[name]?.inputs[input]?.description?.split("\n")[0] ?? metadata.plugins[name]?.inputs[input]?.description ?? input, `${input in preset ? "*" : ""}${value}`, {token:metadata.plugins[name]?.inputs[input]?.type === "token"})
|
||||||
}
|
}
|
||||||
info.break = () => console.log("─".repeat(88))
|
info.break = () => console.log("─".repeat(88))
|
||||||
|
|
||||||
@@ -91,6 +95,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
|||||||
info("Version", conf.package.version)
|
info("Version", conf.package.version)
|
||||||
|
|
||||||
//Core inputs
|
//Core inputs
|
||||||
|
Object.assign(preset, await presets(core.getInput("config_presets"), {log:true, core}))
|
||||||
const {
|
const {
|
||||||
user:_user,
|
user:_user,
|
||||||
repo:_repo,
|
repo:_repo,
|
||||||
@@ -120,7 +125,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
|||||||
"output.condition":_output_condition,
|
"output.condition":_output_condition,
|
||||||
delay,
|
delay,
|
||||||
...config
|
...config
|
||||||
} = metadata.plugins.core.inputs.action({core})
|
} = metadata.plugins.core.inputs.action({core, preset})
|
||||||
const q = {...query, ...(_repo ? {repo:_repo} : null), template}
|
const q = {...query, ...(_repo ? {repo:_repo} : null), template}
|
||||||
const _output = ["svg", "jpeg", "png", "json", "markdown", "markdown-pdf", "insights"].includes(config["config.output"]) ? config["config.output"] : metadata.templates[template].formats[0] ?? null
|
const _output = ["svg", "jpeg", "png", "json", "markdown", "markdown-pdf", "insights"].includes(config["config.output"]) ? config["config.output"] : metadata.templates[template].formats[0] ?? null
|
||||||
const filename = _filename.replace(/[*]/g, {jpeg:"jpg", markdown:"md", "markdown-pdf":"pdf", insights:"html"}[_output] ?? _output)
|
const filename = _filename.replace(/[*]/g, {jpeg:"jpg", markdown:"md", "markdown-pdf":"pdf", insights:"html"}[_output] ?? _output)
|
||||||
@@ -293,7 +298,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
|||||||
|
|
||||||
//Base content
|
//Base content
|
||||||
info.break()
|
info.break()
|
||||||
const {base:parts, repositories:_repositories, ...base} = metadata.plugins.base.inputs.action({core})
|
const {base:parts, repositories:_repositories, ...base} = metadata.plugins.base.inputs.action({core, preset})
|
||||||
conf.settings.repositories = _repositories
|
conf.settings.repositories = _repositories
|
||||||
info.group({metadata, name:"base", inputs:{repositories:conf.settings.repositories, ...base}})
|
info.group({metadata, name:"base", inputs:{repositories:conf.settings.repositories, ...base}})
|
||||||
info("Base sections", parts)
|
info("Base sections", parts)
|
||||||
@@ -306,7 +311,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
|||||||
const plugins = {}
|
const plugins = {}
|
||||||
for (const name of Object.keys(Plugins).filter(key => !["base", "core"].includes(key))) {
|
for (const name of Object.keys(Plugins).filter(key => !["base", "core"].includes(key))) {
|
||||||
//Parse inputs
|
//Parse inputs
|
||||||
const {[name]:enabled, ...inputs} = metadata.plugins[name].inputs.action({core})
|
const {[name]:enabled, ...inputs} = metadata.plugins[name].inputs.action({core, preset})
|
||||||
plugins[name] = {enabled}
|
plugins[name] = {enabled}
|
||||||
//Register user inputs
|
//Register user inputs
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
|||||||
@@ -228,17 +228,34 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
|
|||||||
key,
|
key,
|
||||||
{
|
{
|
||||||
comment:comments[key] ?? `# ${value.description}`,
|
comment:comments[key] ?? `# ${value.description}`,
|
||||||
descriptor:yaml.dump({[key]:Object.fromEntries(Object.entries(value).filter(([key]) => ["description", "default", "required"].includes(key)).map(([k, v]) => k === "description" ? [k, v.split("\n")[0]] : [k, v]))}, {quotingType:'"', noCompatMode:true}),
|
descriptor:yaml.dump({[key]:Object.fromEntries(Object.entries(value).filter(([key]) => ["description", "default", "required"].includes(key)).map(([k, v]) => k === "description" ? [k, v.split("\n")[0]] : k === "default" ? [k, "<default-value>"] : [k, v]))}, {quotingType:'"', noCompatMode:true}),
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
|
|
||||||
//Action inputs
|
//Action inputs
|
||||||
meta.inputs.action = function({core}) {
|
meta.inputs.action = function({core, preset = {}}) {
|
||||||
//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 value = `${core.getInput(key)}`.trim()
|
const unspecified = process.env[`INPUT_${key.replace(/ /g, "_").toUpperCase()}`] === "<default-value>"
|
||||||
|
let value
|
||||||
|
//From presets
|
||||||
|
if ((key in preset)&&(unspecified)) {
|
||||||
|
logger(`metrics/inputs > ${key} has been set by preset value`)
|
||||||
|
q[key] = preset[key]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//From defaults
|
||||||
|
else if (unspecified) {
|
||||||
|
logger(`metrics/inputs > ${key} has been set by default value`)
|
||||||
|
value = metadata.inputs[key]?.default
|
||||||
|
}
|
||||||
|
//From user
|
||||||
|
else {
|
||||||
|
logger(`metrics/inputs > ${key} has been set by user`)
|
||||||
|
value = `${core.getInput(key)}`.trim()
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
q[key] = decodeURIComponent(value)
|
q[key] = decodeURIComponent(value)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user