The great refactor (#82)
This commit is contained in:
26
source/plugins/traffic/README.md
Normal file
26
source/plugins/traffic/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
### 🧮 Repositories traffic
|
||||
|
||||
⚠️ This plugin requires a personal token with repo scope.
|
||||
|
||||
The repositories *traffic* plugin displays the number of page views across your repositories.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.traffic.svg">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
Because of GitHub REST API limitation, provided token requires full `repo` scope to access traffic informations.
|
||||
|
||||

|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_traffic: yes
|
||||
```
|
||||
@@ -1,19 +1,26 @@
|
||||
//Setup
|
||||
export default async function ({login, imports, data, rest, q}, {enabled = false} = {}) {
|
||||
export default async function ({login, imports, data, rest, q, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.traffic))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
imports.metadata.plugins.traffic.inputs({data, account, q})
|
||||
|
||||
//Repositories
|
||||
const repositories = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})) ?? []
|
||||
|
||||
//Get views stats from repositories
|
||||
console.debug(`metrics/compute/${login}/plugins > traffic > querying api`)
|
||||
const views = {count:0, uniques:0}
|
||||
const response = await Promise.all(repositories.map(async ({repo, owner}) => await rest.repos.getViews({owner, repo})))
|
||||
|
||||
//Compute views
|
||||
console.debug(`metrics/compute/${login}/plugins > traffic > computing stats`)
|
||||
response.filter(({data}) => data).map(({data:{count, uniques}}) => (views.count += count, views.uniques += uniques))
|
||||
|
||||
//Results
|
||||
return {views}
|
||||
}
|
||||
|
||||
13
source/plugins/traffic/metadata.yml
Normal file
13
source/plugins/traffic/metadata.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
name: "🧮 Repositories traffic"
|
||||
cost: 1 REST request per repository
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
- repository
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_traffic:
|
||||
description: Display repositories traffic metrics
|
||||
type: boolean
|
||||
default: no
|
||||
Reference in New Issue
Block a user