diff --git a/.changeset/olive-turkeys-switch.md b/.changeset/olive-turkeys-switch.md new file mode 100644 index 0000000000..d208f3b197 --- /dev/null +++ b/.changeset/olive-turkeys-switch.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Fixed bug in queryWithPaging that caused secondary rate limit errors in GitHub with organizations having more than 1000 repositories. This change makes one request per second to avoid concurrency issues. diff --git a/plugins/catalog-backend-module-github/src/lib/github.ts b/plugins/catalog-backend-module-github/src/lib/github.ts index 39501e89bc..d0b629092a 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.ts @@ -545,6 +545,7 @@ export async function queryWithPaging< variables: Variables, ): Promise { const result: OutputType[] = []; + const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); let cursor: string | undefined = undefined; for (let j = 0; j < 1000 /* just for sanity */; ++j) { @@ -573,6 +574,7 @@ export async function queryWithPaging< if (!conn.pageInfo.hasNextPage) { break; } else { + await sleep(1000); cursor = conn.pageInfo.endCursor; } }