Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(bitbucket): remove unused accumulate value utility #22359

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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