Add option to ignore languages/skip repositories in languages plugin (#22)
* Add option to ignore languages/skip repositories in languages plugin * Fix logs on error and first attempt to fix update of file larger than >1mb * Use variable branch name * Update version number
This commit is contained in:
1 parent
d057f20fa3
commit
f9460d6159
10 files changed
+140
-69
No files matched your search
@@ -731,6 +731,8 @@ Add the following to your workflow :
|
||||
with:
|
||||
# ... other options
|
||||
plugin_languages: yes
|
||||
plugin_languages_ignored: "" # List of comma separated languages to ignore
|
||||
plugin_languages_skipped: "" # List of comma separated repositories to skip
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
+12
@@ -115,6 +115,18 @@ inputs:
|
||||
description: Enable most used languages metrics
|
||||
default: no
|
||||
|
||||
# List of ignored languages, comma separated
|
||||
# Ignored languages won't count towards your languages metrics
|
||||
plugin_languages_ignored:
|
||||
description: List of ignored languages
|
||||
default: ""
|
||||
|
||||
# List of skipped repositories, comma separated
|
||||
# Skipped repositories won't count towards your languages metrics
|
||||
plugin_languages_skipped:
|
||||
description: List of skipped repositories
|
||||
default: ""
|
||||
|
||||
# Follow-up plugin
|
||||
# Display the number and the ratio of opened/closed issues and opened/merged pull requests on your repositories
|
||||
plugin_followup:
|
||||
|
||||
Vendored
+9
-3
@@ -1,4 +1,4 @@
|
||||
module.exports=(()=>{var _Mathhypot=Math.hypot,_Mathacos=Math.acos,_Mathtan=Math.tan,_Mathasin=Math.asin,_Mathsin=Math.sin,_Mathcos=Math.cos,_MathPI=Math.PI,_Mathsqrt=Math.sqrt,_NumberisInteger=Number.isInteger,_Stringprototype=String.prototype,_NumberPOSITIVE_INFINITY=Number.POSITIVE_INFINITY,_NumberNEGATIVE_INFINITY=Number.NEGATIVE_INFINITY,_NumberMAX_SAFE_INTEGER=Number.MAX_SAFE_INTEGER,_Mathround=Math.round,_StringfromCharCode=String.fromCharCode,_Mathabs=Math.abs,_Mathpow=Math.pow,_Mathceil=Math.ceil,_Mathfloor=Math.floor,_Mathmax=Math.max,_Mathmin=Math.min;function __webpack_require__(e){if(__webpack_module_cache__[e])return __webpack_module_cache__[e].exports;var t=__webpack_module_cache__[e]={exports:{}},r=!0;try{__webpack_modules__[e].call(t.exports,t,t.exports,__webpack_require__),r=!1}finally{r&&delete __webpack_module_cache__[e]}return t.exports}var __webpack_modules__={75935:(e,t,r)=>{"use strict";async function n({log:e=!0}={}){const t=e?console.debug:()=>null;t(`metrics/setup > setup`);const n="src/templates",a={templates:{},settings:{},statics:r.ab+"html",node_modules:f.resolve("node_modules")};if(t(`metrics/setup > load settings.json`),h.existsSync(r.ab+"settings.json")?(a.settings=JSON.parse(`${await h.promises.readFile(f.resolve("settings.json"))}`),t(`metrics/setup > load settings.json > success`)):t(`metrics/setup > load settings.json > (missing)`),a.settings.templates||(a.settings.templates={default:"classic",enabled:[]}),a.settings.plugins||(a.settings.plugins={}),a.settings.plugins.base={parts:["header","activity","community","repositories","metadata"]},a.settings.debug&&t(a.settings),t(`metrics/setup > load package.json`),h.existsSync(r.ab+"package.json")?(a.package=JSON.parse(`${await h.promises.readFile(f.resolve("package.json"))}`),t(`metrics/setup > load package.json > success`)):(t(`metrics/setup > load package.json > (missing)`),a.package={version:"2.8.0-beta",author:"lowlighter"}),h.existsSync(r.ab+"templates"))for(const e of await h.promises.readdir(n)){if(/.*[.]mjs$/.test(e))continue;t(`metrics/setup > load template [${e}]`);const r=[`${n}/${e}/query.graphql`,`${n}/${e}/image.svg`,`${n}/${e}/style.css`,`${n}/${e}/fonts.css`],[o,i,s,l]=await Promise.all(r.map(async e=>`${await h.promises.readFile(f.resolve(e))}`));a.templates[e]={query:o,image:i,style:s,fonts:l},t(`metrics/setup > load template [${e}] > success`),a.settings.debug&&Object.defineProperty(a.templates,e,{get(){t(`metrics/setup > reload template [${e}]`);const[n,a,o,i]=r.map(e=>`${h.readFileSync(f.resolve(e))}`);return t(`metrics/setup > reload template [${e}] > success`),{query:n,image:a,style:o,fonts:i}}})}else t(`metrics/setup > load templates from build`),a.templates=JSON.parse(Buffer.from(`eyJjbGFzc2ljIjp7InF1ZXJ5IjoicXVlcnkgTWV0cmljcyB7XHJcbiAgdXNlcihsb2dpbjogJGxvZ2luKSB7XHJcbiAgICBkYXRhYmFzZUlkXHJcbiAgICBuYW1lXHJcbiAgICBsb2dpblxyXG4gICAgY3JlYXRlZEF0XHJcbiAgICBhdmF0YXJVcmxcclxuICAgIHdlYnNpdGVVcmxcclxuICAgIGlzSGlyZWFibGVcclxuICAgIGdpc3RzIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgcmVwb3NpdG9yaWVzKGxhc3Q6ICRyZXBvc2l0b3JpZXMsIGlzRm9yazogZmFsc2UsIG93bmVyQWZmaWxpYXRpb25zOiBPV05FUikge1xyXG4gICAgICB0b3RhbENvdW50XHJcbiAgICAgIHRvdGFsRGlza1VzYWdlXHJcbiAgICAgIG5vZGVzIHtcclxuICAgICAgICBuYW1lXHJcbiAgICAgICAgd2F0Y2hlcnMge1xyXG4gICAgICAgICAgdG90YWxDb3VudFxyXG4gICAgICAgIH1cclxuICAgICAgICBzdGFyZ2F6ZXJzIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgbGFuZ3VhZ2VzKGZpcnN0OiA0KSB7XHJcbiAgICAgICAgICBlZGdlcyB7XHJcbiAgICAgICAgICAgIHNpemVcclxuICAgICAgICAgICAgbm9kZSB7XHJcbiAgICAgICAgICAgICAgY29sb3JcclxuICAgICAgICAgICAgICBuYW1lXHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgaXNzdWVzX29wZW46IGlzc3VlcyhzdGF0ZXM6IE9QRU4pIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgaXNzdWVzX2Nsb3NlZDogaXNzdWVzKHN0YXRlczogQ0xPU0VEKSB7XHJcbiAgICAgICAgICB0b3RhbENvdW50XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHByX29wZW46IHB1bGxSZXF1ZXN0cyhzdGF0ZXM6IE9QRU4pIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgcHJfbWVyZ2VkOiBwdWxsUmVxdWVzdHMoc3RhdGVzOiBNRVJHRUQpIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgcmVsZWFzZXMge1xyXG4gICAgICAgICAgdG90YWxDb3VudFxyXG4gICAgICAgIH1cclxuICAgICAgICBmb3JrQ291bnRcclxuICAgICAgICBsaWNlbnNlSW5mbyB7XHJcbiAgICAgICAgICBzcGR4SWRcclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuICAgIH1cclxuICAgIHBhY2thZ2VzIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgc3RhcnJlZFJlcG9zaXRvcmllcyB7XHJcbiAgICAgIHRvdGFsQ291bnRcclxuICAgIH1cclxuICAgIHdhdGNoaW5nIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgc3BvbnNvcnNoaXBzQXNTcG9uc29yIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgc3BvbnNvcnNoaXBzQXNNYWludGFpbmVyIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgY29udHJpYnV0aW9uc0NvbGxlY3Rpb24ge1xyXG4gICAgICB0b3RhbFJlcG9zaXRvcmllc1dpdGhDb250cmlidXRlZENvbW1pdHNcclxuICAgICAgdG90YWxDb21taXRDb250cmlidXRpb25zXHJcbiAgICAgIHJlc3RyaWN0ZWRDb250cmlidXRpb25zQ291bnRcclxuICAgICAgdG90YWxJc3N1ZUNvbnRyaWJ1dGlvbnNcclxuICAgICAgdG90YWxQdWxsUmVxdWVzdENvbnRyaWJ1dGlvbnNcc
Line truncated
|
||||
module.exports=(()=>{var _Mathhypot=Math.hypot,_Mathacos=Math.acos,_Mathtan=Math.tan,_Mathasin=Math.asin,_Mathsin=Math.sin,_Mathcos=Math.cos,_MathPI=Math.PI,_Mathsqrt=Math.sqrt,_NumberisInteger=Number.isInteger,_Stringprototype=String.prototype,_NumberPOSITIVE_INFINITY=Number.POSITIVE_INFINITY,_NumberNEGATIVE_INFINITY=Number.NEGATIVE_INFINITY,_NumberMAX_SAFE_INTEGER=Number.MAX_SAFE_INTEGER,_Mathround=Math.round,_StringfromCharCode=String.fromCharCode,_Mathabs=Math.abs,_Mathpow=Math.pow,_Mathceil=Math.ceil,_Mathfloor=Math.floor,_Mathmax=Math.max,_Mathmin=Math.min;function __webpack_require__(e){if(__webpack_module_cache__[e])return __webpack_module_cache__[e].exports;var t=__webpack_module_cache__[e]={exports:{}},r=!0;try{__webpack_modules__[e].call(t.exports,t,t.exports,__webpack_require__),r=!1}finally{r&&delete __webpack_module_cache__[e]}return t.exports}var __webpack_modules__={75935:(e,t,r)=>{"use strict";async function n({log:e=!0}={}){const t=e?console.debug:()=>null;t(`metrics/setup > setup`);const n="src/templates",a={templates:{},settings:{},statics:r.ab+"html",node_modules:f.resolve("node_modules")};if(t(`metrics/setup > load settings.json`),h.existsSync(r.ab+"settings.json")?(a.settings=JSON.parse(`${await h.promises.readFile(f.resolve("settings.json"))}`),t(`metrics/setup > load settings.json > success`)):t(`metrics/setup > load settings.json > (missing)`),a.settings.templates||(a.settings.templates={default:"classic",enabled:[]}),a.settings.plugins||(a.settings.plugins={}),a.settings.plugins.base={parts:["header","activity","community","repositories","metadata"]},a.settings.debug&&t(a.settings),t(`metrics/setup > load package.json`),h.existsSync(r.ab+"package.json")?(a.package=JSON.parse(`${await h.promises.readFile(f.resolve("package.json"))}`),t(`metrics/setup > load package.json > success`)):(t(`metrics/setup > load package.json > (missing)`),a.package={version:"2.8.0",author:"lowlighter"}),h.existsSync(r.ab+"templates"))for(const e of await h.promises.readdir(n)){if(/.*[.]mjs$/.test(e))continue;t(`metrics/setup > load template [${e}]`);const r=[`${n}/${e}/query.graphql`,`${n}/${e}/image.svg`,`${n}/${e}/style.css`,`${n}/${e}/fonts.css`],[o,i,s,l]=await Promise.all(r.map(async e=>`${await h.promises.readFile(f.resolve(e))}`));a.templates[e]={query:o,image:i,style:s,fonts:l},t(`metrics/setup > load template [${e}] > success`),a.settings.debug&&Object.defineProperty(a.templates,e,{get(){t(`metrics/setup > reload template [${e}]`);const[n,a,o,i]=r.map(e=>`${h.readFileSync(f.resolve(e))}`);return t(`metrics/setup > reload template [${e}] > success`),{query:n,image:a,style:o,fonts:i}}})}else t(`metrics/setup > load templates from build`),a.templates=JSON.parse(Buffer.from(`eyJjbGFzc2ljIjp7InF1ZXJ5IjoicXVlcnkgTWV0cmljcyB7XHJcbiAgdXNlcihsb2dpbjogJGxvZ2luKSB7XHJcbiAgICBkYXRhYmFzZUlkXHJcbiAgICBuYW1lXHJcbiAgICBsb2dpblxyXG4gICAgY3JlYXRlZEF0XHJcbiAgICBhdmF0YXJVcmxcclxuICAgIHdlYnNpdGVVcmxcclxuICAgIGlzSGlyZWFibGVcclxuICAgIGdpc3RzIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgcmVwb3NpdG9yaWVzKGxhc3Q6ICRyZXBvc2l0b3JpZXMsIGlzRm9yazogZmFsc2UsIG93bmVyQWZmaWxpYXRpb25zOiBPV05FUikge1xyXG4gICAgICB0b3RhbENvdW50XHJcbiAgICAgIHRvdGFsRGlza1VzYWdlXHJcbiAgICAgIG5vZGVzIHtcclxuICAgICAgICBuYW1lXHJcbiAgICAgICAgd2F0Y2hlcnMge1xyXG4gICAgICAgICAgdG90YWxDb3VudFxyXG4gICAgICAgIH1cclxuICAgICAgICBzdGFyZ2F6ZXJzIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgbGFuZ3VhZ2VzKGZpcnN0OiA0KSB7XHJcbiAgICAgICAgICBlZGdlcyB7XHJcbiAgICAgICAgICAgIHNpemVcclxuICAgICAgICAgICAgbm9kZSB7XHJcbiAgICAgICAgICAgICAgY29sb3JcclxuICAgICAgICAgICAgICBuYW1lXHJcbiAgICAgICAgICAgIH1cclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgaXNzdWVzX29wZW46IGlzc3VlcyhzdGF0ZXM6IE9QRU4pIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgaXNzdWVzX2Nsb3NlZDogaXNzdWVzKHN0YXRlczogQ0xPU0VEKSB7XHJcbiAgICAgICAgICB0b3RhbENvdW50XHJcbiAgICAgICAgfVxyXG4gICAgICAgIHByX29wZW46IHB1bGxSZXF1ZXN0cyhzdGF0ZXM6IE9QRU4pIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgcHJfbWVyZ2VkOiBwdWxsUmVxdWVzdHMoc3RhdGVzOiBNRVJHRUQpIHtcclxuICAgICAgICAgIHRvdGFsQ291bnRcclxuICAgICAgICB9XHJcbiAgICAgICAgcmVsZWFzZXMge1xyXG4gICAgICAgICAgdG90YWxDb3VudFxyXG4gICAgICAgIH1cclxuICAgICAgICBmb3JrQ291bnRcclxuICAgICAgICBsaWNlbnNlSW5mbyB7XHJcbiAgICAgICAgICBzcGR4SWRcclxuICAgICAgICB9XHJcbiAgICAgIH1cclxuICAgIH1cclxuICAgIHBhY2thZ2VzIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgc3RhcnJlZFJlcG9zaXRvcmllcyB7XHJcbiAgICAgIHRvdGFsQ291bnRcclxuICAgIH1cclxuICAgIHdhdGNoaW5nIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgc3BvbnNvcnNoaXBzQXNTcG9uc29yIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgc3BvbnNvcnNoaXBzQXNNYWludGFpbmVyIHtcclxuICAgICAgdG90YWxDb3VudFxyXG4gICAgfVxyXG4gICAgY29udHJpYnV0aW9uc0NvbGxlY3Rpb24ge1xyXG4gICAgICB0b3RhbFJlcG9zaXRvcmllc1dpdGhDb250cmlidXRlZENvbW1pdHNcclxuICAgICAgdG90YWxDb21taXRDb250cmlidXRpb25zXHJcbiAgICAgIHJlc3RyaWN0ZWRDb250cmlidXRpb25zQ291bnRcclxuICAgICAgdG90YWxJc3N1ZUNvbnRyaWJ1dGlvbnNcclxuICAgICAgdG90YWxQdWxsUmVxdWVzdENvbnRyaWJ1dGlvbnNcclxuIC
Line truncated
|
||||
query Gists {
|
||||
user(login: "${e}") {
|
||||
gists(last: 100) {
|
||||
@@ -45,7 +45,7 @@ module.exports=(()=>{var _Mathhypot=Math.hypot,_Mathacos=Math.acos,_Mathtan=Math
|
||||
<path fill="${t.color}" d="M1.7,2 0,1 1.7,0 3.4,1 z" />
|
||||
<path fill="${t.color}" filter="url(#brightness1)" d="M0,1 1.7,2 1.7,${2+e*f} 0,${1+e*f} z" />
|
||||
<path fill="${t.color}" filter="url(#brightness2)" d="M1.7,2 3.4,1 3.4,${1+e*f} 1.7,${2+e*f} z" />
|
||||
</g>`,i++}b+=`</g>`,y++}return b+=`</g></svg>`,{streak:m,max:u,average:h,svg:b,duration:a}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},languages:async function({data:e,q:t},{enabled:r=!1}={}){try{if(!r||!t.languages)return null;const n={colors:{},total:0,stats:{}};for(const t of e.user.repositories.nodes)for(const{size:e,node:{color:r,name:a}}of Object.values(t.languages.edges))n.stats[a]=(n.stats[a]??0)+e,n.colors[a]=r??"#ededed",n.total+=e;Object.keys(n.stats).map(e=>n.stats[e]/=n.total),n.favorites=Object.entries(n.stats).sort(([e,t],[r,n])=>n-t).slice(0,8).map(([e,t])=>({name:e,value:t,color:n.colors[e],x:0}));for(let e=1;e<n.favorites.length;e++)n.favorites[e].x=n.favorites[e-1].x+n.favorites[e-1].value;return n}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},lines:async function({login:e,data:t,imports:r,rest:n,q:a},{enabled:o=!1}={}){try{if(!o||!a.lines)return null;const i=t.user.repositories.nodes.map(({name:e})=>e)??[],s={added:0,deleted:0},l=await Promise.all(i.map(async t=>await n.repos.getContributorsStats({owner:e,repo:t})));return l.map(({data:t})=>{if(Array.isArray(t)){const[r]=t.filter(({author:t})=>t.login===e);r&&r.weeks.forEach(({a:e,d:t})=>(s.added+=e,s.deleted+=t))}}),s.added=r.format(s.added),s.deleted=r.format(s.deleted),s}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},music:a,pagespeed:async function({login:e,imports:t,data:r,q:n},{enabled:a=!1,token:o=null}={}){try{if(!a||!n.pagespeed||!r.user.websiteUrl)return null;let{"pagespeed.detailed":i=!1}=n;i=!!i;let s=r.user.websiteUrl;/^https?:[/][/]/.test(s)||(s=`https://${s}`);const l={url:s,detailed:i,scores:[],metrics:{}},d=new Map;if(await Promise.all(["performance","accessibility","best-practices","seo"].map(async r=>{const{score:n,title:a}=(await t.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=${r}&url=${s}&key=${o}`)).data.lighthouseResult.categories[r];d.set(r,{score:n,title:a}),console.debug(`metrics/compute/${e}/plugins > pagespeed > ${r} audit performed`)})),l.scores=[d.get("performance"),d.get("accessibility"),d.get("best-practices"),d.get("seo")],i&&Object.assign(l.metrics,...(await t.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?&url=${s}&key=${o}`)).data.lighthouseResult.audits.metrics.details.items),4>l.scores.filter(e=>e).length)throw{error:{message:"Incomplete PageSpeed results"},url:s};return l}catch(e){if(e.response?.status)throw{error:{message:`PageSpeed token error (code ${e.response.status})`},url};if(e.error?.message)throw e;throw console.debug(e),{error:{message:`An error occured`}}}},posts:async function({imports:e,data:t,q:r},{enabled:n=!1}={}){try{if(!n||!r.posts)return null;const a=t.user.login;let{"posts.source":o="","posts.limit":i=4}=r;i=_Mathmax(1,_Mathmin(30,+i));let s=null;switch(o){case"dev.to":{s=(await e.axios.get(`https://dev.to/api/articles?username=${a}&state=fresh`)).data.map(({title:e,readable_publish_date:t})=>({title:e,date:t}));break}default:throw{error:{message:`Unsupported source "${o}"`}};}if(Array.isArray(s))return 0<i&&(console.debug(`metrics/compute/${a}/plugins > posts > keeping only ${i} posts`),s=s.slice(0,i)),{source:o,list:s};throw{error:{message:`An error occured (could not retrieve posts)`}}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},projects:async function({login:e,graphql:t,q:r},{enabled:n=!1}={}){try{if(!n||!r.projects)return null;let{"projects.limit":a=4}=r;a=_Mathmax(1,_Mathmin(100,+a));const{user:{projects:o}}=await t(`
|
||||
</g>`,i++}b+=`</g>`,y++}return b+=`</g></svg>`,{streak:m,max:u,average:h,svg:b,duration:a}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},languages:async function({login:e,data:t,q:r},{enabled:n=!1}={}){try{if(!n||!r.languages)return null;let{"languages.ignored":a="","languages.skipped":o=""}=r;a=decodeURIComponent(a).split(",").map(e=>e.trim().toLocaleLowerCase()).filter(e=>e),o=decodeURIComponent(o).split(",").map(e=>e.trim().toLocaleLowerCase()).filter(e=>e);const s={colors:{},total:0,stats:{}};for(const r of t.user.repositories.nodes){if(o.includes(r.name.toLocaleLowerCase())){console.debug(`metrics/compute/${e}/plugins > languages > skipped repository ${r.name}`);continue}for(const{size:t,node:{color:n,name:o}}of Object.values(r.languages.edges)){if(a.includes(o.toLocaleLowerCase())){console.debug(`metrics/compute/${e}/plugins > languages > ignored language ${o}`);continue}s.stats[o]=(s.stats[o]??0)+t,s.colors[o]=n??"#ededed",s.total+=t}}Object.keys(s.stats).map(e=>s.stats[e]/=s.total),s.favorites=Object.entries(s.stats).sort(([e,t],[r,n])=>n-t).slice(0,8).map(([e,t])=>({name:e,value:t,color:s.colors[e],x:0}));for(let e=1;e<s.favorites.length;e++)s.favorites[e].x=s.favorites[e-1].x+s.favorites[e-1].value;return s}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},lines:async function({login:e,data:t,imports:r,rest:n,q:a},{enabled:o=!1}={}){try{if(!o||!a.lines)return null;const i=t.user.repositories.nodes.map(({name:e})=>e)??[],s={added:0,deleted:0},l=await Promise.all(i.map(async t=>await n.repos.getContributorsStats({owner:e,repo:t})));return l.map(({data:t})=>{if(Array.isArray(t)){const[r]=t.filter(({author:t})=>t.login===e);r&&r.weeks.forEach(({a:e,d:t})=>(s.added+=e,s.deleted+=t))}}),s.added=r.format(s.added),s.deleted=r.format(s.deleted),s}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},music:a,pagespeed:async function({login:e,imports:t,data:r,q:n},{enabled:a=!1,token:o=null}={}){try{if(!a||!n.pagespeed||!r.user.websiteUrl)return null;let{"pagespeed.detailed":i=!1}=n;i=!!i;let s=r.user.websiteUrl;/^https?:[/][/]/.test(s)||(s=`https://${s}`);const l={url:s,detailed:i,scores:[],metrics:{}},d=new Map;if(await Promise.all(["performance","accessibility","best-practices","seo"].map(async r=>{const{score:n,title:a}=(await t.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=${r}&url=${s}&key=${o}`)).data.lighthouseResult.categories[r];d.set(r,{score:n,title:a}),console.debug(`metrics/compute/${e}/plugins > pagespeed > ${r} audit performed`)})),l.scores=[d.get("performance"),d.get("accessibility"),d.get("best-practices"),d.get("seo")],i&&Object.assign(l.metrics,...(await t.axios.get(`https://www.googleapis.com/pagespeedonline/v5/runPagespeed?&url=${s}&key=${o}`)).data.lighthouseResult.audits.metrics.details.items),4>l.scores.filter(e=>e).length)throw{error:{message:"Incomplete PageSpeed results"},url:s};return l}catch(e){if(e.response?.status)throw{error:{message:`PageSpeed token error (code ${e.response.status})`},url};if(e.error?.message)throw e;throw console.debug(e),{error:{message:`An error occured`}}}},posts:async function({imports:e,data:t,q:r},{enabled:n=!1}={}){try{if(!n||!r.posts)return null;const a=t.user.login;let{"posts.source":o="","posts.limit":i=4}=r;i=_Mathmax(1,_Mathmin(30,+i));let s=null;switch(o){case"dev.to":{s=(await e.axios.get(`https://dev.to/api/articles?username=${a}&state=fresh`)).data.map(({title:e,readable_publish_date:t})=>({title:e,date:t}));break}default:throw{error:{message:`Unsupported source "${o}"`}};}if(Array.isArray(s))return 0<i&&(console.debug(`metrics/compute/${a}/plugins > posts > keeping only ${i} posts`),s=s.slice(0,i)),{source:o,list:s};throw{error:{message:`An error occured (could not retrieve posts)`}}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},projects:async function({login:e,graphql:t,q:r},{enabled:n=!1}={}){try{if(!n||!r.projects)return null;let{"projects.limit":a=4}=r;a=_Mathmax(1,_Mathmin(100,+a));const{user:{projects:o}}=await t(`
|
||||
query Projects {
|
||||
user(login: "${e}") {
|
||||
projects(last: ${a}, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
@@ -63,7 +63,13 @@ module.exports=(()=>{var _Mathhypot=Math.hypot,_Mathacos=Math.acos,_Mathtan=Math
|
||||
}
|
||||
}
|
||||
}
|
||||
`),i=[];for(const e of o.nodes){const t=(Date.now()-new Date(e.updatedAt).getTime())/86400000;let r=1>t?"less than 1 day ago":30>t?`${_Mathfloor(t)} day${2<=t?"s":""} ago`:new Date(e.updatedAt).toDateString().substring(4);const{enabled:n,todoCount:a,inProgressCount:o,doneCount:s}=e.progress;i.push({name:e.name,updated:r,progress:{enabled:n,todo:a,doing:o,done:s,total:a+o+s}})}return{list:i,totalCount:o.totalCount}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},topics:async function({login:e,imports:t,q:r},{enabled:n=!1}={}){try{if(!n||!r.topics)return null;let{"topics.sort":a="stars","topics.limit":o=15}=r;const i="random"===a;a={starred:"created",activity:"updated",stars:"stars",random:"created"}[a]??"starred",o=_Mathmax(1,_Mathmin(20,+o));let s=[];console.debug(`metrics/compute/${e}/plugins > topics > starting browser`);const l=await t.puppeteer.launch({headless:!0,executablePath:process.env.PUPPETEER_BROWSER_PATH,args:["--no-sandbox","--disable-extensions","--disable-setuid-sandbox","--disable-dev-shm-usage"]});console.debug(`metrics/compute/${e}/plugins > topics > loaded ${await l.version()}`);const d=await l.newPage();for(let t=1;100>=t;t++){console.debug(`metrics/compute/${e}/plugins > topics > loading page ${t}`),await d.goto(`https://github.com/stars/${e}/topics?direction=desc&page=${t}&sort=${a}`);const r=d.mainFrame();await Promise.race([r.waitForSelector("ul.repo-list"),r.waitForSelector(".blankslate")]);const n=await r.evaluate(()=>[...document.querySelectorAll("ul.repo-list li")].map(e=>({name:e.querySelector(".f3").innerText,description:e.querySelector(".f5").innerText,icon:e.querySelector("img")?.src??null})));if(!n.length)break;s.push(...n)}if(i&&(s=t.shuffle(s)),0<o){console.debug(`metrics/compute/${e}/plugins > topics > keeping only ${o} topics`);const t=s.slice(o);s=s.slice(0,o),s.push({name:`And ${t.length} more...`,description:t.map(({name:e})=>e).join(", "),icon:null})}for(const r of s)r.icon&&(console.debug(`metrics/compute/${e}/plugins > topics > processing ${r.name}`),r.icon=await t.imgb64(r.icon)),r.description=t.htmlescape(r.description);return{list:s}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},traffic:async function({login:e,imports:t,data:r,rest:n,q:a},{enabled:o=!1}={}){try{if(!o||!a.traffic)return null;const i=r.user.repositories.nodes.map(({name:e})=>e)??[],s={count:0,uniques:0},l=await Promise.all(i.map(async t=>await n.repos.getViews({owner:e,repo:t})));return l.filter(({data:e})=>e).map(({data:{count:e,uniques:t}})=>(s.count+=e,s.uniques+=t)),s.count=t.format(s.count),s.uniques=t.format(s.uniques),{views:s}}catch(e){if(403===e.status)throw{error:{message:`Insufficient token rights`}};throw console.debug(e),{error:{message:`An error occured`}}}}},_={classic:async function({login:e,q:t},{conf:r,data:n,rest:a,graphql:i,plugins:l},{s:d,pending:s,imports:p}){await o(...arguments)},terminal:async function({login:e,q:t},{conf:r,data:n,rest:a,graphql:i,plugins:l},{s:d,pending:s,imports:p}){await o(...arguments),t.raw=!0}};var w=r(34651),T=r(78835),E=r(3584),A=r.t(E),O=r(32882),P=r.t(O),L=r(29483),z=r.t(L);(async function(){const[e,t,n,a,o]=[P,z,A,m,g].map(e=>e&&e.default?e.default:e),i=(e,t=!1)=>"string"==typeof e?/^(?:[Tt]rue|[Oo]n|[Yy]es)$/.test(e):t,s=[];try{console.log(`GitHub metrics as SVG image`),console.log(`========================================================`),console.log(`Version | 2.8.0-beta`),process.on("unhandledRejection",e=>{throw e}),"push"===t.context.eventName&&t.context.payload&&t.context.payload.head_commit&&/\[Skip GitHub Action\]/.test(t.context.payload.head_commit.message)&&(console.log(`Skipped because [Skip GitHub Action] is in commit message`),process.exit(0));const l=await a({log:!1});console.log(`Configuration | loaded`);const d=e.getInput("template")||"classic";console.log(`Template to use | ${d}`);const p=e.getInput("token");if(console.log(`Github token | ${p?"provided":"missing"}`),!p)throw new Error("You must provide a valid GitHub token to gather your metrics");const c=n.graphql.defaults({headers:{authorization:`token ${p}`}});console.log(`Github GraphQL API | ok`);const u=t.getOctokit(p);console.log(`Github REST API | ok`);const m=e.getInput("filename")||"github-metrics.svg";console.log(`SVG output file | ${m}`);const g=i(e.getInput("optimize"),!0);l.optimize=g,console.log(`SVG optimization | ${g}`);let h;try{h=(await u.users.getAuthenticated()).data.login}catch{h=t.context.repo.owner}const f=e.getInput("user")||h;console.log(`GitHub user | ${f}`);const y=i(e.getInput("debug"));y||(console.debug=e=>s.push(e)),console.log(`Debug mode | ${y}`);const b={};let S=(e.getInput("base")||"").split(",").map(e=>e.trim());for(const e of l.settings.plugins.base.parts)b[`base.${e}`]=S.includes(e);console.log(`Base parts | ${S.join(", ")||"(none)"}`);const x={lines:{enabled:i(e.getInput("plugin_lines"))},traffic:{enabled:i(e.ge
Line truncated
|
||||
`),i=[];for(const e of o.nodes){const t=(Date.now()-new Date(e.updatedAt).getTime())/86400000;let r=1>t?"less than 1 day ago":30>t?`${_Mathfloor(t)} day${2<=t?"s":""} ago`:new Date(e.updatedAt).toDateString().substring(4);const{enabled:n,todoCount:a,inProgressCount:o,doneCount:s}=e.progress;i.push({name:e.name,updated:r,progress:{enabled:n,todo:a,doing:o,done:s,total:a+o+s}})}return{list:i,totalCount:o.totalCount}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},topics:async function({login:e,imports:t,q:r},{enabled:n=!1}={}){try{if(!n||!r.topics)return null;let{"topics.sort":a="stars","topics.limit":o=15}=r;const i="random"===a;a={starred:"created",activity:"updated",stars:"stars",random:"created"}[a]??"starred",o=_Mathmax(1,_Mathmin(20,+o));let s=[];console.debug(`metrics/compute/${e}/plugins > topics > starting browser`);const l=await t.puppeteer.launch({headless:!0,executablePath:process.env.PUPPETEER_BROWSER_PATH,args:["--no-sandbox","--disable-extensions","--disable-setuid-sandbox","--disable-dev-shm-usage"]});console.debug(`metrics/compute/${e}/plugins > topics > loaded ${await l.version()}`);const d=await l.newPage();for(let t=1;100>=t;t++){console.debug(`metrics/compute/${e}/plugins > topics > loading page ${t}`),await d.goto(`https://github.com/stars/${e}/topics?direction=desc&page=${t}&sort=${a}`);const r=d.mainFrame();await Promise.race([r.waitForSelector("ul.repo-list"),r.waitForSelector(".blankslate")]);const n=await r.evaluate(()=>[...document.querySelectorAll("ul.repo-list li")].map(e=>({name:e.querySelector(".f3").innerText,description:e.querySelector(".f5").innerText,icon:e.querySelector("img")?.src??null})));if(!n.length)break;s.push(...n)}if(i&&(s=t.shuffle(s)),0<o){console.debug(`metrics/compute/${e}/plugins > topics > keeping only ${o} topics`);const t=s.slice(o);s=s.slice(0,o),s.push({name:`And ${t.length} more...`,description:t.map(({name:e})=>e).join(", "),icon:null})}for(const r of s)r.icon&&(console.debug(`metrics/compute/${e}/plugins > topics > processing ${r.name}`),r.icon=await t.imgb64(r.icon)),r.description=t.htmlescape(r.description);return{list:s}}catch(e){throw console.debug(e),{error:{message:`An error occured`}}}},traffic:async function({login:e,imports:t,data:r,rest:n,q:a},{enabled:o=!1}={}){try{if(!o||!a.traffic)return null;const i=r.user.repositories.nodes.map(({name:e})=>e)??[],s={count:0,uniques:0},l=await Promise.all(i.map(async t=>await n.repos.getViews({owner:e,repo:t})));return l.filter(({data:e})=>e).map(({data:{count:e,uniques:t}})=>(s.count+=e,s.uniques+=t)),s.count=t.format(s.count),s.uniques=t.format(s.uniques),{views:s}}catch(e){if(403===e.status)throw{error:{message:`Insufficient token rights`}};throw console.debug(e),{error:{message:`An error occured`}}}}},_={classic:async function({login:e,q:t},{conf:r,data:n,rest:a,graphql:i,plugins:l},{s:d,pending:s,imports:p}){await o(...arguments)},terminal:async function({login:e,q:t},{conf:r,data:n,rest:a,graphql:i,plugins:l},{s:d,pending:s,imports:p}){await o(...arguments),t.raw=!0}};var w=r(34651),T=r(78835),E=r(3584),A=r.t(E),O=r(32882),P=r.t(O),L=r(29483),z=r.t(L);(async function(){const[e,t,n,a,o]=[P,z,A,m,g].map(e=>e&&e.default?e.default:e),i=(e,t=!1)=>"string"==typeof e?/^(?:[Tt]rue|[Oo]n|[Yy]es)$/.test(e):t,s=[];try{console.log(`GitHub metrics`),console.log(`========================================================`),console.log(`Version | 2.8.0`),process.on("unhandledRejection",e=>{throw e}),"push"===t.context.eventName&&t.context.payload&&t.context.payload.head_commit&&/\[Skip GitHub Action\]/.test(t.context.payload.head_commit.message)&&(console.log(`Skipped because [Skip GitHub Action] is in commit message`),process.exit(0));const l=await a({log:!1});console.log(`Configuration | loaded`);const d=e.getInput("template")||"classic";console.log(`Template to use | ${d}`);const p=e.getInput("token");if(console.log(`Github token | ${p?"provided":"missing"}`),!p)throw new Error("You must provide a valid GitHub token to gather your metrics");const c=n.graphql.defaults({headers:{authorization:`token ${p}`}});console.log(`Github GraphQL API | ok`);const u=t.getOctokit(p);console.log(`Github REST API | ok`);const m=e.getInput("filename")||"github-metrics.svg";console.log(`SVG output file | ${m}`);const g=i(e.getInput("optimize"),!0);l.optimize=g,console.log(`SVG optimization | ${g}`);let h;try{h=(await u.users.getAuthenticated()).data.login}catch{h=t.context.repo.owner}const f=e.getInput("user")||h;console.log(`GitHub user | ${f}`);const y=i(e.getInput("debug"));y||(console.debug=e=>s.push(e)),console.log(`Debug mode | ${y}`);const b={};let S=(e.getInput("base")||"").split(",").map(e=>e.trim());for(const e of l.settings.plugins.base.parts)b[`base.${e}`]=S.includes(e);console.log(`Base parts | ${S.join(", ")||"(none)"}`);const x={lines:{enabled:i(e.ge
Line truncated
|
||||
query Sha {
|
||||
repository(owner: "${t.context.repo.owner}", name: "${t.context.repo.repo}") {
|
||||
object(expression: "${r}:${m}") { ... on Blob { oid } }
|
||||
}
|
||||
}
|
||||
`);o=e}catch(e){console.debug(e)}console.log(`Previous render sha | ${o||"none"}`),await a.repos.createOrUpdateFileContents({...t.context.repo,path:m,message:`Update ${m} - [Skip GitHub Action]`,content:Buffer.from(_).toString("base64"),...(o?{sha:o}:{})}),console.log(`Commit to repo | ok`)}console.log(`Success !`),process.exit(0)}catch(t){console.error(t),i(e.getInput("debug"))||console.log("An error occured, logging debug message :",...s),e.setFailed(t.message),process.exit(1)}})().catch(()=>process.exit(1))},12541:function(e,t,r){"use strict";function n(e,t,r){const n=new p(e,t,r);process.stdout.write(n.toString()+s.EOL)}function a(e){return l.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function o(e){return l.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}var i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t["default"]=e,t};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(12087)),l=r(74332);t.issueCommand=n,t.issue=function(e,t=""){n(e,{},t)};const d="::";class p{constructor(e,t,r){e||(e="missing.command"),this.command=e,this.properties=t,this.message=r}toString(){let e=d+this.command;if(this.properties&&0<Object.keys(this.properties).length){e+=" ";let t=!0;for(const r in this.properties)if(this.properties.hasOwnProperty(r)){const n=this.properties[r];n&&(t?t=!1:e+=",",e+=`${r}=${o(n)}`)}}return e+=`${d}${a(this.message)}`,e}}},32882:function(e,t,r){"use strict";function n(e){process.exitCode=g.Failure,a(e)}function a(e){d.issue("error",e instanceof Error?e.toString():e)}function o(e){d.issue("group",e)}function i(){d.issue("endgroup")}var s=this&&this.__awaiter||function(e,t,r,n){function a(e){return e instanceof r?e:new r(function(t){t(e)})}return new(r||(r=Promise))(function(r,o){function i(e){try{l(n.next(e))}catch(t){o(t)}}function s(e){try{l(n["throw"](e))}catch(t){o(t)}}function l(e){e.done?r(e.value):a(e.value).then(i,s)}l((n=n.apply(e,t||[])).next())})},l=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t["default"]=e,t};Object.defineProperty(t,"__esModule",{value:!0});const d=r(12541),p=r(29582),c=r(74332),u=l(r(12087)),m=l(r(85622));var g;(function(e){e[e.Success=0]="Success",e[e.Failure=1]="Failure"})(g=t.ExitCode||(t.ExitCode={})),t.exportVariable=function(e,t){const r=c.toCommandValue(t);process.env[e]=r;const n=process.env.GITHUB_ENV||"";if(n){const t=`${e}<<${"_GitHubActionsFileCommandDelimeter_"}${u.EOL}${r}${u.EOL}${"_GitHubActionsFileCommandDelimeter_"}`;p.issueCommand("ENV",t)}else d.issueCommand("set-env",{name:e},r)},t.setSecret=function(e){d.issueCommand("add-mask",{},e)},t.addPath=function(e){const t=process.env.GITHUB_PATH||"";t?p.issueCommand("PATH",e):d.issueCommand("add-path",{},e),process.env.PATH=`${e}${m.delimiter}${process.env.PATH}`},t.getInput=function(e,t){const r=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!r)throw new Error(`Input required and not supplied: ${e}`);return r.trim()},t.setOutput=function(e,t){d.issueCommand("set-output",{name:e},t)},t.setCommandEcho=function(e){d.issue("echo",e?"on":"off")},t.setFailed=n,t.isDebug=function(){return"1"===process.env.RUNNER_DEBUG},t.debug=function(e){d.issueCommand("debug",{},e)},t.error=a,t.warning=function(e){d.issue("warning",e instanceof Error?e.toString():e)},t.info=function(e){process.stdout.write(e+u.EOL)},t.startGroup=o,t.endGroup=i,t.group=function(e,t){return s(this,void 0,void 0,function*(){o(e);let r;try{r=yield t()}finally{i()}return r})},t.saveState=function(e,t){d.issueCommand("save-state",{name:e},t)},t.getState=function(e){return process.env[`STATE_${e}`]||""}},29582:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t["default"]=e,t};Object.defineProperty(t,"__esModule",{value:!0});const a=n(r(35747)),o=n(r(12087)),i=r(74332);t.issueCommand=function(e,t){const r=process.env[`GITHUB_${e}`];if(!r)throw new Error(`Unable to find environment variable for file command ${e}`);if(!a.existsSync(r))throw new Error(`Missing file at path: ${r}`);a.appendFileSync(r,`${i.toCommandValue(t)}${o.EOL}`,{encoding:"utf8"})}},74332:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.toCommandValue=function(e){return null===e||void 0===e?"":"string"==typeof e||e instanceof String?e:JSON.stringify(e)}},84873:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Context=void 0;const n=r(35747),a=r(12087);class o{constructor(){if(this.payload={},process.env.GITHUB_EVENT_PATH)if(n.existsSync(process.env.GITHUB_EVENT_PATH))this.payload=JSON.parse(n.readFileSync(pro
Line truncated
|
||||
* @file Embedded JavaScript templating engine. {@link http://ejs.co}
|
||||
* @author Matthew Eernisse <mde@fleegix.org>
|
||||
* @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
|
||||
|
||||
+61
-44
@@ -15,9 +15,9 @@
|
||||
//Runner
|
||||
try {
|
||||
//Initialization
|
||||
console.log(`GitHub metrics as SVG image`)
|
||||
console.log(`GitHub metrics`)
|
||||
console.log(`========================================================`)
|
||||
console.log(`Version | <#version>`)
|
||||
console.log(`Version | <#version>`)
|
||||
process.on("unhandledRejection", error => { throw error })
|
||||
|
||||
//Skip process if needed
|
||||
@@ -30,30 +30,30 @@
|
||||
|
||||
//Load configuration
|
||||
const conf = await setup({log:false})
|
||||
console.log(`Configuration | loaded`)
|
||||
console.log(`Configuration | loaded`)
|
||||
|
||||
//Load svg template, style, fonts and query
|
||||
const template = core.getInput("template") || "classic"
|
||||
console.log(`Template to use | ${template}`)
|
||||
console.log(`Template to use | ${template}`)
|
||||
|
||||
//Token for data gathering
|
||||
const token = core.getInput("token")
|
||||
console.log(`Github token | ${token ? "provided" : "missing"}`)
|
||||
console.log(`Github token | ${token ? "provided" : "missing"}`)
|
||||
if (!token)
|
||||
throw new Error("You must provide a valid GitHub token to gather your metrics")
|
||||
const graphql = octokit.graphql.defaults({headers:{authorization: `token ${token}`}})
|
||||
console.log(`Github GraphQL API | ok`)
|
||||
console.log(`Github GraphQL API | ok`)
|
||||
const rest = github.getOctokit(token)
|
||||
console.log(`Github REST API | ok`)
|
||||
console.log(`Github REST API | ok`)
|
||||
|
||||
//SVG output
|
||||
const filename = core.getInput("filename") || "github-metrics.svg"
|
||||
console.log(`SVG output file | ${filename}`)
|
||||
console.log(`SVG output file | ${filename}`)
|
||||
|
||||
//SVG optimization
|
||||
const optimize = bool(core.getInput("optimize"), true)
|
||||
conf.optimize = optimize
|
||||
console.log(`SVG optimization | ${optimize}`)
|
||||
console.log(`SVG optimization | ${optimize}`)
|
||||
|
||||
//GitHub user
|
||||
let authenticated
|
||||
@@ -64,20 +64,20 @@
|
||||
authenticated = github.context.repo.owner
|
||||
}
|
||||
const user = core.getInput("user") || authenticated
|
||||
console.log(`GitHub user | ${user}`)
|
||||
console.log(`GitHub user | ${user}`)
|
||||
|
||||
//Debug mode
|
||||
const debug = bool(core.getInput("debug"))
|
||||
if (!debug)
|
||||
console.debug = message => debugged.push(message)
|
||||
console.log(`Debug mode | ${debug}`)
|
||||
console.log(`Debug mode | ${debug}`)
|
||||
|
||||
//Base elements
|
||||
const base = {}
|
||||
let parts = (core.getInput("base")||"").split(",").map(part => part.trim())
|
||||
for (const part of conf.settings.plugins.base.parts)
|
||||
base[`base.${part}`] = parts.includes(part)
|
||||
console.log(`Base parts | ${parts.join(", ") || "(none)"}`)
|
||||
console.log(`Base parts | ${parts.join(", ") || "(none)"}`)
|
||||
|
||||
//Additional plugins
|
||||
const plugins = {
|
||||
@@ -95,112 +95,129 @@
|
||||
projects:{enabled:bool(core.getInput("plugin_projects"))},
|
||||
}
|
||||
let q = Object.fromEntries(Object.entries(plugins).filter(([key, plugin]) => plugin.enabled).map(([key]) => [key, true]))
|
||||
console.log(`Plugins enabled | ${Object.entries(plugins).filter(([key, plugin]) => plugin.enabled).map(([key]) => key).join(", ")}`)
|
||||
console.log(`Plugins enabled | ${Object.entries(plugins).filter(([key, plugin]) => plugin.enabled).map(([key]) => key).join(", ")}`)
|
||||
//Additional plugins options
|
||||
//Pagespeed
|
||||
if (plugins.pagespeed.enabled) {
|
||||
plugins.pagespeed.token = core.getInput("plugin_pagespeed_token")
|
||||
console.log(`Pagespeed token | ${plugins.pagespeed.token ? "provided" : "missing"}`)
|
||||
q[`pagespeed.detailed`] = bool(core.getInput(`plugin_pagespeed_detailed`))
|
||||
console.log(`Pagespeed detailed | ${q["pagespeed.detailed"]}`)
|
||||
console.log(`Pagespeed token | ${plugins.pagespeed.token ? "provided" : "missing"}`)
|
||||
console.log(`Pagespeed detailed | ${q["pagespeed.detailed"]}`)
|
||||
}
|
||||
//Languages
|
||||
if (plugins.languages.enabled) {
|
||||
for (const option of ["ignored", "skipped"])
|
||||
q[`languages.${option}`] = core.getInput(`plugin_languages_${option}`) || null
|
||||
console.log(`Languages ignored | ${q["languages.ignored"]}`)
|
||||
console.log(`Languages skipped repos | ${q["languages.skipped"]}`)
|
||||
}
|
||||
//Music
|
||||
if (plugins.music.enabled) {
|
||||
plugins.music.token = core.getInput("plugin_music_token") || ""
|
||||
for (const option of ["provider", "mode", "playlist", "limit"])
|
||||
q[`music.${option}`] = core.getInput(`plugin_music_${option}`) || null
|
||||
console.log(`Music provider | ${q["music.provider"]}`)
|
||||
console.log(`Music plugin mode | ${q["music.mode"]}`)
|
||||
console.log(`Music playlist | ${q["music.playlist"]}`)
|
||||
console.log(`Music tracks limit | ${q["music.limit"]}`)
|
||||
plugins.music.token = core.getInput("plugin_music_token") || ""
|
||||
console.log(`Music token | ${plugins.music.token ? "provided" : "missing"}`)
|
||||
console.log(`Music provider | ${q["music.provider"]}`)
|
||||
console.log(`Music plugin mode | ${q["music.mode"]}`)
|
||||
console.log(`Music playlist | ${q["music.playlist"]}`)
|
||||
console.log(`Music tracks limit | ${q["music.limit"]}`)
|
||||
console.log(`Music token | ${plugins.music.token ? "provided" : "missing"}`)
|
||||
}
|
||||
//Posts
|
||||
if (plugins.posts.enabled) {
|
||||
for (const option of ["source", "limit"])
|
||||
q[`posts.${option}`] = core.getInput(`plugin_posts_${option}`) || null
|
||||
console.log(`Posts provider | ${q["posts.provider"]}`)
|
||||
console.log(`Posts limit | ${q["posts.limit"]}`)
|
||||
console.log(`Posts provider | ${q["posts.provider"]}`)
|
||||
console.log(`Posts limit | ${q["posts.limit"]}`)
|
||||
}
|
||||
//Isocalendar
|
||||
if (plugins.isocalendar.enabled) {
|
||||
q["isocalendar.duration"] = core.getInput("plugin_isocalendar_duration") ?? "half-year"
|
||||
console.log(`Isocalendar duration| ${q["isocalendar.duration"]}`)
|
||||
console.log(`Isocalendar duration | ${q["isocalendar.duration"]}`)
|
||||
}
|
||||
//Topics
|
||||
if (plugins.topics.enabled) {
|
||||
for (const option of ["sort", "limit"])
|
||||
q[`topics.${option}`] = core.getInput(`plugin_topics_${option}`) || null
|
||||
console.log(`Topics sort mode | ${q["topics.sort"]}`)
|
||||
console.log(`Topics limit | ${q["topics.limit"]}`)
|
||||
console.log(`Topics sort mode | ${q["topics.sort"]}`)
|
||||
console.log(`Topics limit | ${q["topics.limit"]}`)
|
||||
}
|
||||
//Projects
|
||||
if (plugins.projects.enabled) {
|
||||
for (const option of ["limit"])
|
||||
q[`projects.${option}`] = core.getInput(`plugin_projects_${option}`) || null
|
||||
console.log(`Projects limit | ${q["projects.limit"]}`)
|
||||
console.log(`Projects limit | ${q["projects.limit"]}`)
|
||||
}
|
||||
|
||||
//Repositories to use
|
||||
const repositories = Number(core.getInput("repositories")) || 100
|
||||
console.log(`Repositories to use | ${repositories}`)
|
||||
console.log(`Repositories to use | ${repositories}`)
|
||||
|
||||
//Die on plugins errors
|
||||
const die = bool(core.getInput("plugins_errors_fatal"))
|
||||
console.log(`Plugin errors | ${die ? "die" : "ignore"}`)
|
||||
console.log(`Plugin errors | ${die ? "die" : "ignore"}`)
|
||||
|
||||
//Built query
|
||||
q = {...q, base:false, ...base, repositories, template}
|
||||
|
||||
//Render metrics
|
||||
const rendered = await metrics({login:user, q}, {graphql, rest, plugins, conf, die})
|
||||
console.log(`Render | complete`)
|
||||
console.log(`Render | complete`)
|
||||
|
||||
//Verify svg
|
||||
const verify = bool(core.getInput("verify"))
|
||||
console.log(`Verify SVG | ${verify}`)
|
||||
console.log(`Verify SVG | ${verify}`)
|
||||
if (verify) {
|
||||
const [libxmljs] = [await import("libxmljs")].map(m => (m && m.default) ? m.default : m)
|
||||
const parsed = libxmljs.parseXml(rendered)
|
||||
if (parsed.errors.length)
|
||||
throw new Error(`Malformed SVG : \n${parsed.errors.join("\n")}`)
|
||||
console.log(`SVG valid | yes`)
|
||||
console.log(`SVG valid | yes`)
|
||||
}
|
||||
|
||||
//Commit to repository
|
||||
const dryrun = bool(core.getInput("dryrun"))
|
||||
if (dryrun)
|
||||
console.log(`Dry-run | complete`)
|
||||
console.log(`Dry-run | complete`)
|
||||
else {
|
||||
//Repository
|
||||
console.log(`Repository | ${github.context.repo.owner}/${github.context.repo.repo}`)
|
||||
//Repository and branch
|
||||
const branch = github.context.ref.replace(/^refs[/]heads[/]/, "")
|
||||
console.log(`Repository | ${github.context.repo.owner}/${github.context.repo.repo}`)
|
||||
console.log(`Branch | ${branch}`)
|
||||
//Committer token
|
||||
const token = core.getInput("committer_token") || core.getInput("token")
|
||||
console.log(`Committer token | ${token ? "provided" : "missing"}`)
|
||||
console.log(`Committer token | ${token ? "provided" : "missing"}`)
|
||||
if (!token)
|
||||
throw new Error("You must provide a valid GitHub token to commit your metrics")
|
||||
const rest = github.getOctokit(token)
|
||||
console.log(`Committer REST API | ok`)
|
||||
console.log(`Committer REST API | ok`)
|
||||
try {
|
||||
console.log(`Committer | ${(await rest.users.getAuthenticated()).data.login}`)
|
||||
console.log(`Committer | ${(await rest.users.getAuthenticated()).data.login}`)
|
||||
}
|
||||
catch {
|
||||
console.log(`Committer | (unknown)`)
|
||||
console.log(`Committer | (unknown)`)
|
||||
}
|
||||
//Retrieve previous render SHA to be able to update file content through API
|
||||
let sha = null
|
||||
console.log(github.context.repo)
|
||||
try {
|
||||
const {data} = await rest.repos.getContent({...github.context.repo, path:filename})
|
||||
sha = data.sha
|
||||
const {repository:{object:{oid}}} = await graphql(`
|
||||
query Sha {
|
||||
repository(owner: "${github.context.repo.owner}", name: "${github.context.repo.repo}") {
|
||||
object(expression: "${branch}:${filename}") { ... on Blob { oid } }
|
||||
}
|
||||
}
|
||||
`
|
||||
)
|
||||
sha = oid
|
||||
} catch (error) { console.debug(error) }
|
||||
console.log(`Previous render sha | ${sha || "none"}`)
|
||||
console.log(`Previous render sha | ${sha || "none"}`)
|
||||
//Update file content through API
|
||||
await rest.repos.createOrUpdateFileContents({
|
||||
...github.context.repo, path:filename, message:`Update ${filename} - [Skip GitHub Action]`,
|
||||
content:Buffer.from(rendered).toString("base64"),
|
||||
...(sha ? {sha} : {})
|
||||
})
|
||||
console.log(`Commit to repo | ok`)
|
||||
console.log(`Commit to repo | ok`)
|
||||
}
|
||||
|
||||
//Success
|
||||
@@ -211,7 +228,7 @@
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
if (!bool(core.getInput("debug")))
|
||||
console.debug("An error occured, logging debug message :", ...debugged)
|
||||
console.log("An error occured, logging debug message :", ...debugged)
|
||||
core.setFailed(error.message)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
Generated
+7
-7
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "metrics",
|
||||
"version": "2.7.0-beta",
|
||||
"version": "2.8.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -352,9 +352,9 @@
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "14.14.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.12.tgz",
|
||||
"integrity": "sha512-ASH8OPHMNlkdjrEdmoILmzFfsJICvhBsFfAum4aKZ/9U4B6M6tTmTPh+f3ttWdD74CEGV5XvXWkbyfSdXaTd7g=="
|
||||
"version": "14.14.14",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.14.tgz",
|
||||
"integrity": "sha512-UHnOPWVWV1z+VV8k6L1HhG7UbGBgIdghqF3l9Ny9ApPghbjICXkUJSd/b9gOgQfjM1r+37cipdw/HJ3F6ICEnQ=="
|
||||
},
|
||||
"@types/q": {
|
||||
"version": "1.5.4",
|
||||
@@ -1349,9 +1349,9 @@
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.13.0",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
|
||||
"integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
|
||||
"version": "1.13.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz",
|
||||
"integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg=="
|
||||
},
|
||||
"forwarded": {
|
||||
"version": "0.1.2",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "metrics",
|
||||
"version": "2.8.0-beta",
|
||||
"version": "2.8.0",
|
||||
"description": "Generate an user's GitHub metrics as SVG image format to embed somewhere else",
|
||||
"main": "index.mjs",
|
||||
"scripts": {
|
||||
|
||||
+12
-6
@@ -43,6 +43,8 @@
|
||||
"base.metadata":"Metadata",
|
||||
},
|
||||
options:{
|
||||
"languages.ignored":"",
|
||||
"languages.skipped":"",
|
||||
"pagespeed.detailed":false,
|
||||
"habits.from":100,
|
||||
"music.playlist":"",
|
||||
@@ -103,8 +105,9 @@
|
||||
action() {
|
||||
return [
|
||||
`# Visit https://github.com/lowlighter/metrics/blob/master/action.yml for full reference`,
|
||||
`name: GitHub metrics as SVG image`,
|
||||
`name: GitHub metrics`,
|
||||
`on:`,
|
||||
` # Schedule updates`,
|
||||
` schedule: [{cron: "0 * * * *"}]`,
|
||||
` push: {branches: "master"}`,
|
||||
`jobs:`,
|
||||
@@ -113,16 +116,19 @@
|
||||
` steps:`,
|
||||
` - uses: lowlighter/metrics@latest`,
|
||||
` with:`,
|
||||
` # Setup a personal token in your secrets.`,
|
||||
` # You'll need to setup a personal token in your secrets.`,
|
||||
` token: ${"$"}{{ secrets.METRICS_TOKEN }}`,
|
||||
` # You can also setup a bot token for commits`,
|
||||
` # committer_token: ${"$"}{{ secrets.METRICS_BOT_TOKEN }}`,
|
||||
` # GITHUB_TOKEN is a special auto-generated token used for commits`,
|
||||
` committer_token: ${"$"}{{ secrets.GITHUB_TOKEN }}`,
|
||||
``,
|
||||
` # Options`,
|
||||
` user: ${this.user }`,
|
||||
` template: ${this.templates.selected}`,
|
||||
` base: ${Object.keys(this.plugins.enabled.base).join(", ") }`,
|
||||
...Object.entries(this.plugins.enabled).filter(([key, value]) => (key !== "base")&&(value)).map(([key]) => ` plugin_${key}: yes`)
|
||||
` base: ${Object.entries(this.plugins.enabled.base).filter(([key, value]) => value).map(([key]) => key).join(", ")||'""'}`,
|
||||
...[
|
||||
...Object.entries(this.plugins.enabled).filter(([key, value]) => (key !== "base")&&(value)).map(([key]) => ` plugin_${key}: yes`),
|
||||
...Object.entries(this.plugins.options).filter(([key, value]) => value).filter(([key, value]) => this.plugins.enabled[key.split(".")[0]]).map(([key, value]) => ` plugin_${key.replace(/[.]/, "_")}: ${typeof value === "boolean" ? {true:"yes", false:"no"}[value] : value}`)
|
||||
].sort(),
|
||||
].join("\n")
|
||||
}
|
||||
},
|
||||
|
||||
+12
-1
@@ -51,7 +51,7 @@
|
||||
</label>
|
||||
</div>
|
||||
<i>*Additional plugins may be available when used as GitHub Action</i>
|
||||
<template v-if="(plugins.enabled.music)||(plugins.enabled.pagespeed)||(plugins.enabled.habits)||(plugins.enabled.posts)||(plugins.enabled.isocalendar)||(plugins.enabled.projects)||(plugins.enabled.topics)">
|
||||
<template v-if="(plugins.enabled.music)||(plugins.enabled.pagespeed)||(plugins.enabled.languages)||(plugins.enabled.habits)||(plugins.enabled.posts)||(plugins.enabled.isocalendar)||(plugins.enabled.projects)||(plugins.enabled.topics)">
|
||||
<h3>2.3 Configure additional plugins</h3>
|
||||
<div class="options">
|
||||
<div class="options-group" v-if="plugins.enabled.music">
|
||||
@@ -72,6 +72,17 @@
|
||||
<input type="checkbox" v-model="plugins.options['pagespeed.detailed']" @change="load">
|
||||
</label>
|
||||
</div>
|
||||
<div class="options-group" v-if="plugins.enabled.languages">
|
||||
<h4>{{ plugins.descriptions.languages }}</h4>
|
||||
<label>
|
||||
Ignored languages (comma separated)
|
||||
<input type="text" v-model="plugins.options['languages.ignored']" @change="load">
|
||||
</label>
|
||||
<label>
|
||||
Skipped repositories (comma separated)
|
||||
<input type="text" v-model="plugins.options['languages.skipped']" @change="load">
|
||||
</label>
|
||||
</div>
|
||||
<div class="options-group" v-if="plugins.enabled.habits">
|
||||
<h4>{{ plugins.descriptions.habits }}</h4>
|
||||
<label>
|
||||
|
||||
@@ -1,18 +1,36 @@
|
||||
//Setup
|
||||
export default async function ({data, q}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, q}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.languages))
|
||||
return null
|
||||
//Parameters override
|
||||
let {"languages.ignored":ignored = "", "languages.skipped":skipped = ""} = q
|
||||
//Ignored languages
|
||||
ignored = decodeURIComponent(ignored).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x)
|
||||
//Skipped repositories
|
||||
skipped = decodeURIComponent(skipped).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x)
|
||||
//Iterate through user's repositories and retrieve languages data
|
||||
const languages = {colors:{}, total:0, stats:{}}
|
||||
for (const repository of data.user.repositories.nodes) {
|
||||
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
|
||||
languages.stats[name] = (languages.stats[name] ?? 0) + size
|
||||
languages.colors[name] = color ?? "#ededed"
|
||||
languages.total += size
|
||||
}
|
||||
//Skip repository if asked
|
||||
if (skipped.includes(repository.name.toLocaleLowerCase())) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > skipped repository ${repository.name}`)
|
||||
continue
|
||||
}
|
||||
//Process repository languages
|
||||
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
|
||||
//Ignore language if asked
|
||||
if (ignored.includes(name.toLocaleLowerCase())) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ignored language ${name}`)
|
||||
continue
|
||||
}
|
||||
//Update language stats
|
||||
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)
|
||||
|
||||
@@ -129,7 +129,6 @@
|
||||
`${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:{
|
||||
|
||||
Reference in new issue
Block a user