The great refactor (#82)

This commit is contained in:
Simon Lecoq
2021-01-30 12:31:09 +01:00
committed by GitHub
parent f8c6d19a4e
commit 682e43e10b
158 changed files with 6738 additions and 5022 deletions

View File

@@ -0,0 +1,21 @@
### ✨ Stargazers over last weeks
The *stargazers* plugin displays your stargazers evolution across all of your repositories over the last two weeks.
<table>
<td align="center">
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.stargazers.svg">
<img width="900" height="1" alt="">
</td>
</table>
#### Examples workflows
[➡️ Available options for this plugin](metadata.yml)
```yaml
- uses: lowlighter/metrics@latest
with:
# ... other options
plugin_stargazers: yes
```

View File

@@ -1,10 +1,14 @@
//Setup
export default async function ({login, graphql, data, q, queries}, {enabled = false} = {}) {
export default async function ({login, graphql, data, imports, q, queries, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.stargazers))
return null
//Load inputs
imports.metadata.plugins.stargazers.inputs({data, account, q})
//Retrieve stargazers from graphql api
console.debug(`metrics/compute/${login}/plugins > stargazers > querying api`)
const repositories = data.user.repositories.nodes.map(({name:repository, owner:{login:owner}}) => ({repository, owner})) ?? []
@@ -25,6 +29,7 @@
console.debug(`metrics/compute/${login}/plugins > stargazers > loaded ${dates.length} stargazers for ${repository}`)
}
console.debug(`metrics/compute/${login}/plugins > stargazers > loaded ${dates.length} stargazers in total`)
//Compute stargazers increments
const days = 14
const increments = {dates:Object.fromEntries([...new Array(days).fill(null).map((_, i) => [new Date(Date.now()-i*24*60*60*1000).toISOString().slice(0, 10), 0]).reverse()]), max:NaN, min:NaN}
@@ -34,6 +39,7 @@
.map(date => increments.dates[date]++)
increments.min = Math.min(...Object.values(increments.dates))
increments.max = Math.max(...Object.values(increments.dates))
//Compute total stargazers
let stargazers = data.computed.repositories.stargazers
const total = {dates:{...increments.dates}, max:NaN, min:NaN}
@@ -47,8 +53,10 @@
}
total.min = Math.min(...Object.values(total.dates))
total.max = Math.max(...Object.values(total.dates))
//Months name
const months = ["", "Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]
//Results
return {total, increments, months}
}

View File

@@ -0,0 +1,13 @@
name: "✨ Stargazers over last weeks"
cost: 1 GraphQL request per 100 stargazers
supports:
- user
- organization
- repository
inputs:
# Enable or disable plugin
plugin_stargazers:
description: Display stargazers metrics
type: boolean
default: no

View File

@@ -0,0 +1,10 @@
query StargazersDefault {
repository(name: "$repository", owner: "$login") {
stargazers($after first: 100, orderBy: {field: STARRED_AT, direction: ASC}) {
edges {
starredAt
cursor
}
}
}
}