From e05442017ad2ba51b01a39903ab398f62190d86a Mon Sep 17 00:00:00 2001
From: lowlighter <22963968+lowlighter@users.noreply.github.com>
Date: Fri, 6 Nov 2020 21:16:47 +0100
Subject: [PATCH] Version 2.4
- Add new plugin "Gists"
- Fix sponsorships
- Minor icons changes
- Add new repositories metrics "sponsors" and and "releases"
---
package.json | 2 +-
settings.example.json | 3 ++
src/html/app.js | 1 +
src/plugins/gists/index.mjs | 51 ++++++++++++++++++
src/plugins/index.mjs | 2 +
src/plugins/posts/index.mjs | 2 +-
src/templates/classic/image.svg | 78 +++++++++++++++++++++-------
src/templates/classic/query.graphql | 3 ++
src/templates/common.mjs | 5 +-
src/templates/terminal/image.svg | 2 +-
src/templates/terminal/query.graphql | 3 ++
11 files changed, 127 insertions(+), 25 deletions(-)
create mode 100644 src/plugins/gists/index.mjs
diff --git a/package.json b/package.json
index 60d0d61d..a31ca565 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "metrics",
- "version": "2.3.0",
+ "version": "2.4.0",
"description": "Generate an user's GitHub metrics as SVG image format to embed somewhere else",
"main": "index.mjs",
"scripts": {
diff --git a/settings.example.json b/settings.example.json
index 840d36a2..c62fd6f0 100644
--- a/settings.example.json
+++ b/settings.example.json
@@ -44,6 +44,9 @@
},
"isocalendar":{ "//":"Isometric calendar plugin",
"enabled":false, "//":"Enable or disable isometric calendar"
+ },
+ "gists":{ "//":"Gists plugin",
+ "enabled":false, "//":"Enable or disable gists metrics"
}
}
}
\ No newline at end of file
diff --git a/src/html/app.js b/src/html/app.js
index 12d7c0af..55923b20 100644
--- a/src/html/app.js
+++ b/src/html/app.js
@@ -31,6 +31,7 @@
music:"Music plugin",
posts:"Recent posts",
isocalendar:"Isometric commit calendar",
+ gists:"Gists metrics",
"base.header":"Header",
"base.activity":"Account activity",
"base.community":"Community stats",
diff --git a/src/plugins/gists/index.mjs b/src/plugins/gists/index.mjs
new file mode 100644
index 00000000..6cbba94f
--- /dev/null
+++ b/src/plugins/gists/index.mjs
@@ -0,0 +1,51 @@
+//Setup
+ export default async function ({login, graphql, q}, {enabled = false} = {}) {
+ //Plugin execution
+ try {
+ //Check if plugin is enabled and requirements are met
+ if ((!enabled)||(!q.gists))
+ return null
+
+ //Retrieve contribution calendar from graphql api
+ const {user:{gists}} = await graphql(`
+ query Gists {
+ user(login: "${login}") {
+ gists(last: 100) {
+ totalCount
+ nodes {
+ stargazerCount
+ isFork
+ forks {
+ totalCount
+ }
+ comments {
+ totalCount
+ }
+ }
+ }
+ }
+ }
+ `
+ )
+
+ //Iterate through gists
+ let stargazers = 0, forks = 0, comments = 0
+ for (const gist of gists.nodes) {
+ //Skip forks
+ if (gist.isFork)
+ continue
+ //Compute stars, forks and comments
+ stargazers += gist.stargazerCount
+ forks += gist.forks.totalCount
+ comments += gist.comments.totalCount
+ }
+
+ //Results
+ return {totalCount:gists.totalCount, stargazers, forks, comments}
+ }
+ //Handle errors
+ catch (error) {
+ console.debug(error)
+ throw {error:{message:`An error occured`}}
+ }
+ }
diff --git a/src/plugins/index.mjs b/src/plugins/index.mjs
index 534b6b74..bdce5842 100644
--- a/src/plugins/index.mjs
+++ b/src/plugins/index.mjs
@@ -2,6 +2,7 @@
//Imports
import followup from "./followup/index.mjs"
+ import gists from "./gists/index.mjs"
import habits from "./habits/index.mjs"
import isocalendar from "./isocalendar/index.mjs"
import languages from "./languages/index.mjs"
@@ -15,6 +16,7 @@
//Exports
export default {
followup,
+ gists,
habits,
isocalendar,
languages,
diff --git a/src/plugins/posts/index.mjs b/src/plugins/posts/index.mjs
index ec556881..1f98474f 100644
--- a/src/plugins/posts/index.mjs
+++ b/src/plugins/posts/index.mjs
@@ -28,7 +28,7 @@
if (Array.isArray(posts)) {
//Limit tracklist
if (limit > 0) {
- console.debug(`metrics/compute/${login}/plugins > music > keeping only ${limit} posts`)
+ console.debug(`metrics/compute/${login}/plugins > posts > keeping only ${limit} posts`)
posts = posts.slice(0, limit)
}
//Results
diff --git a/src/templates/classic/image.svg b/src/templates/classic/image.svg
index 74a9cc72..44ced250 100644
--- a/src/templates/classic/image.svg
+++ b/src/templates/classic/image.svg
@@ -2,7 +2,7 @@
+ (!!base.header)*80
+ (!!base.metadata)*38
+ ((!!base.activity)||(!!base.community))*128
- + (!!base.repositories)*92
+ + (!!base.repositories)*108
+ ((!!base.repositories)*((!!computed.plugins.traffic)||(!!computed.plugins.lines)))*16
+ (!!computed.plugins.followup)*68
+ (!!computed.plugins.pagespeed)*126
@@ -11,7 +11,8 @@
+ (!!computed.plugins.music)*64 + (computed.plugins.music ? computed.plugins.music.tracks ? 14+Math.max(0, computed.plugins.music.tracks.length-1)*36 : 0 : 0)
+ (!!computed.plugins.posts)*64 + (computed.plugins.posts ? computed.plugins.posts.posts ? Math.max(0, computed.plugins.posts.posts.length)*40 : 0 : 0)
+ (!!computed.plugins.isocalendar)*180
- + Math.max(0, (((!!base.metadata)+(!!base.header)+((!!base.activity)||(!!base.community))+(!!base.repositories)+((!!computed.plugins.habits))+(!!computed.plugins.pagespeed)+(!!computed.plugins.languages)+(!!computed.plugins.music)+(!!computed.plugins.posts)+(!!computed.plugins.isocalendar))-1))*4
+ + (!!computed.plugins.gists)*68
+ + Math.max(0, (((!!base.metadata)+(!!base.header)+((!!base.activity)||(!!base.community))+(!!base.repositories)+((!!computed.plugins.habits))+(!!computed.plugins.pagespeed)+(!!computed.plugins.languages)+(!!computed.plugins.music)+(!!computed.plugins.posts)+(!!computed.plugins.isocalendar)+(!!computed.plugins.gists))-1))*4
%>">