Add support for users with more than 100 gists (#74)
This commit is contained in:
@@ -211,9 +211,21 @@
|
|||||||
//Gists query
|
//Gists query
|
||||||
if (/^query Gists /.test(query)) {
|
if (/^query Gists /.test(query)) {
|
||||||
console.debug(`metrics/compute/mocks > mocking graphql api result > Projects`)
|
console.debug(`metrics/compute/mocks > mocking graphql api result > Projects`)
|
||||||
return ({
|
return /after: "MOCKED_CURSOR"/m.test(query) ? ({
|
||||||
user:{
|
user:{
|
||||||
gists:{
|
gists:{
|
||||||
|
edges:[],
|
||||||
|
nodes:[],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}) : ({
|
||||||
|
user:{
|
||||||
|
gists:{
|
||||||
|
edges:[
|
||||||
|
{
|
||||||
|
cursor:"MOCKED_CURSOR"
|
||||||
|
},
|
||||||
|
],
|
||||||
totalCount:faker.random.number(100),
|
totalCount:faker.random.number(100),
|
||||||
nodes:[
|
nodes:[
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,13 +5,26 @@
|
|||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
if ((!enabled)||(!q.gists))
|
if ((!enabled)||(!q.gists))
|
||||||
return null
|
return null
|
||||||
//Retrieve gists from graphql api
|
//Query gists from GitHub API
|
||||||
console.debug(`metrics/compute/${login}/plugins > gists > querying api`)
|
const gists = []
|
||||||
const {user:{gists}} = await graphql(queries.gists({login}))
|
{
|
||||||
//Iterate through gists
|
//Iterate through gists
|
||||||
console.debug(`metrics/compute/${login}/plugins > gists > processing ${gists.nodes.length} gists`)
|
let cursor = null
|
||||||
|
let pushed = 0
|
||||||
|
do {
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > gists > retrieving gists after ${cursor}`)
|
||||||
|
const {user:{gists:{edges, nodes, totalCount}}} = await graphql(queries.gists({login, after:cursor ? `after: "${cursor}"` : ""}))
|
||||||
|
cursor = edges?.[edges?.length-1]?.cursor
|
||||||
|
gists.push(...nodes)
|
||||||
|
gists.totalCount = totalCount
|
||||||
|
pushed = nodes.length
|
||||||
|
} 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
|
let stargazers = 0, forks = 0, comments = 0, files = 0
|
||||||
for (const gist of gists.nodes) {
|
for (const gist of gists) {
|
||||||
//Skip forks
|
//Skip forks
|
||||||
if (gist.isFork)
|
if (gist.isFork)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
query Gists {
|
query Gists {
|
||||||
user(login: "$login") {
|
user(login: "$login") {
|
||||||
gists(last: 100) {
|
gists($after first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||||
|
edges {
|
||||||
|
cursor
|
||||||
|
}
|
||||||
totalCount
|
totalCount
|
||||||
nodes {
|
nodes {
|
||||||
stargazerCount
|
stargazerCount
|
||||||
|
|||||||
Reference in New Issue
Block a user