Accept replaceable values in array types
This commit is contained in:
@@ -79,6 +79,19 @@ metadata.plugin = async function({__plugins, name, logger}) {
|
|||||||
if (!meta.supports?.includes(context))
|
if (!meta.supports?.includes(context))
|
||||||
throw {error:{message:`Not supported for: ${context}`, instance:new Error()}}
|
throw {error:{message:`Not supported for: ${context}`, instance:new Error()}}
|
||||||
}
|
}
|
||||||
|
//Special values replacer
|
||||||
|
const replacer = value => {
|
||||||
|
value = `${value}`.trim()
|
||||||
|
if (user) {
|
||||||
|
if (value === ".user.login")
|
||||||
|
return user.login
|
||||||
|
if (value === ".user.twitter")
|
||||||
|
return user.twitterUsername
|
||||||
|
if (value === ".user.website")
|
||||||
|
return user.websiteUrl
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
//Inputs checks
|
//Inputs checks
|
||||||
const result = Object.fromEntries(
|
const result = Object.fromEntries(
|
||||||
Object.entries(inputs).map(([key, {type, format, default:defaulted, min, max, values}]) => [
|
Object.entries(inputs).map(([key, {type, format, default:defaulted, min, max, values}]) => [
|
||||||
@@ -120,19 +133,11 @@ metadata.plugin = async function({__plugins, name, logger}) {
|
|||||||
}
|
}
|
||||||
const separators = {"comma-separated":",", "space-separated":" "}
|
const separators = {"comma-separated":",", "space-separated":" "}
|
||||||
const separator = separators[[format].flat().filter(s => s in separators)[0]] ?? ","
|
const separator = separators[[format].flat().filter(s => s in separators)[0]] ?? ","
|
||||||
return value.split(separator).map(v => v.trim().toLocaleLowerCase()).filter(v => Array.isArray(values) ? values.includes(v) : true).filter(v => v)
|
return value.split(separator).map(v => replacer(v.trim().toLocaleLowerCase())).filter(v => Array.isArray(values) ? values.includes(v) : true).filter(v => v)
|
||||||
}
|
}
|
||||||
//String
|
//String
|
||||||
case "string": {
|
case "string": {
|
||||||
value = `${value}`.trim()
|
value = replacer(value)
|
||||||
if (user) {
|
|
||||||
if (value === ".user.login")
|
|
||||||
return user.login
|
|
||||||
if (value === ".user.twitter")
|
|
||||||
return user.twitterUsername
|
|
||||||
if (value === ".user.website")
|
|
||||||
return user.websiteUrl
|
|
||||||
}
|
|
||||||
if ((Array.isArray(values)) && (!values.includes(value)))
|
if ((Array.isArray(values)) && (!values.includes(value)))
|
||||||
return defaulted
|
return defaulted
|
||||||
return value
|
return value
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
export default async function({login, graphql, data, q, queries, imports}, conf) {
|
export default async function({login, graphql, data, q, queries, imports}, conf) {
|
||||||
//Load inputs
|
//Load inputs
|
||||||
console.debug(`metrics/compute/${login}/base > started`)
|
console.debug(`metrics/compute/${login}/base > started`)
|
||||||
let {repositories, "repositories.forks":_forks, "repositories.affiliations":_affiliations, "repositories.skipped":_skipped} = imports.metadata.plugins.base.inputs({data, q, account:"bypass"}, {repositories:conf.settings.repositories ?? 100})
|
let {repositories, "repositories.forks":_forks, "repositories.affiliations":_affiliations} = imports.metadata.plugins.base.inputs({data, q, account:"bypass"}, {repositories:conf.settings.repositories ?? 100})
|
||||||
const forks = _forks ? "" : ", isFork: false"
|
const forks = _forks ? "" : ", isFork: false"
|
||||||
const affiliations = _affiliations?.length ? `, ownerAffiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]${conf.authenticated === login ? `, affiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]` : ""}` : ""
|
const affiliations = _affiliations?.length ? `, ownerAffiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]${conf.authenticated === login ? `, affiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]` : ""}` : ""
|
||||||
console.debug(`metrics/compute/${login}/base > affiliations constraints ${affiliations}`)
|
console.debug(`metrics/compute/${login}/base > affiliations constraints ${affiliations}`)
|
||||||
@@ -21,10 +21,6 @@ export default async function({login, graphql, data, q, queries, imports}, conf)
|
|||||||
for (const part of conf.settings.plugins.base.parts)
|
for (const part of conf.settings.plugins.base.parts)
|
||||||
data.base[part] = `base.${part}` in q ? legacy.converter(q[`base.${part}`]) : defaulted
|
data.base[part] = `base.${part}` in q ? legacy.converter(q[`base.${part}`]) : defaulted
|
||||||
|
|
||||||
//Shared options
|
|
||||||
data.shared = {"repositories.skipped":_skipped}
|
|
||||||
console.debug(`metrics/compute/${login}/base > shared options > ${JSON.stringify(data.shared)}`)
|
|
||||||
|
|
||||||
//Iterate through account types
|
//Iterate through account types
|
||||||
for (const account of ["user", "organization"]) {
|
for (const account of ["user", "organization"]) {
|
||||||
try {
|
try {
|
||||||
@@ -53,6 +49,10 @@ export default async function({login, graphql, data, q, queries, imports}, conf)
|
|||||||
data.user[type].nodes.splice(repositories)
|
data.user[type].nodes.splice(repositories)
|
||||||
console.debug(`metrics/compute/${login}/base > loaded ${data.user[type].nodes.length} ${type}`)
|
console.debug(`metrics/compute/${login}/base > loaded ${data.user[type].nodes.length} ${type}`)
|
||||||
}
|
}
|
||||||
|
//Shared options
|
||||||
|
let {"repositories.skipped":skipped, "commits.authoring":authoring} = imports.metadata.plugins.base.inputs({data, q, account:"bypass"})
|
||||||
|
data.shared = {"repositories.skipped":skipped, "commits.authoring":authoring}
|
||||||
|
console.debug(`metrics/compute/${login}/base > shared options > ${JSON.stringify(data.shared)}`)
|
||||||
//Success
|
//Success
|
||||||
console.debug(`metrics/compute/${login}/base > graphql query > account ${account} > success`)
|
console.debug(`metrics/compute/${login}/base > graphql query > account ${account} > success`)
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
Reference in New Issue
Block a user