Refactor plugins and erros

This commit is contained in:
lowlighter
2020-10-26 19:31:56 +01:00
parent c27d3edaa5
commit c6884b0a86
14 changed files with 810 additions and 1009 deletions

342
action/dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -111,7 +111,7 @@
//Compute rendering //Compute rendering
try { try {
//Render //Render
console.log(req.query) console.debug(`metrics/app/${login} > ${JSON.stringify(req.query)}`)
const rendered = await metrics({login, q:parse(req.query)}, {graphql, rest, plugins, conf}) const rendered = await metrics({login, q:parse(req.query)}, {graphql, rest, plugins, conf})
//Cache //Cache
if ((!debug)&&(cached)) if ((!debug)&&(cached))

View File

@@ -25,14 +25,13 @@
const {query, image, style, fonts} = conf.templates[template] const {query, image, style, fonts} = conf.templates[template]
//Query data from GitHub API //Query data from GitHub API
console.debug(`metrics/compute/${login} > query`) console.debug(`metrics/compute/${login} > graphql query`)
const data = await graphql(query const data = await graphql(query
.replace(/[$]login/, `"${login}"`) .replace(/[$]login/, `"${login}"`)
.replace(/[$]repositories/, `${repositories}`) .replace(/[$]repositories/, `${repositories}`)
.replace(/[$]calendar.to/, `"${(new Date()).toISOString()}"`) .replace(/[$]calendar.to/, `"${(new Date()).toISOString()}"`)
.replace(/[$]calendar.from/, `"${(new Date(Date.now()-14*24*60*60*1000)).toISOString()}"`) .replace(/[$]calendar.from/, `"${(new Date(Date.now()-14*24*60*60*1000)).toISOString()}"`)
) )
console.debug(`metrics/compute/${login} > query > success`)
//Base parts //Base parts
data.base = {} data.base = {}
@@ -41,28 +40,31 @@
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) ? !!q[`base.${part}`] : true data.base[part] = (`base.${part}` in q) ? !!q[`base.${part}`] : true
//Template //Compute metrics
console.debug(`metrics/compute/${login} > compute`) console.debug(`metrics/compute/${login} > compute`)
const computer = Templates[template].default || Templates[template] const computer = Templates[template].default || Templates[template]
await computer({login, q}, {conf, data, rest, graphql, plugins}, {s, pending, imports:{plugins:Plugins, url, imgb64, axios, puppeteer, format, shuffle}}) await computer({login, q}, {conf, data, rest, graphql, plugins}, {s, pending, imports:{plugins:Plugins, url, imgb64, axios, puppeteer, format, shuffle}})
await Promise.all(pending)
console.debug(`metrics/compute/${login} > compute > success`)
//Eval rendering //Promised computed metrics
const promised = await Promise.all(pending)
if (conf.settings.debug)
for (const {name, result = null} of promised)
console.debug(`plugin ${name} ${result ? result.error ? "failed" : "success" : "ignored"} : ${JSON.stringify(result).replace(/^(.{888}).+/, "$1...")}`)
//Template rendering
console.debug(`metrics/compute/${login} > render`) console.debug(`metrics/compute/${login} > render`)
let rendered = await ejs.render(image, {...data, s, style, fonts}, {async:true}) let rendered = await ejs.render(image, {...data, s, style, fonts}, {async:true})
console.debug(`metrics/compute/${login} > render > success`)
//Optimize rendering //Optimize rendering
if ((conf.optimize)&&(!q.raw)) { if ((conf.optimize)&&(!q.raw)) {
console.debug(`metrics/compute/${login} > optimize`) console.debug(`metrics/compute/${login} > optimize`)
const svgo = new SVGO({full:true, plugins:[{cleanupAttrs:true}, {inlineStyles:false}]}) const svgo = new SVGO({full:true, plugins:[{cleanupAttrs:true}, {inlineStyles:false}]})
const {data:optimized} = await svgo.optimize(rendered) const {data:optimized} = await svgo.optimize(rendered)
console.debug(`metrics/compute/${login} > optimize > success`)
rendered = optimized rendered = optimized
} }
//Result //Result
console.debug(`metrics/compute/${login} > success`)
return rendered return rendered
} }
//Internal error //Internal error

View File

@@ -1,15 +1,10 @@
//Setup //Setup
export default function ({login, imports, data, computed, pending, q}, {enabled = false} = {}) { export default async function ({computed, q}, {enabled = false} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.followup = null
if (!q.followup)
return computed.plugins.followup = null
console.debug(`metrics/compute/${login}/plugins > followup`)
//Plugin execution //Plugin execution
pending.push(new Promise(async solve => {
try { try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.followup))
return null
//Define getters //Define getters
const followup = { const followup = {
issues:{ issues:{
@@ -23,18 +18,12 @@
get merged() { return computed.repositories.pr_merged } get merged() { return computed.repositories.pr_merged }
} }
} }
//Save results //Results
computed.plugins.followup = followup return followup
console.debug(`metrics/compute/${login}/plugins > followup > success`)
console.debug(JSON.stringify(computed.plugins.followup))
solve()
} }
//Handle errors
catch (error) { catch (error) {
//Generic error
computed.plugins.followup = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > followup > error`)
console.debug(error) console.debug(error)
solve() throw {error:{message:`An error occured`}}
} }
}))
} }

View File

@@ -1,22 +1,14 @@
//Setup //Setup
export default function ({login, imports, rest, computed, pending, q}, {enabled = false, from:defaults = 100} = {}) { export default async function ({login, rest, q}, {enabled = false, from:defaults = 100} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met //Check if plugin is enabled and requirements are met
if (!enabled) if ((!enabled)||(!q.habits))
return computed.plugins.habits = null return null
if (!q.habits)
return computed.plugins.habits = null
console.debug(`metrics/compute/${login}/plugins > habits`)
//Parameters override //Parameters override
let {"habits.from":from = defaults.from ?? 100} = q let {"habits.from":from = defaults.from ?? 100} = q
//Events //Events
from = Math.max(1, Math.min(100, Number(from))) from = Math.max(1, Math.min(100, Number(from)))
//Debug
console.debug(`metrics/compute/${login}/plugins > habits > ${JSON.stringify({from})}`)
//Plugin execution
pending.push(new Promise(async solve => {
try {
//Initialization //Initialization
const habits = {commits:{hour:NaN, hours:{}}, indents:{style:"", spaces:0, tabs:0}} const habits = {commits:{hour:NaN, hours:{}}, indents:{style:"", spaces:0, tabs:0}}
//Get user recent commits from events //Get user recent commits from events
@@ -31,7 +23,7 @@
for (const hour of hours) for (const hour of hours)
habits.commits.hours[hour] = (habits.commits.hours[hour] ?? 0) + 1 habits.commits.hours[hour] = (habits.commits.hours[hour] ?? 0) + 1
//Compute hour with most commits //Compute hour with most commits
habits.commits.hour = hours.length ? Object.entries(habits.commits.hours).sort(([an, a], [bn, b]) => b - a).map(([hour, occurence]) => hour)[0] : NaN habits.commits.hour = hours.length ? `${Object.entries(habits.commits.hours).sort(([an, a], [bn, b]) => b - a).map(([hour, occurence]) => hour)[0]}`.padStart(2, "0") : NaN
} }
//Indent style //Indent style
{ {
@@ -49,18 +41,12 @@
//Compute indent style //Compute indent style
habits.indents.style = habits.indents.spaces > habits.indents.tabs ? "spaces" : habits.indents.tabs > habits.indents.spaces ? "tabs" : "" habits.indents.style = habits.indents.spaces > habits.indents.tabs ? "spaces" : habits.indents.tabs > habits.indents.spaces ? "tabs" : ""
} }
//Save results //Results
computed.plugins.habits = habits return habits
console.debug(`metrics/compute/${login}/plugins > habits > success`)
console.debug(JSON.stringify(computed.plugins.habits))
solve()
} }
//Handle errors
catch (error) { catch (error) {
//Generic error
computed.plugins.habits = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > habits > error`)
console.debug(error) console.debug(error)
solve() throw {error:{message:`An error occured`}}
} }
}))
} }

View File

@@ -1,21 +1,16 @@
//Setup //Setup
export default function ({login, imports, data, computed, pending, q}, {enabled = false} = {}) { export default async function ({data, q}, {enabled = false} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.languages = null
if (!q.languages)
return computed.plugins.languages = null
console.debug(`metrics/compute/${login}/plugins > languages`)
//Plugin execution //Plugin execution
pending.push(new Promise(async solve => {
try { try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.languages))
return null
//Iterate through user's repositories and retrieve languages data //Iterate through user's repositories and retrieve languages data
const languages = {colors:{}, total:0, stats:{}} const languages = {colors:{}, total:0, stats:{}}
for (const repository of data.user.repositories.nodes) { for (const repository of data.user.repositories.nodes) {
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) { for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
languages.stats[name] = (languages.stats[name] || 0) + size languages.stats[name] = (languages.stats[name] ?? 0) + size
languages.colors[name] = color || "#ededed" languages.colors[name] = color ?? "#ededed"
languages.total += size languages.total += size
} }
} }
@@ -24,18 +19,12 @@
languages.favorites = Object.entries(languages.stats).sort(([an, a], [bn, b]) => b - a).slice(0, 8).map(([name, value]) => ({name, value, color:languages.colors[name], x:0})) languages.favorites = Object.entries(languages.stats).sort(([an, a], [bn, b]) => b - a).slice(0, 8).map(([name, value]) => ({name, value, color:languages.colors[name], x:0}))
for (let i = 1; i < languages.favorites.length; i++) for (let i = 1; i < languages.favorites.length; i++)
languages.favorites[i].x = languages.favorites[i-1].x + languages.favorites[i-1].value languages.favorites[i].x = languages.favorites[i-1].x + languages.favorites[i-1].value
//Save results //Results
computed.plugins.languages = languages return languages
console.debug(`metrics/compute/${login}/plugins > languages > success`)
console.debug(JSON.stringify(computed.plugins.languages))
solve()
} }
//Handle errors
catch (error) { catch (error) {
//Generic error
computed.plugins.languages = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > languages > error`)
console.debug(error) console.debug(error)
solve() throw {error:{message:`An error occured`}}
} }
}))
} }

View File

@@ -1,15 +1,12 @@
//Setup //Setup
export default function ({login, imports, repositories = [], rest, computed, pending, q}, {enabled = false} = {}) { export default async function ({login, data, imports, rest, q}, {enabled = false} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.lines = null
if (!q.lines)
return computed.plugins.lines = null
console.debug(`metrics/compute/${login}/plugins > lines`)
//Plugin execution //Plugin execution
pending.push(new Promise(async solve => {
try { try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.lines))
return null
//Repositories
const repositories = data.user.repositories.nodes.map(({name}) => name) ?? []
//Get contributors stats from repositories //Get contributors stats from repositories
const lines = {added:0, deleted:0} const lines = {added:0, deleted:0}
const response = await Promise.all(repositories.map(async repo => await rest.repos.getContributorsStats({owner:login, repo}))) const response = await Promise.all(repositories.map(async repo => await rest.repos.getContributorsStats({owner:login, repo})))
@@ -27,19 +24,13 @@
//Format values //Format values
lines.added = imports.format(lines.added) lines.added = imports.format(lines.added)
lines.deleted = imports.format(lines.deleted) lines.deleted = imports.format(lines.deleted)
//Save results //Results
computed.plugins.lines = {...lines} return lines
console.debug(`metrics/compute/${login}/plugins > lines > success`)
console.debug(JSON.stringify(computed.plugins.lines))
solve()
} }
//Handle errors
catch (error) { catch (error) {
//Generic error
computed.plugins.lines = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > lines > error`)
console.debug(error) console.debug(error)
solve() throw {error:{message:`An error occured`}}
} }
}))
} }

View File

@@ -17,19 +17,21 @@
} }
//Setup //Setup
export default function ({login, imports, rest, computed, pending, q}, {enabled = false, token = ""} = {}) { export default async function ({login, imports, q}, {enabled = false, token = ""} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met //Check if plugin is enabled and requirements are met
if (!enabled) if ((!enabled)||(!q.music))
return computed.plugins.music = null return null
if (!q.music)
return computed.plugins.music = null //Initialization
console.debug(`metrics/compute/${login}/plugins > music`)
const raw = { const raw = {
get provider() { return providers[provider]?.name ?? "" }, get provider() { return providers[provider]?.name ?? "" },
get mode() { return modes[mode] ?? "Unconfigured music plugin"}, get mode() { return modes[mode] ?? "Unconfigured music plugin"},
} }
let tracks = null
//Parameters override and checks //Parameters override
let {"music.provider":provider = "", "music.mode":mode = "", "music.playlist":playlist = null, "music.limit":limit = 4} = q let {"music.provider":provider = "", "music.mode":mode = "", "music.playlist":playlist = null, "music.limit":limit = 4} = q
//Auto-guess parameters //Auto-guess parameters
if ((playlist)&&(!mode)) if ((playlist)&&(!mode))
@@ -42,28 +44,20 @@
mode = "recent" mode = "recent"
//Provider //Provider
if (!(provider in providers)) if (!(provider in providers))
return computed.plugins.music = {...raw, error:provider ? `Unsupported provider "${provider}"` : `Missing provider`} throw {error:{message:provider ? `Unsupported provider "${provider}"` : `Missing provider`}, ...raw}
//Mode //Mode
if (!(mode in modes)) if (!(mode in modes))
return computed.plugins.music = {...raw, error:`Unsupported mode "${mode}"`} throw {error:{message:`Unsupported mode "${mode}"`}, ...raw}
//Playlist mode //Playlist mode
if (mode === "playlist") { if (mode === "playlist") {
if (!playlist) if (!playlist)
return computed.plugins.music = {...raw, error:`Missing playlist url`} throw {error:{message:`Missing playlist url`}, ...raw}
if (!providers[provider].embed.test(playlist)) if (!providers[provider].embed.test(playlist))
return computed.plugins.music = {...raw, error:`Unsupported playlist url format`} throw {error:{message:`Unsupported playlist url format`}, ...raw}
} }
//Limit //Limit
limit = Math.max(1, Math.min(100, Number(limit))) limit = Math.max(1, Math.min(100, Number(limit)))
//Debug
console.debug(`metrics/compute/${login}/plugins > habits > ${JSON.stringify({provider, mode, playlist, limit})}`)
//Plugin execution
pending.push(new Promise(async solve => {
//Retrieve music data
try {
//Initialization
let tracks = null
//Handle mode //Handle mode
switch (mode) { switch (mode) {
//Playlist mode //Playlist mode
@@ -102,9 +96,8 @@
break break
} }
//Unsupported //Unsupported
default:{ default:
throw {status:`Unsupported mode "${mode}" for provider "${provider}"`} throw {error:{message:`Unsupported mode "${mode}" for provider "${provider}"`}, ...raw}
}
} }
//Close browser //Close browser
console.debug(`metrics/compute/${login}/plugins > music > closing browser`) console.debug(`metrics/compute/${login}/plugins > music > closing browser`)
@@ -130,7 +123,7 @@
//Prepare credentials //Prepare credentials
const [client_id, client_secret, refresh_token] = token.split(",").map(part => part.trim()) const [client_id, client_secret, refresh_token] = token.split(",").map(part => part.trim())
if ((!client_id)||(!client_secret)||(!refresh_token)) if ((!client_id)||(!client_secret)||(!refresh_token))
throw {status:`Spotify token must contain client id/secret and refresh token`} throw {error:`Spotify token must contain client id/secret and refresh token`}
//API call and parse tracklist //API call and parse tracklist
try { try {
//Request access token //Request access token
@@ -154,24 +147,21 @@
} }
//Handle errors //Handle errors
catch (error) { catch (error) {
console.debug(error) if ((error.response?.status))
if ((error.response)&&(error.response.status)) throw {error:{message:`API returned ${error.response.status}`}, ...raw}
throw {status:`API call returned ${error.response.status}`}
throw error throw error
} }
break break
} }
//Unsupported //Unsupported
default:{ default:
throw {status:`Unsupported mode "${mode}" for provider "${provider}"`} throw {error:{message:`Unsupported mode "${mode}" for provider "${provider}"`}, ...raw}
}
} }
break break
} }
//Unsupported //Unsupported
default:{ default:
throw {status:`Unsupported mode "${mode}"`} throw {error:{message:`Unsupported mode "${mode}"`}, ...raw}
}
} }
//Format tracks //Format tracks
if (Array.isArray(tracks)) { if (Array.isArray(tracks)) {
@@ -188,25 +178,16 @@
} }
//Save results //Save results
console.debug(`metrics/compute/${login}/plugins > music > success`) console.debug(`metrics/compute/${login}/plugins > music > success`)
computed.plugins.music = {...raw, tracks} return {...raw, tracks}
solve()
return
} }
//Unhandled error //Unhandled error
throw {status:`An error occured (unhandled)`} throw {error:{message:`An error occured (could not retrieve tracks)`}}
} }
//Handle errors
catch (error) { catch (error) {
//Plugin error if (error.error?.message)
if (error.status) { throw error
computed.plugins.music = {...raw, error:error.status}
console.debug(`metrics/compute/${login}/plugins > music > error > ${error.status}`)
return solve()
}
//Generic error
computed.plugins.music = {...raw, error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > music > error`)
console.debug(error) console.debug(error)
solve() throw {error:{message:`An error occured`}}
} }
}))
} }

View File

@@ -1,18 +1,12 @@
//Setup //Setup
export default function ({login, imports, url, computed, pending, q}, {enabled = false, token = null} = {}) { export default async function ({imports, data, q}, {enabled = false, token = null} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.pagespeed = null
if (!url)
return computed.plugins.pagespeed = null
if (!q.pagespeed)
return computed.plugins.pagespeed = null
console.debug(`metrics/compute/${login}/plugins > pagespeed`)
//Plugin execution //Plugin execution
pending.push(new Promise(async solve => {
try { try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.pagespeed)||(!data.user.websiteUrl))
return null
//Format url if needed //Format url if needed
let url = data.user.websiteUrl
if (!/^https?:[/][/]/.test(url)) if (!/^https?:[/][/]/.test(url))
url = `https://${url}` url = `https://${url}`
//Load scores from API //Load scores from API
@@ -21,24 +15,13 @@
const {score, title} = (await imports.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=${category}&url=${url}&key=${token}`)).data.lighthouseResult.categories[category] const {score, title} = (await imports.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=${category}&url=${url}&key=${token}`)).data.lighthouseResult.categories[category]
scores.set(category, {score, title}) scores.set(category, {score, title})
})) }))
//Save results //Results
computed.plugins.pagespeed = {url, scores:[scores.get("performance"), scores.get("accessibility"), scores.get("best-practices"), scores.get("seo")]} return {url, scores:[scores.get("performance"), scores.get("accessibility"), scores.get("best-practices"), scores.get("seo")]}
console.debug(`metrics/compute/${login}/plugins > pagespeed > success`)
console.debug(JSON.stringify(computed.plugins.pagespeed))
solve()
} }
//Handle errors
catch (error) { catch (error) {
//Thrown when token is incorrect if (error.response?.status)
if ((error.response)&&(error.response.status)) { throw {error:{message:`PageSpeed token error (code ${error.response.status})`}, url}
computed.plugins.pagespeed = {url, error:`PageSpeed token error (code ${error.response.status})`} throw {error:{message:`An error occured`}}
console.debug(`metrics/plugins/pagespeed/${login} > ${error.response.status}`)
return solve()
} }
//Generic error
computed.plugins.pagespeed = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > pagespeed > error`)
console.debug(error)
solve()
}
}))
} }

View File

@@ -1,15 +1,10 @@
//Setup //Setup
export default function ({login, imports, rest, computed, pending, q}, {enabled = false} = {}) { export default async function ({login, rest, computed, q}, {enabled = false} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.selfskip = null
if (!q.selfskip)
return computed.plugins.selfskip = null
console.debug(`metrics/compute/${login}/plugins > selfskip`)
//Plugin execution //Plugin execution
pending.push(new Promise(async solve => {
try { try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.selfskip))
return null
//Search for auto-generated commits //Search for auto-generated commits
let commits = 0 let commits = 0
for (let page = 0;;page++) { for (let page = 0;;page++) {
@@ -18,19 +13,13 @@
if (!data.length) if (!data.length)
break break
} }
//Save results //Results
computed.plugins.selfskip = {commits}
computed.commits -= commits computed.commits -= commits
console.debug(`metrics/compute/${login}/plugins > selfskip > success`) return {commits}
console.debug(JSON.stringify(computed.plugins.selfskip))
solve()
} }
//Handle errors
catch (error) { catch (error) {
//Generic error
computed.plugins.selfskip = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > selfskip > error`)
console.debug(error) console.debug(error)
solve() throw {error:{message:`An error occured`}}
} }
}))
} }

View File

@@ -1,15 +1,12 @@
//Setup //Setup
export default function ({login, imports, repositories = [], rest, computed, pending, q}, {enabled = false} = {}) { export default async function ({login, imports, data, rest, q}, {enabled = false} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.traffic = null
if (!q.traffic)
return computed.plugins.traffic = null
console.debug(`metrics/compute/${login}/plugins > traffic`)
//Plugin execution //Plugin execution
pending.push(new Promise(async solve => {
try { try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.traffic))
return null
//Repositories
const repositories = data.user.repositories.nodes.map(({name}) => name) ?? []
//Get views stats from repositories //Get views stats from repositories
const views = {count:0, uniques:0} const views = {count:0, uniques:0}
const response = await Promise.all(repositories.map(async repo => await rest.repos.getViews({owner:login, repo}))) const response = await Promise.all(repositories.map(async repo => await rest.repos.getViews({owner:login, repo})))
@@ -18,24 +15,14 @@
//Format values //Format values
views.count = imports.format(views.count) views.count = imports.format(views.count)
views.uniques = imports.format(views.uniques) views.uniques = imports.format(views.uniques)
//Save results //Results
computed.plugins.traffic = {views} return {views}
console.debug(`metrics/compute/${login}/plugins > traffic > success`)
console.debug(JSON.stringify(computed.plugins.traffic))
solve()
} }
//Handle errors
catch (error) { catch (error) {
//Thrown when token has unsufficient permissions if (error.status === 403)
if (error.status === 403) { throw {error:{message:`Insufficient token rights`}}
computed.plugins.traffic = {error:`Insufficient token rights`}
console.debug(`metrics/compute/${login}/plugins > error > 403 (insufficient token rights)`)
return solve()
}
//Generic error
computed.plugins.traffic = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > error`)
console.debug(error) console.debug(error)
solve() throw {error:{message:`An error occured`}}
} }
}))
} }

View File

@@ -144,7 +144,7 @@
<div class="field <%= computed.plugins.lines.error ? 'error' : '' %>"> <div class="field <%= computed.plugins.lines.error ? 'error' : '' %>">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.72 3.22a.75.75 0 011.06 1.06L2.06 8l3.72 3.72a.75.75 0 11-1.06 1.06L.47 8.53a.75.75 0 010-1.06l4.25-4.25zm6.56 0a.75.75 0 10-1.06 1.06L13.94 8l-3.72 3.72a.75.75 0 101.06 1.06l4.25-4.25a.75.75 0 000-1.06l-4.25-4.25z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.72 3.22a.75.75 0 011.06 1.06L2.06 8l3.72 3.72a.75.75 0 11-1.06 1.06L.47 8.53a.75.75 0 010-1.06l4.25-4.25zm6.56 0a.75.75 0 10-1.06 1.06L13.94 8l-3.72 3.72a.75.75 0 101.06 1.06l4.25-4.25a.75.75 0 000-1.06l-4.25-4.25z"></path></svg>
<% if (computed.plugins.lines.error) { %> <% if (computed.plugins.lines.error) { %>
<%= computed.plugins.lines.error %> <%= computed.plugins.lines.error.message %>
<% } else { %> <% } else { %>
<%= computed.plugins.lines.added %> added, <%= computed.plugins.lines.deleted %> removed <%= computed.plugins.lines.added %> added, <%= computed.plugins.lines.deleted %> removed
<% } %> <% } %>
@@ -168,7 +168,7 @@
<div class="field <%= computed.plugins.traffic.error ? 'error' : '' %>"> <div class="field <%= computed.plugins.traffic.error ? 'error' : '' %>">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M0 1.75A.75.75 0 01.75 1h4.253c1.227 0 2.317.59 3 1.501A3.744 3.744 0 0111.006 1h4.245a.75.75 0 01.75.75v10.5a.75.75 0 01-.75.75h-4.507a2.25 2.25 0 00-1.591.659l-.622.621a.75.75 0 01-1.06 0l-.622-.621A2.25 2.25 0 005.258 13H.75a.75.75 0 01-.75-.75V1.75zm8.755 3a2.25 2.25 0 012.25-2.25H14.5v9h-3.757c-.71 0-1.4.201-1.992.572l.004-7.322zm-1.504 7.324l.004-5.073-.002-2.253A2.25 2.25 0 005.003 2.5H1.5v9h3.757a3.75 3.75 0 011.994.574z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M0 1.75A.75.75 0 01.75 1h4.253c1.227 0 2.317.59 3 1.501A3.744 3.744 0 0111.006 1h4.245a.75.75 0 01.75.75v10.5a.75.75 0 01-.75.75h-4.507a2.25 2.25 0 00-1.591.659l-.622.621a.75.75 0 01-1.06 0l-.622-.621A2.25 2.25 0 005.258 13H.75a.75.75 0 01-.75-.75V1.75zm8.755 3a2.25 2.25 0 012.25-2.25H14.5v9h-3.757c-.71 0-1.4.201-1.992.572l.004-7.322zm-1.504 7.324l.004-5.073-.002-2.253A2.25 2.25 0 005.003 2.5H1.5v9h3.757a3.75 3.75 0 011.994.574z"></path></svg>
<% if (computed.plugins.traffic.error) { %> <% if (computed.plugins.traffic.error) { %>
<%= computed.plugins.traffic.error %> <%= computed.plugins.traffic.error.message %>
<% } else { %> <% } else { %>
<%= computed.plugins.traffic.views.count %> view<%= s(computed.plugins.traffic.views.count) %> in last two weeks <%= computed.plugins.traffic.views.count %> view<%= s(computed.plugins.traffic.views.count) %> in last two weeks
<% } %> <% } %>
@@ -188,7 +188,7 @@
<section> <section>
<div class="field error"> <div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg>
<%= computed.plugins.followup.error %> <%= computed.plugins.followup.error.message %>
</div> </div>
</section> </section>
<% } else { %> <% } else { %>
@@ -219,7 +219,7 @@
<section> <section>
<div class="field error"> <div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg>
<%= computed.plugins.followup.error %> <%= computed.plugins.followup.error.message %>
</div> </div>
</section> </section>
<% } else { %> <% } else { %>
@@ -254,7 +254,7 @@
<section> <section>
<div class="field error"> <div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg>
<%= computed.plugins.languages.error %> <%= computed.plugins.languages.error.message %>
</div> </div>
</section> </section>
<% } else { %> <% } else { %>
@@ -297,7 +297,7 @@
<section> <section>
<div class="field error"> <div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg>
<%= computed.plugins.pagespeed.error %> <%= computed.plugins.pagespeed.error.message %>
</div> </div>
</section> </section>
</div> </div>
@@ -336,7 +336,7 @@
<section> <section>
<div class="field error"> <div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg>
<%= computed.plugins.habits.error %> <%= computed.plugins.habits.error.message %>
</div> </div>
</section> </section>
<% } else { %> <% } else { %>
@@ -370,7 +370,7 @@
<% if (computed.plugins.music.error) { %> <% if (computed.plugins.music.error) { %>
<div class="field error"> <div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"></path></svg>
<%= computed.plugins.music.error %> <%= computed.plugins.music.error.message %>
</div> </div>
<% } else { %> <% } else { %>
<% if (computed.plugins.music.tracks.length) { %> <% if (computed.plugins.music.tracks.length) { %>

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -6,15 +6,19 @@
const avatar = imports.imgb64(data.user.avatarUrl) const avatar = imports.imgb64(data.user.avatarUrl)
//Plugins //Plugins
if (data.user.websiteUrl) for (const name of Object.keys(imports.plugins)) {
imports.plugins.pagespeed({login, imports, url:data.user.websiteUrl, computed, pending, q}, plugins.pagespeed) pending.push((async () => {
imports.plugins.music({login, imports, data, computed, pending, q}, plugins.music) try {
imports.plugins.lines({login, imports, repositories:data.user.repositories.nodes.map(({name}) => name), rest, computed, pending, q}, plugins.lines) computed.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql}, plugins[name])
imports.plugins.traffic({login, imports, repositories:data.user.repositories.nodes.map(({name}) => name), rest, computed, pending, q}, plugins.traffic) }
imports.plugins.habits({login, imports, rest, computed, pending, q}, plugins.habits) catch (error) {
imports.plugins.selfskip({login, imports, rest, computed, pending, q}, plugins.selfskip) computed.plugins[name] = error
imports.plugins.languages({login, imports, data, computed, pending, q}, plugins.languages) }
imports.plugins.followup({login, imports, data, computed, pending, q}, plugins.followup) finally {
return {name, result:computed.plugins[name]}
}
})())
}
//Iterate through user's repositories //Iterate through user's repositories
for (const repository of data.user.repositories.nodes) { for (const repository of data.user.repositories.nodes) {

View File

@@ -99,7 +99,7 @@ Last generated: <%= new Date().toGMTString() %>
<div class="stdout"><%# -%> <div class="stdout"><%# -%>
Total <%= user.repositories.totalCount %> repositor<%= s(user.repositories.totalCount, "y") %> Total <%= user.repositories.totalCount %> repositor<%= s(user.repositories.totalCount, "y") %>
<% if (computed.plugins.traffic) { if (computed.plugins.traffic.error) { -%> <% if (computed.plugins.traffic) { if (computed.plugins.traffic.error) { -%>
---- <b> </b> views <span class="error">(<%= computed.plugins.traffic.error %>)</span> ---- <b> </b> views <span class="error">(<%= computed.plugins.traffic.error.message %>)</span>
<% } else { -%> <% } else { -%>
-r-- <b><%= `${computed.plugins.traffic.views.count}`.padStart(5) %></b> views -r-- <b><%= `${computed.plugins.traffic.views.count}`.padStart(5) %></b> views
<% }} -%> <% }} -%>
@@ -109,8 +109,8 @@ Total <%= user.repositories.totalCount %> repositor<%= s(user.repositories.total
dr-x <b><%= `${user.packages.totalCount}`.padStart(5) %></b> package<%= s(user.packages.totalCount) %> dr-x <b><%= `${user.packages.totalCount}`.padStart(5) %></b> package<%= s(user.packages.totalCount) %>
dr-x <b><%= `${user.gists.totalCount}`.padStart(5) %></b> gist<%= s(user.gists.totalCount) %> dr-x <b><%= `${user.gists.totalCount}`.padStart(5) %></b> gist<%= s(user.gists.totalCount) %>
<% if (computed.plugins.followup) { if (computed.plugins.followup.error) { -%> <% if (computed.plugins.followup) { if (computed.plugins.followup.error) { -%>
d--- <b> </b> ISSUES <span class="error">(<%= computed.plugins.followup.error %>)</span> d--- <b> </b> ISSUES <span class="error">(<%= computed.plugins.followup.error.message %>)</span>
d--- <b> </b> PULL_REQUESTS <span class="error">(<%= computed.plugins.followup.error %>)</span> d--- <b> </b> PULL_REQUESTS <span class="error">(<%= computed.plugins.followup.error.message %>)</span>
<% } else { -%> <% } else { -%>
dr-x <b><%= `${computed.plugins.followup.issues.count}`.padStart(5) %></b> ISSUES dr-x <b><%= `${computed.plugins.followup.issues.count}`.padStart(5) %></b> ISSUES
-r-- <b><%= `${computed.plugins.followup.issues.open}`.padStart(5) %></b> ├── open -r-- <b><%= `${computed.plugins.followup.issues.open}`.padStart(5) %></b> ├── open
@@ -124,7 +124,7 @@ dr-x LICENSE
-r-- └── <%= computed.licenses.favorite %> -r-- └── <%= computed.licenses.favorite %>
<% } -%> <% } -%>
<% if (computed.plugins.lines) { if (computed.plugins.lines.error) { %> <% if (computed.plugins.lines) { if (computed.plugins.lines.error) { %>
<span class="diff error">@@ <%= computed.plugins.lines.error %> @@</span><% } else { %> <span class="diff error">@@ <%= computed.plugins.lines.error.message %> @@</span><% } else { %>
<span class="diff">@@ -<%= computed.plugins.lines.deleted %> +<%= computed.plugins.lines.added %> @@</span> <span class="diff">@@ -<%= computed.plugins.lines.deleted %> +<%= computed.plugins.lines.added %> @@</span>
<% }} -%> <% }} -%>
</div><% } -%> </div><% } -%>
@@ -133,7 +133,7 @@ dr-x LICENSE
<div class="stdin"><%- meta.$ %> locale</div><%# -%> <div class="stdin"><%- meta.$ %> locale</div><%# -%>
<div class="stdout"><%# -%> <div class="stdout"><%# -%>
<% if (computed.plugins.languages.error) { -%> <% if (computed.plugins.languages.error) { -%>
<span class="error"><%= computed.plugins.languages.error %></span><%# -%> <span class="error"><%= computed.plugins.languages.error.message %></span><%# -%>
<% } else { for (const {name, value} of computed.plugins.languages.favorites) { -%> <% } else { for (const {name, value} of computed.plugins.languages.favorites) { -%>
<b><%= name.toLocaleUpperCase().padEnd(12) %></b> [<%= "#".repeat(Math.ceil(100*value/5)).padEnd(20) %>] <%= (100*value).toFixed(2).padEnd(5) %>% <b><%= name.toLocaleUpperCase().padEnd(12) %></b> [<%= "#".repeat(Math.ceil(100*value/5)).padEnd(20) %>] <%= (100*value).toFixed(2).padEnd(5) %>%
<% }} -%> <% }} -%>
@@ -143,7 +143,7 @@ dr-x LICENSE
<div class="stdin"><%- meta.$ %> curl -I <%= user.websiteUrl %></div><%# -%> <div class="stdin"><%- meta.$ %> curl -I <%= user.websiteUrl %></div><%# -%>
<div class="stdout"><%# -%> <div class="stdout"><%# -%>
<% if (computed.plugins.pagespeed.error) { -%> <% if (computed.plugins.pagespeed.error) { -%>
<span class="error"><%= computed.plugins.pagespeed.error %></span><% } else { -%> <span class="error"><%= computed.plugins.pagespeed.error.message %></span><% } else { -%>
<b>User-Agent</b>: Google PageSpeed API <b>User-Agent</b>: Google PageSpeed API
<b>Location</b>: <%= user.websiteUrl %> <b>Location</b>: <%= user.websiteUrl %>
<% for (const {score, title} of computed.plugins.pagespeed.scores) { -%> <% for (const {score, title} of computed.plugins.pagespeed.scores) { -%>

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB