Skip to content

Commit 11cb6f0

Browse files
authored
Add new plugin stars (lowlighter#36)
1 parent a010a33 commit 11cb6f0

File tree

12 files changed

+281
-4
lines changed

12 files changed

+281
-4
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,20 @@ But there's more with [plugins](https://github.com/lowlighter/metrics/tree/maste
147147
</td>
148148
</tr>
149149
<tr>
150+
<th><a href="https://github.com/lowlighter/metrics#-stars">🌟 Recently starred repositories</a></th>
150151
<th><a href="https://github.com/lowlighter/metrics#%EF%B8%8F-base-content">🗃️ Header special features</a></th>
151-
<th></th>
152152
</tr>
153153
<tr>
154+
<td>
155+
<a href="https://github.com/lowlighter/metrics#-stars">
156+
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.stars.svg" alt="" width="400">
157+
</a>
158+
</td>
154159
<td>
155160
<a href="https://github.com/lowlighter/metrics#%EF%B8%8F-base-content">
156161
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.header.svg" alt="" width="400">
157162
</a>
158163
</td>
159-
<td></td>
160164
</tr>
161165
<tr>
162166
<td colspan="2" align="center">
@@ -511,6 +515,7 @@ Used template defaults to the `classic` one.
511515
<th><span title="Posts">✒️</span></th>
512516
<th><span title="Habits">💡</span></th>
513517
<th><span title="Gists">🎫</span></th>
518+
<th><span title="Stars">🌟</span></th>
514519
</tr>
515520
<tr>
516521
<th>Classic</th>
@@ -528,6 +533,7 @@ Used template defaults to the `classic` one.
528533
<td>✔️</td>
529534
<td>✔️</td>
530535
<td>✔️</td>
536+
<td><span title="Available on master">✔️<sup>M</sup></span></td>
531537
</tr>
532538
<tr>
533539
<th>Terminal</th>
@@ -545,6 +551,7 @@ Used template defaults to the `classic` one.
545551
<td>❌</td>
546552
<td>❌</td>
547553
<td>✔️</td>
554+
<td>❌</td>
548555
</tr>
549556
<tr>
550557
<th>Repository<sup>R</sup></th>
@@ -562,6 +569,7 @@ Used template defaults to the `classic` one.
562569
<td>❌</td>
563570
<td>❌</td>
564571
<td>❌</td>
572+
<td>❌</td>
565573
</tr>
566574
</table>
567575

@@ -1249,6 +1257,30 @@ Add the following to your workflow :
12491257

12501258
</details>
12511259

1260+
### 🌟 Stars
1261+
1262+
🚧 This feature is available on @master
1263+
1264+
The *stars* plugin displays your recently starred repositories.
1265+
1266+
![Stars plugin](https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.stars.svg)
1267+
1268+
<details>
1269+
<summary>💬 About</summary>
1270+
1271+
It will consume an additional GitHub request.
1272+
1273+
Add the following to your workflow :
1274+
```yaml
1275+
- uses: lowlighter/metrics@latest
1276+
with:
1277+
# ... other options
1278+
plugin_stars: yes
1279+
plugin_stars_limit: 4
1280+
```
1281+
1282+
</details>
1283+
12521284
### 🔧 Other options
12531285

12541286
A few additional options are available.

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ inputs:
347347
description: Number of tweets to display
348348
default: 2
349349

350+
# Display recently starred repositories
351+
plugin_stars:
352+
description: Display recently starred repositories
353+
default: no
354+
355+
# Number of recently starred repositories to display
356+
plugin_stars_limit:
357+
description: Number of recently starred repositories to display
358+
default: 4
359+
350360
# ====================================================================================
351361
# Options below are mostly used for testing
352362

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": "3.0.0",
3+
"version": "3.1.0-beta",
44
"description": "An image generator with 20+ metrics about your GitHub account such as activity, community, repositories, coding habits, website performances, music played, starred topics, etc. that you can put on your profile or elsewhere !",
55
"main": "index.mjs",
66
"scripts": {

settings.example.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@
5656
"enabled":false, "//":"Enable or disable personal projects display"
5757
},
5858
"tweets":{ "//":"Tweets plugin",
59-
"enabled":false, "//":"Enable or disable recent tweets display",
59+
"enabled":false, "//":"Enable or disable recent tweets display",
6060
"token":null, "//":"Twitter token (required when enabled)"
61+
},
62+
"stars":{ "//":"Stars plugin",
63+
"enabled":true, "//":"Enable or disable recently starred repositories display"
6164
}
6265
}
6366
}

source/app/action/index.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
topics:{enabled:input.bool("plugin_topics")},
140140
projects:{enabled:input.bool("plugin_projects")},
141141
tweets:{enabled:input.bool("plugin_tweets")},
142+
stars:{enabled:input.bool("plugin_stars")},
142143
}
143144
let q = Object.fromEntries(Object.entries(plugins).filter(([key, plugin]) => plugin.enabled).map(([key]) => [key, true]))
144145
info("Plugins enabled", Object.entries(plugins).filter(([key, plugin]) => plugin.enabled).map(([key]) => key))
@@ -208,6 +209,11 @@
208209
for (const option of ["limit"])
209210
info(`Tweets ${option}`, q[`tweets.${option}`] = input.number(`plugin_tweets_${option}`))
210211
}
212+
//Stars
213+
if (plugins.posts.enabled) {
214+
for (const option of ["limit"])
215+
info(`Stars ${option}`, q[`stars.${option}`] = input.number(`plugin_stars_${option}`))
216+
}
211217

212218
//Repositories to use
213219
const repositories = input.number("repositories")

source/app/mocks.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,43 @@
259259
}
260260
})
261261
}
262+
//Starred repositories query
263+
if (/^query Starred /.test(query)) {
264+
console.debug(`metrics/compute/mocks > mocking graphql api result > Starred`)
265+
return ({
266+
user:{
267+
starredRepositories:{
268+
edges:[
269+
{
270+
starredAt:"2020-10-16T18:53:16Z",
271+
node:{
272+
description:"📊 An image generator with 20+ metrics about your GitHub account such as activity, community, repositories, coding habits, website performances, music played, starred topics, etc. that you can put on your profile or elsewhere !",
273+
forkCount:12,
274+
isFork:false,
275+
issues:{
276+
totalCount: 12
277+
},
278+
nameWithOwner:"lowlighter/metrics",
279+
openGraphImageUrl:"https://repository-images.githubusercontent.com/293860197/7fd72080-496d-11eb-8fe0-238b38a0746a",
280+
pullRequests:{
281+
totalCount:23
282+
},
283+
stargazerCount:120,
284+
licenseInfo:{
285+
nickname:null,
286+
name:"MIT License"
287+
},
288+
primaryLanguage:{
289+
color:"#f1e05a",
290+
name:"JavaScript"
291+
}
292+
}
293+
},
294+
]
295+
}
296+
}
297+
})
298+
}
262299
//Unmocked call
263300
return target(...args)
264301
}

source/app/web/statics/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
topics:"Starred topics",
4646
projects:"Projects",
4747
tweets:"Latest tweets",
48+
stars:"Recently starred repositories",
4849
"base.header":"Header",
4950
"base.activity":"Account activity",
5051
"base.community":"Community stats",
@@ -71,6 +72,7 @@
7172
"topics.sort":"stars",
7273
"topics.limit":12,
7374
"tweets.limit":2,
75+
"stars.limit":4,
7476
},
7577
},
7678
templates:{

source/plugins/stars/index.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//Setup
2+
export default async function ({login, graphql, q, queries, imports}, {enabled = false} = {}) {
3+
//Plugin execution
4+
try {
5+
//Check if plugin is enabled and requirements are met
6+
if ((!enabled)||(!q.stars))
7+
return null
8+
//Parameters override
9+
let {"stars.limit":limit = 4} = q
10+
//Limit
11+
limit = Math.max(1, Math.min(100, Number(limit)))
12+
//Retrieve user stars from graphql api
13+
console.debug(`metrics/compute/${login}/plugins > stars > querying api`)
14+
const {user:{starredRepositories:{edges:repositories}}} = await graphql(queries.starred({login, limit}))
15+
//Format starred repositories
16+
for (const edge of repositories) {
17+
//Formats values
18+
edge.node.stargazers = imports.format(edge.node.stargazerCount)
19+
edge.node.forks = imports.format(edge.node.forkCount)
20+
//Format date
21+
const time = (Date.now()-new Date(edge.starredAt).getTime())/(24*60*60*1000)
22+
let updated = new Date(edge.starredAt).toDateString().substring(4)
23+
if (time < 1)
24+
updated = `${Math.ceil(time*24)} hour${Math.ceil(time*24) >= 2 ? "s" : ""} ago`
25+
else if (time < 30)
26+
updated = `${Math.floor(time)} day${time >= 2 ? "s" : ""} ago`
27+
edge.starred = updated
28+
}
29+
//Results
30+
return {repositories}
31+
}
32+
//Handle errors
33+
catch (error) {
34+
throw {error:{message:"An error occured", instance:error}}
35+
}
36+
}

source/queries/starred.graphql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
query Starred {
2+
user(login: "$login") {
3+
starredRepositories(first: $limit, orderBy: {field: STARRED_AT, direction: DESC}) {
4+
edges {
5+
starredAt
6+
node {
7+
description
8+
forkCount
9+
isFork
10+
issues {
11+
totalCount
12+
}
13+
nameWithOwner
14+
openGraphImageUrl
15+
licenseInfo {
16+
nickname
17+
name
18+
}
19+
pullRequests {
20+
totalCount
21+
}
22+
stargazerCount
23+
primaryLanguage {
24+
color
25+
name
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}

source/templates/classic/image.svg

Lines changed: 70 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)