Add basic support for organizations (#80)

This commit is contained in:
Simon Lecoq
2021-01-25 23:47:24 +01:00
committed by GitHub
parent d4d873bb39
commit 1c8dcbc8aa
21 changed files with 178 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
//Setup
export default async function ({login, graphql, data, q, queries, imports}, {enabled = false} = {}) {
export default async function ({login, graphql, data, q, queries}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
@@ -7,16 +7,16 @@
return null
//Retrieve stargazers from graphql api
console.debug(`metrics/compute/${login}/plugins > stargazers > querying api`)
const repositories = data.user.repositories.nodes.map(({name}) => name).slice(0, 2)
const repositories = data.user.repositories.nodes.map(({name:repository, owner:{login:owner}}) => ({repository, owner})) ?? []
const dates = []
for (const repository of repositories) {
for (const {repository, owner} of repositories) {
//Iterate through stargazers
console.debug(`metrics/compute/${login}/plugins > stargazers > retrieving stargazers of ${repository}`)
let cursor = null
let pushed = 0
do {
console.debug(`metrics/compute/${login}/plugins > stargazers > retrieving stargazers of ${repository} after ${cursor}`)
const {repository:{stargazers:{edges}}} = await graphql(queries.stargazers({login, repository, after:cursor ? `after: "${cursor}"` : ""}))
const {repository:{stargazers:{edges}}} = await graphql(queries.stargazers({login:owner, repository, after:cursor ? `after: "${cursor}"` : ""}))
cursor = edges?.[edges?.length-1]?.cursor
dates.push(...edges.map(({starredAt}) => new Date(starredAt)))
pushed = edges.length