From cbbb95828f1dcd61caee75a7727eab84fc0532ac Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 22 May 2023 14:25:53 -0400 Subject: [PATCH] refactor(bitbucket): remove unused accumulate value utility (#22359) --- lib/modules/platform/bitbucket/utils.spec.ts | 35 ----------- lib/modules/platform/bitbucket/utils.ts | 61 -------------------- 2 files changed, 96 deletions(-) delete mode 100644 lib/modules/platform/bitbucket/utils.spec.ts diff --git a/lib/modules/platform/bitbucket/utils.spec.ts b/lib/modules/platform/bitbucket/utils.spec.ts deleted file mode 100644 index 9506ef1503b0ef..00000000000000 --- a/lib/modules/platform/bitbucket/utils.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import * as httpMock from '../../../../test/http-mock'; -import { setBaseUrl } from '../../../util/http/bitbucket'; -import * as utils from './utils'; - -const range = (count: number) => [...Array(count).keys()]; - -const baseUrl = 'https://api.bitbucket.org'; - -describe('modules/platform/bitbucket/utils', () => { - beforeEach(() => { - setBaseUrl(baseUrl); - }); - - it('paginates', async () => { - httpMock - .scope(baseUrl) - .get('/some-url?pagelen=10') - .reply(200, { - values: range(10), - next: 'https://api.bitbucket.org/2.0/repositories/?pagelen=10&after=9&role=contributor', - }) - .get('/2.0/repositories/?pagelen=10&after=9&role=contributor') - .reply(200, { - values: range(10), - next: 'https://api.bitbucket.org/2.0/repositories/?pagelen=10&after=19&role=contributor', - }) - .get('/2.0/repositories/?pagelen=10&after=19&role=contributor') - .reply(200, { - values: range(5), - }); - - const res = await utils.accumulateValues('some-url', 'get', undefined, 10); - expect(res).toHaveLength(25); - }); -}); diff --git a/lib/modules/platform/bitbucket/utils.ts b/lib/modules/platform/bitbucket/utils.ts index 5466351d437db5..a5665bd2f7a9cb 100644 --- a/lib/modules/platform/bitbucket/utils.ts +++ b/lib/modules/platform/bitbucket/utils.ts @@ -1,8 +1,5 @@ -import URL from 'node:url'; import type { MergeStrategy } from '../../../config/types'; import type { BranchStatus } from '../../../types'; -import { BitbucketHttp } from '../../../util/http/bitbucket'; -import type { HttpOptions, HttpResponse } from '../../../util/http/types'; import { getPrBodyStruct } from '../pr-body'; import type { Pr } from '../types'; import type { @@ -14,8 +11,6 @@ import type { RepoInfoBody, } from './types'; -const bitbucketHttp = new BitbucketHttp(); - export function repoInfoTransformer(repoInfoBody: RepoInfoBody): RepoInfo { return { isFork: !!repoInfoBody.parent, @@ -63,62 +58,6 @@ export const buildStates: Record = { yellow: 'INPROGRESS', }; -const addMaxLength = (inputUrl: string, pagelen = 100): string => { - const { search, ...parsedUrl } = URL.parse(inputUrl, true); - const maxedUrl = URL.format({ - ...parsedUrl, - query: { ...parsedUrl.query, pagelen }, - }); - return maxedUrl; -}; - -function callApi( - apiUrl: string, - method: string, - options?: HttpOptions -): Promise> { - /* istanbul ignore next */ - switch (method.toLowerCase()) { - case 'post': - return bitbucketHttp.postJson(apiUrl, options); - case 'put': - return bitbucketHttp.putJson(apiUrl, options); - case 'patch': - return bitbucketHttp.patchJson(apiUrl, options); - case 'head': - return bitbucketHttp.headJson(apiUrl, options) as Promise< - HttpResponse - >; - case 'delete': - return bitbucketHttp.deleteJson(apiUrl, options); - case 'get': - default: - return bitbucketHttp.getJson(apiUrl, options); - } -} - -export async function accumulateValues( - reqUrl: string, - method = 'get', - options?: HttpOptions, - pagelen?: number -): Promise { - let accumulator: T[] = []; - let nextUrl = addMaxLength(reqUrl, pagelen); - - while (typeof nextUrl !== 'undefined') { - const { body } = await callApi<{ values: T[]; next: string }>( - nextUrl, - method, - options - ); - accumulator = [...accumulator, ...body.values]; - nextUrl = body.next; - } - - return accumulator; -} - export function prInfo(pr: PrResponse): Pr { return { number: pr.id,