Skip to content

Commit

Permalink
Correct pagination logic when rate limiting data is present in response
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Nov 3, 2023
1 parent 82e4c46 commit 4e3470d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plugins/github-enricher/github-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,27 @@ function findPaginatedElements(data, name, inPath) {
let currentPath = inPath || []
let contents

let answer

for (let key in data) {
if (key === name) {
contents = data[key]
break
} else if (typeof data[key] == "object") {
currentPath.push(key)
return findPaginatedElements(data[key], name, currentPath)
answer = findPaginatedElements(data[key], name, currentPath)
if (answer) {
contents = answer.contents
break
} else {
currentPath.pop(key)
}
}
}

return { keys: currentPath, contents }
if (contents) {
return { keys: currentPath, contents }
}
}

/*
Expand All @@ -106,7 +116,6 @@ const queryGraphQl = async (query) => {

const amendedQuery = query.replace(/edges\s*{/, PAGE_INFO_SUBQUERY).replace("query {", "query {" + RATE_LIMIT_PREQUERY)


const answer = await tolerantFetch("https://api.github.com/graphql", {
method: "POST",
body: JSON.stringify({ query: amendedQuery })
Expand Down
7 changes: 7 additions & 0 deletions plugins/github-enricher/github-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ describe("the github helper", () => {

const response1 = {
data: {
rateLimit: {
limit: 5000,
cost: 1,
remaining: 727,
resetAt: "2023-11-02T21:53:43Z"
},

holder: {
information: {
pageInfo: {
Expand Down

0 comments on commit 4e3470d

Please sign in to comment.