Version 1.8 (#5)
This commit is contained in:
@@ -79,7 +79,7 @@
|
||||
//Render
|
||||
if (debug)
|
||||
[template, style, query] = await load()
|
||||
const rendered = await metrics({login, q:req.query}, {template, style, query, graphql, rest, plugins})
|
||||
const rendered = await metrics({login, q:req.query}, {template, style, query, graphql, rest, plugins, optimize:settings.optimize})
|
||||
//Cache
|
||||
if ((!debug)&&(cached))
|
||||
cache.put(login, rendered, cached)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import Plugins from "./plugins/index.mjs"
|
||||
|
||||
//Setup
|
||||
export default async function metrics({login, q}, {template, style, query, graphql, rest, plugins}) {
|
||||
export default async function metrics({login, q}, {template, style, query, graphql, rest, plugins, selfless = true, optimize = true}) {
|
||||
//Compute rendering
|
||||
try {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
Plugins.lines({login, repositories:data.user.repositories.nodes.map(({name}) => name), rest, computed, pending, q}, plugins.lines)
|
||||
Plugins.traffic({login, repositories:data.user.repositories.nodes.map(({name}) => name), rest, computed, pending, q}, plugins.traffic)
|
||||
Plugins.habits({login, rest, computed, pending, q}, plugins.habits)
|
||||
Plugins.selfskip({login, rest, computed, pending, q}, plugins.selfskip)
|
||||
|
||||
//Iterate through user's repositories
|
||||
for (const repository of data.user.repositories.nodes) {
|
||||
@@ -82,16 +83,18 @@
|
||||
|
||||
//Eval rendering
|
||||
console.debug(`metrics/metrics/${login} > computed`)
|
||||
const templated = eval(`\`${template}\``)
|
||||
let rendered = eval(`\`${template}\``)
|
||||
console.debug(`metrics/metrics/${login} > templated`)
|
||||
|
||||
//Optimize rendering
|
||||
const svgo = new SVGO({full:true, plugins:[{cleanupAttrs:true}, {inlineStyles:false}]})
|
||||
const {data:optimized} = await svgo.optimize(templated)
|
||||
console.debug(`metrics/metrics/${login} > optimized`)
|
||||
if (optimize) {
|
||||
const svgo = new SVGO({full:true, plugins:[{cleanupAttrs:true}, {inlineStyles:false}]})
|
||||
const {data:optimized} = await svgo.optimize(rendered)
|
||||
console.debug(`metrics/metrics/${login} > optimized`)
|
||||
rendered = optimized
|
||||
}
|
||||
|
||||
//Result
|
||||
const rendered = optimized
|
||||
return rendered
|
||||
}
|
||||
//Internal error
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import habits from "./habits/index.mjs"
|
||||
import lines from "./lines/index.mjs"
|
||||
import pagespeed from "./pagespeed/index.mjs"
|
||||
import selfskip from "./selfskip/index.mjs"
|
||||
import traffic from "./traffic/index.mjs"
|
||||
|
||||
//Exports
|
||||
@@ -9,5 +10,6 @@
|
||||
habits,
|
||||
lines,
|
||||
pagespeed,
|
||||
selfskip,
|
||||
traffic,
|
||||
}
|
||||
@@ -6,8 +6,6 @@
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if (!enabled)
|
||||
return computed.plugins.pagespeed = null
|
||||
if (!token)
|
||||
return computed.plugins.pagespeed = null
|
||||
if (!url)
|
||||
return computed.plugins.pagespeed = null
|
||||
if (!q.pagespeed)
|
||||
|
||||
33
src/plugins/selfskip/index.mjs
Normal file
33
src/plugins/selfskip/index.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
//Setup
|
||||
export default function ({login, rest, computed, pending, 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/plugins/selfskip/${login} > started`)
|
||||
|
||||
//Plugin execution
|
||||
pending.push(new Promise(async solve => {
|
||||
try {
|
||||
//Search for auto-generated commits
|
||||
let commits = 0
|
||||
for (let page = 0;;page++) {
|
||||
const {data} = await rest.repos.listCommits({owner:login, repo:login, author:login, per_page:100, page})
|
||||
commits += data.filter(({commit}) => /\[Skip GitHub Action\]/.test(commit.message)).length
|
||||
if (!data.length)
|
||||
break
|
||||
}
|
||||
//Save results
|
||||
computed.plugins.selfskip = {commits}
|
||||
console.debug(`metrics/plugins/selfskip/${login} > ${JSON.stringify(computed.plugins.selfskip)}`)
|
||||
solve()
|
||||
}
|
||||
catch (error) {
|
||||
//Generic error
|
||||
computed.plugins.selfskip = {error:`An error occured`}
|
||||
console.debug(error)
|
||||
solve()
|
||||
}
|
||||
}))
|
||||
}
|
||||
@@ -54,7 +54,7 @@
|
||||
</h2>
|
||||
<div class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M10.5 7.75a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm1.43.75a4.002 4.002 0 01-7.86 0H.75a.75.75 0 110-1.5h3.32a4.001 4.001 0 017.86 0h3.32a.75.75 0 110 1.5h-3.32z"></path></svg>
|
||||
${data.computed.commits} Commit${data.computed.commits > 1 ? "s" : ""}
|
||||
${data.computed.commits - (computed.plugins.selfskip ? computed.plugins.selfskip.commits||0 : 0)} Commit${data.computed.commits - (computed.plugins.selfskip ? computed.plugins.selfskip.commits||0 : 0) > 1 ? "s" : ""}
|
||||
</div>
|
||||
<div class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.5 1.75a.25.25 0 01.25-.25h8.5a.25.25 0 01.25.25v7.736a.75.75 0 101.5 0V1.75A1.75 1.75 0 0011.25 0h-8.5A1.75 1.75 0 001 1.75v11.5c0 .966.784 1.75 1.75 1.75h3.17a.75.75 0 000-1.5H2.75a.25.25 0 01-.25-.25V1.75zM4.75 4a.75.75 0 000 1.5h4.5a.75.75 0 000-1.5h-4.5zM4 7.75A.75.75 0 014.75 7h2a.75.75 0 010 1.5h-2A.75.75 0 014 7.75zm11.774 3.537a.75.75 0 00-1.048-1.074L10.7 14.145 9.281 12.72a.75.75 0 00-1.062 1.058l1.943 1.95a.75.75 0 001.055.008l4.557-4.45z"></path></svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Reference in New Issue
Block a user