Skip to content

Commit 66ace41

Browse files
committed
Add support for prefered license and gists count
1 parent 66cd9d4 commit 66ace41

File tree

7 files changed

+55
-13
lines changed

7 files changed

+55
-13
lines changed

action/dist/index.js

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/index.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
//Runner
1212
try {
1313
//Initialization
14-
console.log(`GitHub metrics as SVG image [v1.2]`)
14+
console.log(`GitHub metrics as SVG image`)
1515
console.log(`========================================================`)
16+
console.log(`Version | <#version>`)
1617
process.on("unhandledRejection", error => { throw error })
1718

1819
//Load svg template, style and query
@@ -56,6 +57,8 @@
5657
//Commit to repository
5758
{
5859
const rest = github.getOctokit(committer)
60+
const {data:{login:committer}} = await rest.users.getAuthenticated()
61+
console.log(`Committer | ${committer}`)
5962
let sha = undefined
6063
try {
6164
const {data} = await rest.repos.getContent({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metrics",
3-
"version": "1.0.0",
3+
"version": "1.3.0",
44
"description": "Generate an user's GitHub metrics as SVG image format to embed somewhere else",
55
"main": "index.mjs",
66
"scripts": {

src/metrics.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
//Init
1919
const languages = {colors:{}, total:0, stats:{}}
20-
const computed = data.computed = {commits:0, languages, repositories:{watchers:0, stargazers:0, issues_open:0, issues_closed:0, pr_open:0, pr_merged:0, forks:0}, plugins:{}}
20+
const licenses = {favorite:"", used:{}}
21+
const computed = data.computed = {commits:0, languages, licenses, repositories:{watchers:0, stargazers:0, issues_open:0, issues_closed:0, pr_open:0, pr_merged:0, forks:0}, plugins:{}}
2122
const avatar = imgb64(data.user.avatarUrl)
2223
const pending = []
2324

@@ -40,6 +41,9 @@
4041
languages.colors[name] = color || "#ededed"
4142
languages.total += size
4243
}
44+
//License
45+
if (repository.licenseInfo)
46+
licenses.used[repository.licenseInfo.spdxId] = (licenses.used[repository.licenseInfo.spdxId] || 0) + 1
4347
}
4448

4549
//Compute count for issues and pull requests
@@ -62,6 +66,9 @@
6266
for (let i = 1; i < languages.favorites.length; i++)
6367
languages.favorites[i].x = languages.favorites[i-1].x + languages.favorites[i-1].value
6468

69+
//Compute licenses stats
70+
licenses.favorite = Object.entries(licenses.used).sort(([an, a], [bn, b]) => b - a).slice(0, 1).map(([name, value]) => name) || ""
71+
6572
//Compute calendar
6673
computed.calendar = data.user.calendar.contributionCalendar.weeks.flatMap(({contributionDays}) => contributionDays).slice(0, 14).reverse()
6774

src/query.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ query Metrics {
55
createdAt
66
avatarUrl
77
websiteUrl
8+
gists {
9+
totalCount
10+
}
811
repositories(last: 100, isFork: false, ownerAffiliations: OWNER) {
912
totalCount
1013
nodes {
@@ -37,6 +40,9 @@ query Metrics {
3740
totalCount
3841
}
3942
forkCount
43+
licenseInfo {
44+
spdxId
45+
}
4046
}
4147
}
4248
packages {

src/template.svg

Lines changed: 12 additions & 4 deletions
Loading

utils/build.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
//Perform static includes
1818
for (const match of [...code.match(/(?<=`)<#include (.+?)>(?=`)/g)]) {
1919
const file = match.match(/<#include (.+?)>/)[1]
20-
code = code.replace(`<#include ${file}>`, `${await fs.promises.readFile(path.join("src", file))}`.replace(/([$`])/g, "\\$1"))
20+
code = code.replace(`<#include ${file}>`, `${await fs.promises.readFile(path.join(__dirname, "..", "src", file))}`.replace(/([$`])/g, "\\$1"))
2121
console.log(`Included ${file}`)
2222
}
2323

24+
//Perform version include
25+
const version = JSON.parse(await fs.promises.readFile(path.join(__dirname, "..", "package.json"))).version
26+
code = code.replace(`<#version>`, version)
27+
2428
//Save build
2529
await fs.promises.writeFile(`${__dirname}/dist/index.js`, code)

0 commit comments

Comments
 (0)