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 %>"> @@ -94,13 +95,17 @@ Community stats +
+ + Member of <%= user.organizations.totalCount %> organization<%= s(user.organizations.totalCount) %> +
Following <%= user.following.totalCount %> user<%= s(user.followers.totalCount) %>
- Sponsoring <%= computed.sponsorships %> repositor<%= s(computed.sponsorships, "y") %> + Sponsoring <%= user.sponsorshipsAsSponsor.totalCount %> repositor<%= s(user.sponsorshipsAsSponsor.totalCount, "y") %>
@@ -110,10 +115,6 @@ Watching <%= user.watching.totalCount %> repositor<%= s(user.watching.totalCount, "y") %>
-
- - Member of <%= user.organizations.totalCount %> organization<%= s(user.organizations.totalCount) %> -
<% } %> @@ -134,6 +135,10 @@ No license preference <% } %> +
+ + <%= computed.repositories.releases %> Release<%= s(computed.repositories.releases) %> +
<%= user.packages.totalCount %> Package<%= s(user.packages.totalCount) %> @@ -144,8 +149,7 @@
<% if (computed.plugins.lines) { %>
- - <% if (computed.plugins.lines.error) { %> + <% if (computed.plugins.lines.error) { %> <%= computed.plugins.lines.error.message %> <% } else { %> <%= computed.plugins.lines.added %> added, <%= computed.plugins.lines.deleted %> removed @@ -154,6 +158,10 @@ <% } %>
+
+ + <%= user.sponsorshipsAsMaintainer.totalCount %> Sponsor<%= s(user.sponsorshipsAsMaintainer.totalCount) %> +
<%= computed.repositories.stargazers %> Stargazer<%= s(computed.repositories.stargazers) %> @@ -189,7 +197,7 @@ <% if (computed.plugins.followup.error) { %>
- + <%= computed.plugins.followup.error.message %>
@@ -220,7 +228,7 @@ <% if (computed.plugins.followup.error) { %>
- + <%= computed.plugins.followup.error.message %>
@@ -255,7 +263,7 @@ <% if (computed.plugins.languages.error) { %>
- + <%= computed.plugins.languages.error.message %>
@@ -281,6 +289,38 @@
<% } %> + <% if (computed.plugins.gists) { %> +
+

+ + <%= computed.plugins.gists.totalCount %> Gist<%= s(computed.plugins.gists.totalCount) %> +

+
+ <% if (computed.plugins.gists.error) { %> +
+
+ + <%= computed.plugins.gists.error.message %> +
+
+ <% } else { %> +
+
+ + <%= computed.plugins.gists.stargazers %> Stargazer<%= s(computed.plugins.gists.stargazers) %> +
+
+
+
+ + <%= computed.plugins.gists.forks %> Fork<%= s(computed.plugins.gists.forks) %> +
+
+ <% } %> +
+
+ <% } %> + <% if (computed.plugins.pagespeed) { %>
@@ -298,7 +338,7 @@
- + <%= computed.plugins.pagespeed.error.message %>
@@ -337,7 +377,7 @@ <% if (computed.plugins.habits.error) { %>
- + <%= computed.plugins.habits.error.message %>
@@ -371,7 +411,7 @@ <% } %> <% if (computed.plugins.music.error) { %>
- + <%= computed.plugins.music.error.message %>
<% } else { %> @@ -402,14 +442,14 @@ <% if (computed.plugins.posts) { %>

- + Recent articles

<% if (computed.plugins.posts.error) { %>
- + <%= computed.plugins.posts.error.message %>
<% } else { %> @@ -449,7 +489,7 @@
<% if (computed.plugins.isocalendar.error) { %>
- + <%= computed.plugins.isocalendar.error.message %>
<% } %> @@ -462,7 +502,7 @@
- ~ <%= computed.plugins.isocalendar.average %> commits per day + ~<%= computed.plugins.isocalendar.average %> commits per day
<% } %> diff --git a/src/templates/classic/query.graphql b/src/templates/classic/query.graphql index dba776df..12aab848 100644 --- a/src/templates/classic/query.graphql +++ b/src/templates/classic/query.graphql @@ -41,6 +41,9 @@ query Metrics { pr_merged: pullRequests(states: MERGED) { totalCount } + releases { + totalCount + } forkCount licenseInfo { spdxId diff --git a/src/templates/common.mjs b/src/templates/common.mjs index 44c8c41b..036afd67 100644 --- a/src/templates/common.mjs +++ b/src/templates/common.mjs @@ -2,7 +2,7 @@ export default async function ({login, q}, {conf, data, rest, graphql, plugins}, {s, pending, imports}) { //Init - const computed = data.computed = {commits:0, sponsorships:0, licenses:{favorite:"", used:{}}, token:{}, repositories:{watchers:0, stargazers:0, issues_open:0, issues_closed:0, pr_open:0, pr_merged:0, forks:0}, plugins:{}} + const computed = data.computed = {commits:0, sponsorships:0, licenses:{favorite:"", used:{}}, token:{}, repositories:{watchers:0, stargazers:0, issues_open:0, issues_closed:0, pr_open:0, pr_merged:0, forks:0, releases:0}, plugins:{}} const avatar = imports.imgb64(data.user.avatarUrl) //Plugins @@ -23,7 +23,7 @@ //Iterate through user's repositories for (const repository of data.user.repositories.nodes) { //Simple properties with totalCount - for (const property of ["watchers", "stargazers", "issues_open", "issues_closed", "pr_open", "pr_merged"]) + for (const property of ["watchers", "stargazers", "issues_open", "issues_closed", "pr_open", "pr_merged", "releases"]) computed.repositories[property] += repository[property].totalCount //Forks computed.repositories.forks += repository.forkCount @@ -40,7 +40,6 @@ //Compute total commits and sponsorships computed.commits += data.user.contributionsCollection.totalCommitContributions + data.user.contributionsCollection.restrictedContributionsCount - computed.sponsorships = data.user.sponsorshipsAsSponsor.totalCount + data.user.sponsorshipsAsMaintainer.totalCount //Compute registration date const diff = (Date.now()-(new Date(data.user.createdAt)).getTime())/(365*24*60*60*1000) diff --git a/src/templates/terminal/image.svg b/src/templates/terminal/image.svg index 071297b5..c73e16ff 100644 --- a/src/templates/terminal/image.svg +++ b/src/templates/terminal/image.svg @@ -88,7 +88,7 @@ Last generated: <%= new Date().toGMTString() %> <% if (base.community) { -%> Tracked activity <%= `${user.following.totalCount}`.padStart(5) %> user<%= s(user.followers.totalCount) %> followed - <%= `${computed.sponsorships}`.padStart(5) %> repositor<%= s(computed.sponsorships, "y") %> sponsored + <%= `${user.sponsorshipsAsSponsor.totalCount}`.padStart(5) %> repositor<%= s(user.sponsorshipsAsSponsor.totalCount, "y") %> sponsored <%= `${user.starredRepositories.totalCount}`.padStart(5) %> repositor<%= s(user.starredRepositories.totalCount, "y") %> starred <%= `${user.watching.totalCount}`.padStart(5) %> repositor<%= s(user.watching.totalCount, "y") %> watched <% } -%> diff --git a/src/templates/terminal/query.graphql b/src/templates/terminal/query.graphql index dba776df..12aab848 100644 --- a/src/templates/terminal/query.graphql +++ b/src/templates/terminal/query.graphql @@ -41,6 +41,9 @@ query Metrics { pr_merged: pullRequests(states: MERGED) { totalCount } + releases { + totalCount + } forkCount licenseInfo { spdxId