From 7df784681db6dcff380ef2f9ba7335261294da39 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Thu, 18 May 2023 07:11:46 -0400 Subject: [PATCH] add max pages limit --- lib/util/http/bitbucket.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/util/http/bitbucket.ts b/lib/util/http/bitbucket.ts index f870621732db7a..0d4a51c28a9b50 100644 --- a/lib/util/http/bitbucket.ts +++ b/lib/util/http/bitbucket.ts @@ -5,6 +5,7 @@ import { parseUrl, resolveBaseUrl } from '../url'; import type { HttpOptions, HttpResponse } from './types'; import { Http } from '.'; +const MAX_PAGES = 100; const MAX_PAGELEN = 100; let baseUrl = 'https://api.bitbucket.org/'; @@ -46,10 +47,10 @@ export class BitbucketHttp extends Http { if (opts.paginate && isPagedResult(result.body)) { const resultBody = result.body as PagedResult; - + let page = 1; let nextURL = resultBody.next; - while (is.nonEmptyString(nextURL)) { + while (is.nonEmptyString(nextURL) && page <= MAX_PAGES) { const nextResult = await super.request>( nextURL, options @@ -58,12 +59,13 @@ export class BitbucketHttp extends Http { resultBody.values.push(...nextResult.body.values); nextURL = nextResult.body?.next; + page += 1; } // Override other page-related attributes resultBody.pagelen = resultBody.values.length; - resultBody.size = resultBody.values.length; - resultBody.next = undefined; + resultBody.size = page > MAX_PAGES ? undefined : resultBody.values.length; + resultBody.next = page > MAX_PAGES ? undefined : nextURL; } return result;