Skip to content

Commit

Permalink
refactor(bitbucket): remove unused accumulate value utility (#22359)
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed May 22, 2023
1 parent a219a6a commit cbbb958
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 96 deletions.
35 changes: 0 additions & 35 deletions lib/modules/platform/bitbucket/utils.spec.ts

This file was deleted.

61 changes: 0 additions & 61 deletions 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 {
Expand All @@ -14,8 +11,6 @@ import type {
RepoInfoBody,
} from './types';

const bitbucketHttp = new BitbucketHttp();

export function repoInfoTransformer(repoInfoBody: RepoInfoBody): RepoInfo {
return {
isFork: !!repoInfoBody.parent,
Expand Down Expand Up @@ -63,62 +58,6 @@ export const buildStates: Record<BranchStatus, BitbucketBranchState> = {
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<T>(
apiUrl: string,
method: string,
options?: HttpOptions
): Promise<HttpResponse<T>> {
/* istanbul ignore next */
switch (method.toLowerCase()) {
case 'post':
return bitbucketHttp.postJson<T>(apiUrl, options);
case 'put':
return bitbucketHttp.putJson<T>(apiUrl, options);
case 'patch':
return bitbucketHttp.patchJson<T>(apiUrl, options);
case 'head':
return bitbucketHttp.headJson(apiUrl, options) as Promise<
HttpResponse<T>
>;
case 'delete':
return bitbucketHttp.deleteJson<T>(apiUrl, options);
case 'get':
default:
return bitbucketHttp.getJson<T>(apiUrl, options);
}
}

export async function accumulateValues<T = any>(
reqUrl: string,
method = 'get',
options?: HttpOptions,
pagelen?: number
): Promise<T[]> {
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,
Expand Down

0 comments on commit cbbb958

Please sign in to comment.