The great refactor (#82)
This commit is contained in:
21
source/plugins/gists/README.md
Normal file
21
source/plugins/gists/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
### 🎫 Gists
|
||||
|
||||
The *gists* plugin displays your [gists](https://gist.github.com) metrics.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.gists.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_gists: yes
|
||||
```
|
||||
@@ -1,12 +1,14 @@
|
||||
//Setup
|
||||
export default async function ({login, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, graphql, q, imports, queries, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.gists))
|
||||
return null
|
||||
if (account === "organization")
|
||||
throw {error:{message:"Not available for organizations"}}
|
||||
|
||||
//Load inputs
|
||||
imports.metadata.plugins.gists.inputs({data, account, q})
|
||||
|
||||
//Query gists from GitHub API
|
||||
const gists = []
|
||||
{
|
||||
@@ -23,6 +25,7 @@
|
||||
} while ((pushed)&&(cursor))
|
||||
console.debug(`metrics/compute/${login}/plugins > gists > loaded ${gists.length} gists`)
|
||||
}
|
||||
|
||||
//Iterate through gists
|
||||
console.debug(`metrics/compute/${login}/plugins > gists > processing ${gists.length} gists`)
|
||||
let stargazers = 0, forks = 0, comments = 0, files = 0
|
||||
@@ -36,6 +39,7 @@
|
||||
comments += gist.comments.totalCount
|
||||
files += gist.files.length
|
||||
}
|
||||
|
||||
//Results
|
||||
return {totalCount:gists.totalCount, stargazers, forks, files, comments}
|
||||
}
|
||||
|
||||
11
source/plugins/gists/metadata.yml
Normal file
11
source/plugins/gists/metadata.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
name: "🎫 Gists"
|
||||
cost: 1 GraphQL request per 100 gists
|
||||
supports:
|
||||
- user
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_gists:
|
||||
description: Display gists metrics
|
||||
type: boolean
|
||||
default: no
|
||||
23
source/plugins/gists/queries/gists.graphql
Normal file
23
source/plugins/gists/queries/gists.graphql
Normal file
@@ -0,0 +1,23 @@
|
||||
query GistsDefault {
|
||||
user(login: "$login") {
|
||||
gists($after first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
edges {
|
||||
cursor
|
||||
}
|
||||
totalCount
|
||||
nodes {
|
||||
stargazerCount
|
||||
isFork
|
||||
forks {
|
||||
totalCount
|
||||
}
|
||||
files {
|
||||
name
|
||||
}
|
||||
comments {
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user