Skip to content

Commit eaa844e

Browse files
authored
Add support for full year display in isocalendar (lowlighter#10)
* fix(inst): base=0 flag combined with other base.part flags is now correctly handled * ref(plugins): Space adjustements in plugins code * feat(plugins/isocalendar): Add support for full year * feat(repo): Update package.json * fix(plugins/isocalendar): Isocalendar first row sometimes displayed 6 days instead of 7
1 parent 3a180ef commit eaa844e

File tree

11 files changed

+124
-164
lines changed

11 files changed

+124
-164
lines changed

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ inputs:
194194
description: Display an isometric view of your commits calendar, along with a few additional stats
195195
default: no
196196

197+
# Duration shown by isometric calendar plugin
198+
# Supported values are "half-year" and "full-year"
199+
plugin_isocalendar_duration:
200+
description: Set isometric calendar duration
201+
default: half-year
202+
197203
# Gists plugins
198204
# Display gists metrics
199205
plugin_gists:

action/dist/index.js

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

action/index.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
console.log(`Posts provider | ${q["posts.provider"]}`)
111111
console.log(`Posts limit | ${q["posts.limit"]}`)
112112
}
113+
//Isocalendar
114+
if (plugins.isocalendar.enabled) {
115+
q["isocalendar.duration"] = core.getInput("plugin_isocalendar_duration") ?? "half-year"
116+
console.log(`Isocalendar duration| ${q["isocalendar.duration"]}`)
117+
}
113118

114119
//Repositories to use
115120
const repositories = Number(core.getInput("repositories")) || 100

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "metrics",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "Generate an user's GitHub metrics as SVG image format to embed somewhere else",
55
"main": "index.mjs",
66
"scripts": {
@@ -29,11 +29,11 @@
2929
"compression": "^1.7.4",
3030
"ejs": "^3.1.5",
3131
"express": "^4.17.1",
32-
"express-rate-limit": "^5.1.3",
32+
"express-rate-limit": "^5.2.3",
3333
"image-to-base64": "^2.1.1",
3434
"memory-cache": "^0.2.0",
3535
"prismjs": "^1.22.0",
36-
"puppeteer": "^5.4.1",
36+
"puppeteer": "^5.5.0",
3737
"svgo": "^1.3.2",
3838
"vue": "^2.6.12",
3939
"vue-prism-component": "^1.2.0"

src/metrics.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828
//Base parts
2929
if (("base" in q)&&(!q.base))
30-
conf.settings.plugins.base.parts.map(part => q[`base.${part}`] = false)
30+
conf.settings.plugins.base.parts.map(part => !(`base.${part}` in q) ? q[`base.${part}`] = false : false)
3131
for (const part of conf.settings.plugins.base.parts)
32-
data.base[part] = (`base.${part}` in q) ? !!q[`base.${part}`] : true
32+
data.base[part] = !!q[`base.${part}`]
3333

3434
//Placeholder
3535
if (login === "placeholder")

src/plugins/gists/index.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//Check if plugin is enabled and requirements are met
66
if ((!enabled)||(!q.gists))
77
return null
8-
98
//Retrieve contribution calendar from graphql api
109
const {user:{gists}} = await graphql(`
1110
query Gists {
@@ -27,7 +26,6 @@
2726
}
2827
`
2928
)
30-
3129
//Iterate through gists
3230
let stargazers = 0, forks = 0, comments = 0
3331
for (const gist of gists.nodes) {
@@ -39,7 +37,6 @@
3937
forks += gist.forks.totalCount
4038
comments += gist.comments.totalCount
4139
}
42-
4340
//Results
4441
return {totalCount:gists.totalCount, stargazers, forks, comments}
4542
}

src/plugins/isocalendar/index.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
//Check if plugin is enabled and requirements are met
66
if ((!enabled)||(!q.isocalendar))
77
return null
8-
//Compute start day (need to start on monday to ensure last row is complete)
9-
const from = new Date(Date.now()-180*24*60*60*1000)
10-
const day = from.getDay()||7
11-
if (day !== 1)
12-
from.setHours(-24*(day-1))
8+
//Parameters override
9+
let {"isocalendar.duration":duration = "half-year"} = q
10+
//Duration in days
11+
const leap = (new Date(new Date().getYear(), 1, 29).getDate() === 29)
12+
const days = {"half-year":180, "full-year":365 + leap}[duration] ?? 180
13+
//Compute start day (to ensure last row is complete, we'll retrieve one more week that we'll shift later)
14+
const from = new Date(Date.now()-days*24*60*60*1000)
15+
from.setHours(-24*7)
1316
//Retrieve contribution calendar from graphql api
1417
const {user:{calendar:{contributionCalendar:calendar}}} = await graphql(`
1518
query Calendar {
@@ -29,6 +32,7 @@
2932
}
3033
`
3134
)
35+
calendar.weeks.shift()
3236
//Compute the highest contributions in a day, streaks and average commits per day
3337
let max = 0, streak = {max:0, current:0}, values = [], average = 0
3438
for (const week of calendar.weeks) {
@@ -44,7 +48,7 @@
4448
const size = 6
4549
let i = 0, j = 0
4650
let svg = `
47-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="margin-top: -52px;" viewBox="0,0 480,170">
51+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="margin-top: -52px;" viewBox="0,0 480,${duration === "full-year" ? 270 : 170}">
4852
${[1, 2].map(k => `
4953
<filter id="brightness${k}">
5054
<feComponentTransfer>
@@ -73,7 +77,7 @@
7377
}
7478
svg += `</g></svg>`
7579
//Results
76-
return {streak, max, average, svg}
80+
return {streak, max, average, svg, duration}
7781
}
7882
//Handle errors
7983
catch (error) {

src/plugins/music/index.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
//Check if plugin is enabled and requirements are met
2424
if ((!enabled)||(!q.music))
2525
return null
26-
2726
//Initialization
2827
const raw = {
2928
get provider() { return providers[provider]?.name ?? "" },
3029
get mode() { return modes[mode] ?? "Unconfigured music plugin"},
3130
}
3231
let tracks = null
33-
3432
//Parameters override
3533
let {"music.provider":provider = "", "music.mode":mode = "", "music.playlist":playlist = null, "music.limit":limit = 4} = q
3634
//Auto-guess parameters
@@ -57,7 +55,6 @@
5755
}
5856
//Limit
5957
limit = Math.max(1, Math.min(100, Number(limit)))
60-
6158
//Handle mode
6259
switch (mode) {
6360
//Playlist mode

src/plugins/posts/index.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
//Check if plugin is enabled and requirements are met
66
if ((!enabled)||(!q.posts))
77
return null
8-
98
//Parameters override
109
const login = data.user.login
1110
let {"posts.source":source = "", "posts.limit":limit = 4} = q
1211
//Limit
1312
limit = Math.max(1, Math.min(30, Number(limit)))
14-
1513
//Retrieve posts
1614
let posts = null
1715
switch (source) {

0 commit comments

Comments
 (0)