Refactor source paths

This commit is contained in:
linguist
2020-12-30 20:05:31 +01:00
parent dd0b3c5626
commit e38614a100
45 changed files with 32 additions and 36 deletions

View File

@@ -0,0 +1,31 @@
//Setup
export default async function ({login, graphql, q, queries}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.gists))
return null
//Retrieve gists from graphql api
console.debug(`metrics/compute/${login}/plugins > gists > querying api`)
const {user:{gists}} = await graphql(queries.gists({login}))
//Iterate through gists
console.debug(`metrics/compute/${login}/plugins > gists > processing ${gists.nodes.length} gists`)
let stargazers = 0, forks = 0, comments = 0, files = 0
for (const gist of gists.nodes) {
//Skip forks
if (gist.isFork)
continue
//Compute stars, forks, comments and files count
stargazers += gist.stargazerCount
forks += gist.forks.totalCount
comments += gist.comments.totalCount
files += gist.files.length
}
//Results
return {totalCount:gists.totalCount, stargazers, forks, files, comments}
}
//Handle errors
catch (error) {
throw {error:{message:"An error occured", instance:error}}
}
}