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

898
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,40 +1,29 @@
//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
//Define getters if ((!enabled)||(!q.followup))
const followup = { return null
issues:{ //Define getters
get count() { return this.open + this.closed }, const followup = {
get open() { return computed.repositories.issues_open }, issues:{
get closed() { return computed.repositories.issues_closed }, get count() { return this.open + this.closed },
}, get open() { return computed.repositories.issues_open },
pr:{ get closed() { return computed.repositories.issues_closed },
get count() { return this.open + this.merged }, },
get open() { return computed.repositories.pr_open }, pr:{
get merged() { return computed.repositories.pr_merged } get count() { return this.open + this.merged },
} get open() { return computed.repositories.pr_open },
get merged() { return computed.repositories.pr_merged }
} }
//Save results }
computed.plugins.followup = followup //Results
console.debug(`metrics/compute/${login}/plugins > followup > success`) return followup
console.debug(JSON.stringify(computed.plugins.followup)) }
solve() //Handle errors
} catch (error) {
catch (error) { console.debug(error)
//Generic error throw {error:{message:`An error occured`}}
computed.plugins.followup = {error:`An error occured`} }
console.debug(`metrics/compute/${login}/plugins > followup > error`)
console.debug(error)
solve()
}
}))
} }

View File

@@ -1,66 +1,52 @@
//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} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.habits = null
if (!q.habits)
return computed.plugins.habits = null
console.debug(`metrics/compute/${login}/plugins > habits`)
//Parameters override
let {"habits.from":from = defaults.from ?? 100} = q
//Events
from = Math.max(1, Math.min(100, Number(from)))
//Debug
console.debug(`metrics/compute/${login}/plugins > habits > ${JSON.stringify({from})}`)
//Plugin execution //Plugin execution
pending.push(new Promise(async solve => { try {
try { //Check if plugin is enabled and requirements are met
//Initialization if ((!enabled)||(!q.habits))
const habits = {commits:{hour:NaN, hours:{}}, indents:{style:"", spaces:0, tabs:0}} return null
//Get user recent commits from events //Parameters override
const events = await rest.activity.listEventsForAuthenticatedUser({username:login, per_page:from}) let {"habits.from":from = defaults.from ?? 100} = q
const commits = events.data //Events
.filter(({type}) => type === "PushEvent") from = Math.max(1, Math.min(100, Number(from)))
.filter(({actor}) => actor.login === login) //Initialization
//Commit hour const habits = {commits:{hour:NaN, hours:{}}, indents:{style:"", spaces:0, tabs:0}}
{ //Get user recent commits from events
//Compute commit hours const events = await rest.activity.listEventsForAuthenticatedUser({username:login, per_page:from})
const hours = commits.map(({created_at}) => (new Date(created_at)).getHours()) const commits = events.data
for (const hour of hours) .filter(({type}) => type === "PushEvent")
habits.commits.hours[hour] = (habits.commits.hours[hour] ?? 0) + 1 .filter(({actor}) => actor.login === login)
//Compute hour with most commits //Commit hour
habits.commits.hour = hours.length ? Object.entries(habits.commits.hours).sort(([an, a], [bn, b]) => b - a).map(([hour, occurence]) => hour)[0] : NaN {
} //Compute commit hours
//Indent style const hours = commits.map(({created_at}) => (new Date(created_at)).getHours())
{ for (const hour of hours)
//Retrieve edited files habits.commits.hours[hour] = (habits.commits.hours[hour] ?? 0) + 1
const edited = await Promise.allSettled(commits //Compute hour with most commits
.flatMap(({payload}) => payload.commits).map(commit => commit.url) 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
.map(async commit => (await rest.request(commit)).data.files) }
) //Indent style
//Attemp to guess whether tabs or spaces are used from patch {
edited //Retrieve edited files
.filter(({status}) => status === "fulfilled") const edited = await Promise.allSettled(commits
.map(({value}) => value) .flatMap(({payload}) => payload.commits).map(commit => commit.url)
.flatMap(files => files.flatMap(file => (file.patch ?? "").match(/(?<=^[+])((?:\t)|(?: )) /gm) ?? [])) .map(async commit => (await rest.request(commit)).data.files)
.forEach(indent => habits.indents[/^\t/.test(indent) ? "tabs" : "spaces"]++) )
//Compute indent style //Attemp to guess whether tabs or spaces are used from patch
habits.indents.style = habits.indents.spaces > habits.indents.tabs ? "spaces" : habits.indents.tabs > habits.indents.spaces ? "tabs" : "" edited
} .filter(({status}) => status === "fulfilled")
//Save results .map(({value}) => value)
computed.plugins.habits = habits .flatMap(files => files.flatMap(file => (file.patch ?? "").match(/(?<=^[+])((?:\t)|(?: )) /gm) ?? []))
console.debug(`metrics/compute/${login}/plugins > habits > success`) .forEach(indent => habits.indents[/^\t/.test(indent) ? "tabs" : "spaces"]++)
console.debug(JSON.stringify(computed.plugins.habits)) //Compute indent style
solve() habits.indents.style = habits.indents.spaces > habits.indents.tabs ? "spaces" : habits.indents.tabs > habits.indents.spaces ? "tabs" : ""
} }
catch (error) { //Results
//Generic error return habits
computed.plugins.habits = {error:`An error occured`} }
console.debug(`metrics/compute/${login}/plugins > habits > error`) //Handle errors
console.debug(error) catch (error) {
solve() console.debug(error)
} throw {error:{message:`An error occured`}}
})) }
} }

View File

@@ -1,41 +1,30 @@
//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
//Iterate through user's repositories and retrieve languages data if ((!enabled)||(!q.languages))
const languages = {colors:{}, total:0, stats:{}} return null
for (const repository of data.user.repositories.nodes) { //Iterate through user's repositories and retrieve languages data
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) { const languages = {colors:{}, total:0, stats:{}}
languages.stats[name] = (languages.stats[name] || 0) + size for (const repository of data.user.repositories.nodes) {
languages.colors[name] = color || "#ededed" for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
languages.total += size languages.stats[name] = (languages.stats[name] ?? 0) + size
} languages.colors[name] = color ?? "#ededed"
languages.total += size
} }
//Compute languages stats }
Object.keys(languages.stats).map(name => languages.stats[name] /= languages.total) //Compute languages stats
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})) Object.keys(languages.stats).map(name => languages.stats[name] /= languages.total)
for (let i = 1; i < languages.favorites.length; i++) 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[i].x = languages.favorites[i-1].x + languages.favorites[i-1].value for (let i = 1; i < languages.favorites.length; i++)
//Save results languages.favorites[i].x = languages.favorites[i-1].x + languages.favorites[i-1].value
computed.plugins.languages = languages //Results
console.debug(`metrics/compute/${login}/plugins > languages > success`) return languages
console.debug(JSON.stringify(computed.plugins.languages)) }
solve() //Handle errors
} catch (error) {
catch (error) { console.debug(error)
//Generic error throw {error:{message:`An error occured`}}
computed.plugins.languages = {error:`An error occured`} }
console.debug(`metrics/compute/${login}/plugins > languages > error`)
console.debug(error)
solve()
}
}))
} }

View File

@@ -1,45 +1,36 @@
//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
//Get contributors stats from repositories if ((!enabled)||(!q.lines))
const lines = {added:0, deleted:0} return null
const response = await Promise.all(repositories.map(async repo => await rest.repos.getContributorsStats({owner:login, repo}))) //Repositories
//Compute changed lines const repositories = data.user.repositories.nodes.map(({name}) => name) ?? []
response.map(({data:repository}) => { //Get contributors stats from repositories
//Check if data are available const lines = {added:0, deleted:0}
if (!Array.isArray(repository)) const response = await Promise.all(repositories.map(async repo => await rest.repos.getContributorsStats({owner:login, repo})))
return //Compute changed lines
//Extract author response.map(({data:repository}) => {
const [contributor] = repository.filter(({author}) => author.login === login) //Check if data are available
//Compute editions if (!Array.isArray(repository))
if (contributor) return
contributor.weeks.forEach(({a, d}) => (lines.added += a, lines.deleted += d)) //Extract author
}) const [contributor] = repository.filter(({author}) => author.login === login)
//Format values //Compute editions
lines.added = imports.format(lines.added) if (contributor)
lines.deleted = imports.format(lines.deleted) contributor.weeks.forEach(({a, d}) => (lines.added += a, lines.deleted += d))
//Save results })
computed.plugins.lines = {...lines} //Format values
console.debug(`metrics/compute/${login}/plugins > lines > success`) lines.added = imports.format(lines.added)
console.debug(JSON.stringify(computed.plugins.lines)) lines.deleted = imports.format(lines.deleted)
solve() //Results
} return lines
catch (error) { }
//Generic error //Handle errors
computed.plugins.lines = {error:`An error occured`} catch (error) {
console.debug(`metrics/compute/${login}/plugins > lines > error`) console.debug(error)
console.debug(error) throw {error:{message:`An error occured`}}
solve() }
}
}))
} }

View File

@@ -17,196 +17,177 @@
} }
//Setup //Setup
export default function ({login, imports, rest, computed, pending, q}, {enabled = false, token = ""} = {}) { export default async function ({login, imports, q}, {enabled = false, token = ""} = {}) {
//Check if plugin is enabled and requirements are met
if (!enabled)
return computed.plugins.music = null
if (!q.music)
return computed.plugins.music = null
console.debug(`metrics/compute/${login}/plugins > music`)
const raw = {
get provider() { return providers[provider]?.name ?? "" },
get mode() { return modes[mode] ?? "Unconfigured music plugin"},
}
//Parameters override and checks
let {"music.provider":provider = "", "music.mode":mode = "", "music.playlist":playlist = null, "music.limit":limit = 4} = q
//Auto-guess parameters
if ((playlist)&&(!mode))
mode = "playlist"
if ((playlist)&&(!provider))
for (const [name, {embed}] of Object.entries(providers))
if (embed.test(playlist))
provider = name
if (!mode)
mode = "recent"
//Provider
if (!(provider in providers))
return computed.plugins.music = {...raw, error:provider ? `Unsupported provider "${provider}"` : `Missing provider`}
//Mode
if (!(mode in modes))
return computed.plugins.music = {...raw, error:`Unsupported mode "${mode}"`}
//Playlist mode
if (mode === "playlist") {
if (!playlist)
return computed.plugins.music = {...raw, error:`Missing playlist url`}
if (!providers[provider].embed.test(playlist))
return computed.plugins.music = {...raw, error:`Unsupported playlist url format`}
}
//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 //Plugin execution
pending.push(new Promise(async solve => { try {
//Retrieve music data //Check if plugin is enabled and requirements are met
try { if ((!enabled)||(!q.music))
//Initialization return null
let tracks = null
//Handle mode //Initialization
switch (mode) { const raw = {
//Playlist mode get provider() { return providers[provider]?.name ?? "" },
case "playlist":{ get mode() { return modes[mode] ?? "Unconfigured music plugin"},
//Start puppeteer and navigate to playlist
console.debug(`metrics/compute/${login}/plugins > music > starting browser`)
const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]})
console.debug(`metrics/compute/${login}/plugins > music > loaded ${await browser.version()}`)
const page = await browser.newPage()
console.debug(`metrics/compute/${login}/plugins > music > loading page`)
await page.goto(playlist)
const frame = page.mainFrame()
//Handle provider
switch (provider) {
//Apple music
case "apple":{
//Parse tracklist
await frame.waitForSelector(".tracklist.playlist")
tracks = [...await frame.evaluate(() => [...document.querySelectorAll(".tracklist li")].map(li => ({
name:li.querySelector(".tracklist__track__name").innerText,
artist:li.querySelector(".tracklist__track__sub").innerText,
artwork:li.querySelector(".tracklist__track__artwork img").src
})))]
break
}
//Spotify
case "spotify":{
//Parse tracklist
await frame.waitForSelector("table")
tracks = [...await frame.evaluate(() => [...document.querySelectorAll("table tr")].map(tr => ({
name:tr.querySelector("td:nth-child(2) div:nth-child(1)").innerText,
artist:tr.querySelector("td:nth-child(2) div:nth-child(2)").innerText,
//Spotify doesn't provide artworks so we fallback on playlist artwork instead
artwork:window.getComputedStyle(document.querySelector("button[title=Play]").parentNode, null).backgroundImage.match(/^url\("(https:...+)"\)$/)[1]
})))]
break
}
//Unsupported
default:{
throw {status:`Unsupported mode "${mode}" for provider "${provider}"`}
}
}
//Close browser
console.debug(`metrics/compute/${login}/plugins > music > closing browser`)
await browser.close()
//Format tracks
if (Array.isArray(tracks)) {
//Tracks
console.debug(`metrics/compute/${login}/plugins > music > found ${tracks.length} tracks`)
console.debug(JSON.stringify(tracks))
//Shuffle tracks
tracks = imports.shuffle(tracks)
}
break
}
//Recently played
case "recent":{
//Initialisation
const timestamp = Date.now()-24*60*60*1000
//Handle provider
switch (provider) {
//Spotify
case "spotify":{
//Prepare credentials
const [client_id, client_secret, refresh_token] = token.split(",").map(part => part.trim())
if ((!client_id)||(!client_secret)||(!refresh_token))
throw {status:`Spotify token must contain client id/secret and refresh token`}
//API call and parse tracklist
try {
//Request access token
console.debug(`metrics/compute/${login}/plugins > music > requesting access token with refresh token for spotify`)
const {data:{access_token:access}} = await imports.axios.post("https://accounts.spotify.com/api/token",
`${new imports.url.URLSearchParams({grant_type:"refresh_token", refresh_token, client_id, client_secret})}`,
{headers:{"Content-Type":"application/x-www-form-urlencoded"}},
)
console.log(access)
console.debug(`metrics/compute/${login}/plugins > music > got new access token`)
//Retriev tracks
tracks = (await imports.axios(`https://api.spotify.com/v1/me/player/recently-played?limit=${limit}&after=${timestamp}`, {headers:{
"Accept":"application/json",
"Content-Type":"application/json",
"Authorization":`Bearer ${access}`}
})).data.items.map(({track}) => ({
name:track.name,
artist:track.artists[0].name,
artwork:track.album.images[0].url,
}))
}
//Handle errors
catch (error) {
console.debug(error)
if ((error.response)&&(error.response.status))
throw {status:`API call returned ${error.response.status}`}
throw error
}
break
}
//Unsupported
default:{
throw {status:`Unsupported mode "${mode}" for provider "${provider}"`}
}
}
break
}
//Unsupported
default:{
throw {status:`Unsupported mode "${mode}"`}
}
}
//Format tracks
if (Array.isArray(tracks)) {
//Limit tracklist
if (limit > 0) {
console.debug(`metrics/compute/${login}/plugins > music > keeping only ${limit} tracks`)
tracks = tracks.slice(0, limit)
}
//Convert artworks to base64
console.debug(`metrics/compute/${login}/plugins > music > loading artworks`)
for (const track of tracks) {
console.debug(`metrics/compute/${login}/plugins > music > processing ${track.name}`)
track.artwork = await imports.imgb64(track.artwork)
}
//Save results
console.debug(`metrics/compute/${login}/plugins > music > success`)
computed.plugins.music = {...raw, tracks}
solve()
return
}
//Unhandled error
throw {status:`An error occured (unhandled)`}
} }
catch (error) { let tracks = null
//Plugin error
if (error.status) { //Parameters override
computed.plugins.music = {...raw, error:error.status} let {"music.provider":provider = "", "music.mode":mode = "", "music.playlist":playlist = null, "music.limit":limit = 4} = q
console.debug(`metrics/compute/${login}/plugins > music > error > ${error.status}`) //Auto-guess parameters
return solve() if ((playlist)&&(!mode))
mode = "playlist"
if ((playlist)&&(!provider))
for (const [name, {embed}] of Object.entries(providers))
if (embed.test(playlist))
provider = name
if (!mode)
mode = "recent"
//Provider
if (!(provider in providers))
throw {error:{message:provider ? `Unsupported provider "${provider}"` : `Missing provider`}, ...raw}
//Mode
if (!(mode in modes))
throw {error:{message:`Unsupported mode "${mode}"`}, ...raw}
//Playlist mode
if (mode === "playlist") {
if (!playlist)
throw {error:{message:`Missing playlist url`}, ...raw}
if (!providers[provider].embed.test(playlist))
throw {error:{message:`Unsupported playlist url format`}, ...raw}
} }
//Generic error //Limit
computed.plugins.music = {...raw, error:`An error occured`} limit = Math.max(1, Math.min(100, Number(limit)))
console.debug(`metrics/compute/${login}/plugins > music > error`)
console.debug(error) //Handle mode
solve() switch (mode) {
//Playlist mode
case "playlist":{
//Start puppeteer and navigate to playlist
console.debug(`metrics/compute/${login}/plugins > music > starting browser`)
const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]})
console.debug(`metrics/compute/${login}/plugins > music > loaded ${await browser.version()}`)
const page = await browser.newPage()
console.debug(`metrics/compute/${login}/plugins > music > loading page`)
await page.goto(playlist)
const frame = page.mainFrame()
//Handle provider
switch (provider) {
//Apple music
case "apple":{
//Parse tracklist
await frame.waitForSelector(".tracklist.playlist")
tracks = [...await frame.evaluate(() => [...document.querySelectorAll(".tracklist li")].map(li => ({
name:li.querySelector(".tracklist__track__name").innerText,
artist:li.querySelector(".tracklist__track__sub").innerText,
artwork:li.querySelector(".tracklist__track__artwork img").src
})))]
break
}
//Spotify
case "spotify":{
//Parse tracklist
await frame.waitForSelector("table")
tracks = [...await frame.evaluate(() => [...document.querySelectorAll("table tr")].map(tr => ({
name:tr.querySelector("td:nth-child(2) div:nth-child(1)").innerText,
artist:tr.querySelector("td:nth-child(2) div:nth-child(2)").innerText,
//Spotify doesn't provide artworks so we fallback on playlist artwork instead
artwork:window.getComputedStyle(document.querySelector("button[title=Play]").parentNode, null).backgroundImage.match(/^url\("(https:...+)"\)$/)[1]
})))]
break
}
//Unsupported
default:
throw {error:{message:`Unsupported mode "${mode}" for provider "${provider}"`}, ...raw}
}
//Close browser
console.debug(`metrics/compute/${login}/plugins > music > closing browser`)
await browser.close()
//Format tracks
if (Array.isArray(tracks)) {
//Tracks
console.debug(`metrics/compute/${login}/plugins > music > found ${tracks.length} tracks`)
console.debug(JSON.stringify(tracks))
//Shuffle tracks
tracks = imports.shuffle(tracks)
}
break
}
//Recently played
case "recent":{
//Initialisation
const timestamp = Date.now()-24*60*60*1000
//Handle provider
switch (provider) {
//Spotify
case "spotify":{
//Prepare credentials
const [client_id, client_secret, refresh_token] = token.split(",").map(part => part.trim())
if ((!client_id)||(!client_secret)||(!refresh_token))
throw {error:`Spotify token must contain client id/secret and refresh token`}
//API call and parse tracklist
try {
//Request access token
console.debug(`metrics/compute/${login}/plugins > music > requesting access token with refresh token for spotify`)
const {data:{access_token:access}} = await imports.axios.post("https://accounts.spotify.com/api/token",
`${new imports.url.URLSearchParams({grant_type:"refresh_token", refresh_token, client_id, client_secret})}`,
{headers:{"Content-Type":"application/x-www-form-urlencoded"}},
)
console.log(access)
console.debug(`metrics/compute/${login}/plugins > music > got new access token`)
//Retriev tracks
tracks = (await imports.axios(`https://api.spotify.com/v1/me/player/recently-played?limit=${limit}&after=${timestamp}`, {headers:{
"Accept":"application/json",
"Content-Type":"application/json",
"Authorization":`Bearer ${access}`}
})).data.items.map(({track}) => ({
name:track.name,
artist:track.artists[0].name,
artwork:track.album.images[0].url,
}))
}
//Handle errors
catch (error) {
if ((error.response?.status))
throw {error:{message:`API returned ${error.response.status}`}, ...raw}
throw error
}
break
}
//Unsupported
default:
throw {error:{message:`Unsupported mode "${mode}" for provider "${provider}"`}, ...raw}
}
break
}
//Unsupported
default:
throw {error:{message:`Unsupported mode "${mode}"`}, ...raw}
} }
})) //Format tracks
} if (Array.isArray(tracks)) {
//Limit tracklist
if (limit > 0) {
console.debug(`metrics/compute/${login}/plugins > music > keeping only ${limit} tracks`)
tracks = tracks.slice(0, limit)
}
//Convert artworks to base64
console.debug(`metrics/compute/${login}/plugins > music > loading artworks`)
for (const track of tracks) {
console.debug(`metrics/compute/${login}/plugins > music > processing ${track.name}`)
track.artwork = await imports.imgb64(track.artwork)
}
//Save results
console.debug(`metrics/compute/${login}/plugins > music > success`)
return {...raw, tracks}
}
//Unhandled error
throw {error:{message:`An error occured (could not retrieve tracks)`}}
}
//Handle errors
catch (error) {
if (error.error?.message)
throw error
console.debug(error)
throw {error:{message:`An error occured`}}
}
}

View File

@@ -1,44 +1,27 @@
//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
//Format url if needed if ((!enabled)||(!q.pagespeed)||(!data.user.websiteUrl))
if (!/^https?:[/][/]/.test(url)) return null
url = `https://${url}` //Format url if needed
//Load scores from API let url = data.user.websiteUrl
const scores = new Map() if (!/^https?:[/][/]/.test(url))
await Promise.all(["performance", "accessibility", "best-practices", "seo"].map(async category => { url = `https://${url}`
const {score, title} = (await imports.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=${category}&url=${url}&key=${token}`)).data.lighthouseResult.categories[category] //Load scores from API
scores.set(category, {score, title}) const scores = new Map()
})) await Promise.all(["performance", "accessibility", "best-practices", "seo"].map(async category => {
//Save results const {score, title} = (await imports.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=${category}&url=${url}&key=${token}`)).data.lighthouseResult.categories[category]
computed.plugins.pagespeed = {url, scores:[scores.get("performance"), scores.get("accessibility"), scores.get("best-practices"), scores.get("seo")]} scores.set(category, {score, title})
console.debug(`metrics/compute/${login}/plugins > pagespeed > success`) }))
console.debug(JSON.stringify(computed.plugins.pagespeed)) //Results
solve() return {url, scores:[scores.get("performance"), scores.get("accessibility"), scores.get("best-practices"), scores.get("seo")]}
} }
catch (error) { //Handle errors
//Thrown when token is incorrect catch (error) {
if ((error.response)&&(error.response.status)) { if (error.response?.status)
computed.plugins.pagespeed = {url, error:`PageSpeed token error (code ${error.response.status})`} throw {error:{message:`PageSpeed token error (code ${error.response.status})`}, url}
console.debug(`metrics/plugins/pagespeed/${login} > ${error.response.status}`) throw {error:{message:`An error occured`}}
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,36 +1,25 @@
//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
//Search for auto-generated commits if ((!enabled)||(!q.selfskip))
let commits = 0 return null
for (let page = 0;;page++) { //Search for auto-generated commits
const {data} = await rest.repos.listCommits({owner:login, repo:login, author:login, per_page:100, page}) let commits = 0
commits += data.filter(({commit}) => /\[Skip GitHub Action\]/.test(commit.message)).length for (let page = 0;;page++) {
if (!data.length) const {data} = await rest.repos.listCommits({owner:login, repo:login, author:login, per_page:100, page})
break commits += data.filter(({commit}) => /\[Skip GitHub Action\]/.test(commit.message)).length
} if (!data.length)
//Save results break
computed.plugins.selfskip = {commits} }
computed.commits -= commits //Results
console.debug(`metrics/compute/${login}/plugins > selfskip > success`) computed.commits -= commits
console.debug(JSON.stringify(computed.plugins.selfskip)) return {commits}
solve() }
} //Handle errors
catch (error) { catch (error) {
//Generic error console.debug(error)
computed.plugins.selfskip = {error:`An error occured`} throw {error:{message:`An error occured`}}
console.debug(`metrics/compute/${login}/plugins > selfskip > error`) }
console.debug(error)
solve()
}
}))
} }

View File

@@ -1,41 +1,28 @@
//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
//Get views stats from repositories if ((!enabled)||(!q.traffic))
const views = {count:0, uniques:0} return null
const response = await Promise.all(repositories.map(async repo => await rest.repos.getViews({owner:login, repo}))) //Repositories
//Compute views const repositories = data.user.repositories.nodes.map(({name}) => name) ?? []
response.filter(({data}) => data).map(({data:{count, uniques}}) => (views.count += count, views.uniques += uniques)) //Get views stats from repositories
//Format values const views = {count:0, uniques:0}
views.count = imports.format(views.count) const response = await Promise.all(repositories.map(async repo => await rest.repos.getViews({owner:login, repo})))
views.uniques = imports.format(views.uniques) //Compute views
//Save results response.filter(({data}) => data).map(({data:{count, uniques}}) => (views.count += count, views.uniques += uniques))
computed.plugins.traffic = {views} //Format values
console.debug(`metrics/compute/${login}/plugins > traffic > success`) views.count = imports.format(views.count)
console.debug(JSON.stringify(computed.plugins.traffic)) views.uniques = imports.format(views.uniques)
solve() //Results
} return {views}
catch (error) { }
//Thrown when token has unsufficient permissions //Handle errors
if (error.status === 403) { catch (error) {
computed.plugins.traffic = {error:`Insufficient token rights`} if (error.status === 403)
console.debug(`metrics/compute/${login}/plugins > error > 403 (insufficient token rights)`) throw {error:{message:`Insufficient token rights`}}
return solve() console.debug(error)
} throw {error:{message:`An error occured`}}
//Generic error }
computed.plugins.traffic = {error:`An error occured`}
console.debug(`metrics/compute/${login}/plugins > error`)
console.debug(error)
solve()
}
}))
} }

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