chore: code formatting
This commit is contained in:
@@ -38,7 +38,7 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
|
|||||||
}
|
}
|
||||||
: null),
|
: null),
|
||||||
}
|
}
|
||||||
const extras = {css: imports.metadata.plugins.core.extras("extras_css", {...conf.settings, error:false}) ? q["extras.css"] ?? "" : "", js: imports.metadata.plugins.core.extras("extras_js", {...conf.settings, error:false}) ? q["extras.js"] ?? "" : ""}
|
const extras = {css: imports.metadata.plugins.core.extras("extras_css", {...conf.settings, error: false}) ? q["extras.css"] ?? "" : "", js: imports.metadata.plugins.core.extras("extras_js", {...conf.settings, error: false}) ? q["extras.js"] ?? "" : ""}
|
||||||
const data = {q, animated: true, large: false, base: {}, config: {}, errors: [], plugins: {}, computed: {}, extras, postscripts: []}
|
const data = {q, animated: true, large: false, base: {}, config: {}, errors: [], plugins: {}, computed: {}, extras, postscripts: []}
|
||||||
const experimental = new Set(decodeURIComponent(q["experimental.features"] ?? "").split(" ").map(x => x.trim().toLocaleLowerCase()).filter(x => x))
|
const experimental = new Set(decodeURIComponent(q["experimental.features"] ?? "").split(" ").map(x => x.trim().toLocaleLowerCase()).filter(x => x))
|
||||||
if (conf.settings["debug.headless"])
|
if (conf.settings["debug.headless"])
|
||||||
@@ -184,7 +184,7 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
|
|||||||
if ((conf.settings?.optimize === true) || (conf.settings?.optimize?.includes?.("svg")))
|
if ((conf.settings?.optimize === true) || (conf.settings?.optimize?.includes?.("svg")))
|
||||||
rendered = await imports.svg.optimize.svg(rendered, q, experimental)
|
rendered = await imports.svg.optimize.svg(rendered, q, experimental)
|
||||||
//Verify svg
|
//Verify svg
|
||||||
if ((verify)&&(imports.metadata.plugins.core.extras("verify", {...conf.settings, error:false}))) {
|
if ((verify) && (imports.metadata.plugins.core.extras("verify", {...conf.settings, error: false}))) {
|
||||||
console.debug(`metrics/compute/${login} > verify SVG`)
|
console.debug(`metrics/compute/${login} > verify SVG`)
|
||||||
let libxmljs = null
|
let libxmljs = null
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
|
|||||||
console.debug(`metrics/extras > ${name} > ${key} > skipping (no error mode)`)
|
console.debug(`metrics/extras > ${name} > ${key} > skipping (no error mode)`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
throw Object.assign(new Error(`Unsupported option "${key}"`), {extras:true})
|
throw Object.assign(new Error(`Unsupported option "${key}"`), {extras: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export default async function({log = true, sandbox = false, community = {}} = {}
|
|||||||
logger("metrics/setup > load package.json > success")
|
logger("metrics/setup > load package.json > success")
|
||||||
|
|
||||||
//Load community templates
|
//Load community templates
|
||||||
if ((conf.settings.extras?.features?.includes("metrics.setup.community.templates"))||(conf.settings.extras?.features === true)||(conf.settings.extras?.default)) {
|
if ((conf.settings.extras?.features?.includes("metrics.setup.community.templates")) || (conf.settings.extras?.features === true) || (conf.settings.extras?.default)) {
|
||||||
if ((typeof conf.settings.community.templates === "string") && (conf.settings.community.templates.length)) {
|
if ((typeof conf.settings.community.templates === "string") && (conf.settings.community.templates.length)) {
|
||||||
logger("metrics/setup > parsing community templates list")
|
logger("metrics/setup > parsing community templates list")
|
||||||
conf.settings.community.templates = [...new Set([...decodeURIComponent(conf.settings.community.templates).split(",").map(v => v.trim().toLocaleLowerCase()).filter(v => v)])]
|
conf.settings.community.templates = [...new Set([...decodeURIComponent(conf.settings.community.templates).split(",").map(v => v.trim().toLocaleLowerCase()).filter(v => v)])]
|
||||||
@@ -194,12 +194,12 @@ export default async function({log = true, sandbox = false, community = {}} = {}
|
|||||||
conf.metadata = await metadata({log})
|
conf.metadata = await metadata({log})
|
||||||
|
|
||||||
//Modes
|
//Modes
|
||||||
if ((!conf.settings.modes)||(!conf.settings.modes.length))
|
if ((!conf.settings.modes) || (!conf.settings.modes.length))
|
||||||
conf.settings.modes = ["embed", "insights"]
|
conf.settings.modes = ["embed", "insights"]
|
||||||
logger(`metrics/setup > setup > enabled modes ${JSON.stringify(conf.settings.modes)}`)
|
logger(`metrics/setup > setup > enabled modes ${JSON.stringify(conf.settings.modes)}`)
|
||||||
|
|
||||||
//Allowed outputs formats
|
//Allowed outputs formats
|
||||||
if ((!conf.settings.outputs)||(!conf.settings.outputs.length))
|
if ((!conf.settings.outputs) || (!conf.settings.outputs.length))
|
||||||
conf.settings.outputs = metadata.inputs.config_output.values
|
conf.settings.outputs = metadata.inputs.config_output.values
|
||||||
else
|
else
|
||||||
conf.settings.outputs = conf.settings.outputs.filter(format => metadata.inputs.config_output.values.includes(format))
|
conf.settings.outputs = conf.settings.outputs.filter(format => metadata.inputs.config_output.values.includes(format))
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ export function formatters({timeZone} = {}) {
|
|||||||
message = `API error: ${status}`
|
message = `API error: ${status}`
|
||||||
|
|
||||||
//Error description (optional)
|
//Error description (optional)
|
||||||
if ((descriptions)&&(descriptions[status]))
|
if ((descriptions) && (descriptions[status]))
|
||||||
message += ` (${descriptions[status]})`
|
message += ` (${descriptions[status]})`
|
||||||
else {
|
else {
|
||||||
const description = error.response?.data?.errors?.[0]?.message ?? error.response.data?.error_description ?? error.response?.data?.message ?? null
|
const description = error.response?.data?.errors?.[0]?.message ?? error.response.data?.error_description ?? error.response?.data?.message ?? null
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ export default async function({sandbox = false} = {}) {
|
|||||||
//Render
|
//Render
|
||||||
const q = req.query
|
const q = req.query
|
||||||
console.debug(`metrics/app/${login} > ${util.inspect(q, {depth: Infinity, maxStringLength: 256})}`)
|
console.debug(`metrics/app/${login} > ${util.inspect(q, {depth: Infinity, maxStringLength: 256})}`)
|
||||||
if ((q["config.presets"]) && ((conf.settings.extras?.features?.includes("metrics.setup.community.presets"))||(conf.settings.extras?.features === true)||(conf.settings.extras?.default))) {
|
if ((q["config.presets"]) && ((conf.settings.extras?.features?.includes("metrics.setup.community.presets")) || (conf.settings.extras?.features === true) || (conf.settings.extras?.default))) {
|
||||||
console.debug(`metrics/app/${login} > presets have been specified, loading them`)
|
console.debug(`metrics/app/${login} > presets have been specified, loading them`)
|
||||||
Object.assign(q, await presets(q["config.presets"]))
|
Object.assign(q, await presets(q["config.presets"]))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
//Methods
|
//Methods
|
||||||
methods:{
|
methods: {
|
||||||
//Metrics insights
|
//Metrics insights
|
||||||
async insights() {
|
async insights() {
|
||||||
window.location.href = `/insights?user=${this.user1}`
|
window.location.href = `/insights?user=${this.user1}`
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
//Metrics embed
|
//Metrics embed
|
||||||
async embed() {
|
async embed() {
|
||||||
window.location.href = `/embed?user=${this.user2}`
|
window.location.href = `/embed?user=${this.user2}`
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export default async function({login, graphql, rest, data, q, queries, imports,
|
|||||||
}
|
}
|
||||||
//Query contributions collection over account lifetime instead of last year
|
//Query contributions collection over account lifetime instead of last year
|
||||||
if (account === "user") {
|
if (account === "user") {
|
||||||
if ((indepth) && (imports.metadata.plugins.base.extras("indepth", {...conf.settings, error:false}))) {
|
if ((indepth) && (imports.metadata.plugins.base.extras("indepth", {...conf.settings, error: false}))) {
|
||||||
const fields = ["totalRepositoriesWithContributedCommits", "totalCommitContributions", "restrictedContributionsCount", "totalIssueContributions", "totalPullRequestContributions", "totalPullRequestReviewContributions"]
|
const fields = ["totalRepositoriesWithContributedCommits", "totalCommitContributions", "restrictedContributionsCount", "totalIssueContributions", "totalPullRequestContributions", "totalPullRequestReviewContributions"]
|
||||||
const start = new Date(data.user.createdAt)
|
const start = new Date(data.user.createdAt)
|
||||||
const end = new Date()
|
const end = new Date()
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw imports.format.error(error, {title:"Screenshot error"})
|
throw imports.format.error(error, {title: "Screenshot error"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export default async function({login, data, computed, imports, q, graphql, queri
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Indepth mode
|
//Indepth mode
|
||||||
if ((indepth)&&(imports.metadata.plugins.followup.extras("indepth", {extras}))) {
|
if ((indepth) && (imports.metadata.plugins.followup.extras("indepth", {extras}))) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > followup > indepth`)
|
console.debug(`metrics/compute/${login}/plugins > followup > indepth`)
|
||||||
followup.indepth = {repositories: {}}
|
followup.indepth = {repositories: {}}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Linguist
|
//Linguist
|
||||||
if ((charts)&&((imports.metadata.plugins.habits.extras("charts", {extras, error:false})))) {
|
if ((charts) && (imports.metadata.plugins.habits.extras("charts", {extras, error: false}))) {
|
||||||
//Check if linguist exists
|
//Check if linguist exists
|
||||||
console.debug(`metrics/compute/${login}/plugins > habits > searching recently used languages using linguist`)
|
console.debug(`metrics/compute/${login}/plugins > habits > searching recently used languages using linguist`)
|
||||||
if (patches.length) {
|
if (patches.length) {
|
||||||
@@ -113,7 +113,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Generating charts with chartist
|
//Generating charts with chartist
|
||||||
if ((_charts === "chartist")&&(imports.metadata.plugins.habits.extras("charts.type", {extras}))) {
|
if ((_charts === "chartist") && (imports.metadata.plugins.habits.extras("charts.type", {extras}))) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > habits > generating charts`)
|
console.debug(`metrics/compute/${login}/plugins > habits > generating charts`)
|
||||||
habits.charts = await Promise.all([
|
habits.charts = await Promise.all([
|
||||||
{type: "line", data: {...empty(24), ...Object.fromEntries(Object.entries(habits.commits.hours).filter(([k]) => !Number.isNaN(+k)))}, low: 0, high: habits.commits.hours.max},
|
{type: "line", data: {...empty(24), ...Object.fromEntries(Object.entries(habits.commits.hours).filter(([k]) => !Number.isNaN(+k)))}, low: 0, high: habits.commits.hours.max},
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Indepth mode
|
//Indepth mode
|
||||||
if ((indepth)&&(imports.metadata.plugins.languages.extras("indepth", {extras}))) {
|
if ((indepth) && (imports.metadata.plugins.languages.extras("indepth", {extras}))) {
|
||||||
//Fetch gpg keys (web-flow is GitHub's public key when making changes from web ui)
|
//Fetch gpg keys (web-flow is GitHub's public key when making changes from web ui)
|
||||||
const gpg = []
|
const gpg = []
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export default async function({login, q, imports, rest, graphql, data, account,
|
|||||||
console.debug(`metrics/compute/${login}/plugins > notable > found ${contributions.length} notable contributions`)
|
console.debug(`metrics/compute/${login}/plugins > notable > found ${contributions.length} notable contributions`)
|
||||||
|
|
||||||
//Indepth
|
//Indepth
|
||||||
if ((indepth)&&(imports.metadata.plugins.notable.extras("indepth", {extras}))) {
|
if ((indepth) && (imports.metadata.plugins.notable.extras("indepth", {extras}))) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > notable > indepth`)
|
console.debug(`metrics/compute/${login}/plugins > notable > indepth`)
|
||||||
|
|
||||||
//Fetch issues
|
//Fetch issues
|
||||||
|
|||||||
@@ -47,13 +47,18 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw imports.format.error(error, {descriptions:{"429":'(consider using "plugin_pagespeed_token")', custom(error) {
|
throw imports.format.error(error, {
|
||||||
|
descriptions: {
|
||||||
|
"429": '(consider using "plugin_pagespeed_token")',
|
||||||
|
custom(error) {
|
||||||
const description = error.response?.data?.error?.message?.match(/Lighthouse returned error: (?<description>[A-Z_]+)/)?.groups?.description ?? null
|
const description = error.response?.data?.error?.message?.match(/Lighthouse returned error: (?<description>[A-Z_]+)/)?.groups?.description ?? null
|
||||||
if (description) {
|
if (description) {
|
||||||
const status = error.response?.status
|
const status = error.response?.status
|
||||||
return `API error: ${status} (${description})`
|
return `API error: ${status} (${description})`
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}}})
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,10 +66,14 @@ export default async function({login, data, imports, graphql, q, queries, accoun
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw imports.format.error(error, {descriptions:{custom(error) {
|
throw imports.format.error(error, {
|
||||||
|
descriptions: {
|
||||||
|
custom(error) {
|
||||||
if (error.errors?.map(({type}) => type)?.includes("INSUFFICIENT_SCOPES"))
|
if (error.errors?.map(({type}) => type)?.includes("INSUFFICIENT_SCOPES"))
|
||||||
return "Insufficient token scopes"
|
return "Insufficient token scopes"
|
||||||
return null
|
return null
|
||||||
}}})
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
|||||||
|
|
||||||
//Generating charts
|
//Generating charts
|
||||||
let charts = null
|
let charts = null
|
||||||
if ((_charts === "chartist")&&(imports.metadata.plugins.stargazers.extras("charts.type", {extras}))) {
|
if ((_charts === "chartist") && (imports.metadata.plugins.stargazers.extras("charts.type", {extras}))) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > stargazers > generating charts`)
|
console.debug(`metrics/compute/${login}/plugins > stargazers > generating charts`)
|
||||||
charts = await Promise.all([{data: total, low: total.min, high: total.max}, {data: increments, ref: 0, low: increments.min, high: increments.max, sign: true}].map(({data: {dates: set}, high, low, ref, sign = false}) =>
|
charts = await Promise.all([{data: total, low: total.min, high: total.max}, {data: increments, ref: 0, low: increments.min, high: increments.max, sign: true}].map(({data: {dates: set}, high, low, ref, sign = false}) =>
|
||||||
imports.chartist("line", {
|
imports.chartist("line", {
|
||||||
|
|||||||
@@ -27,6 +27,6 @@ export default async function({login, imports, data, rest, q, account}, {enabled
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw imports.format.error(error, {descriptions:{"403":"Insufficient token scopes"}})
|
throw imports.format.error(error, {descriptions: {"403": "Insufficient token scopes"}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ describe("GitHub Action", () =>
|
|||||||
if ((skip.includes(template)) || ((modes.length) && (!modes.includes("action"))))
|
if ((skip.includes(template)) || ((modes.length) && (!modes.includes("action"))))
|
||||||
test.skip(name, () => null)
|
test.skip(name, () => null)
|
||||||
else
|
else
|
||||||
test(name, async () => expect(await action.run({template, base: "", query: JSON.stringify(query), plugins_errors_fatal: true, dryrun: true, use_mocked_data: true, verify: true, retries:1, ...input})).toBe(true), timeout)
|
test(name, async () => expect(await action.run({template, base: "", query: JSON.stringify(query), plugins_errors_fatal: true, dryrun: true, use_mocked_data: true, verify: true, retries: 1, ...input})).toBe(true), timeout)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user