From 1bc8fee4947d65acd18113069b977cc91a9be4cc Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Thu, 4 Aug 2022 12:54:52 +0200 Subject: [PATCH] refactor: cleanup http option interface (#16967) --- lib/util/http/gitea.ts | 3 +-- lib/util/http/github.ts | 10 +++------- lib/util/http/gitlab.ts | 11 +++-------- lib/util/http/types.ts | 2 ++ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/util/http/gitea.ts b/lib/util/http/gitea.ts index 62defee036adf0..a3305b6cc77b2d 100644 --- a/lib/util/http/gitea.ts +++ b/lib/util/http/gitea.ts @@ -9,9 +9,8 @@ export const setBaseUrl = (newBaseUrl: string): void => { baseUrl = newBaseUrl.replace(/\/*$/, '/'); // TODO #12875 }; -export interface GiteaHttpOptions extends InternalHttpOptions { +export interface GiteaHttpOptions extends HttpOptions { paginate?: boolean; - token?: string; } function getPaginationContainer(body: unknown): T[] | null { diff --git a/lib/util/http/github.ts b/lib/util/http/github.ts index 0d3a143d1cee67..45021b32d48aa7 100644 --- a/lib/util/http/github.ts +++ b/lib/util/http/github.ts @@ -18,6 +18,7 @@ import { parseLinkHeader } from '../url'; import type { GotLegacyError } from './legacy'; import type { GraphqlOptions, + HttpOptions, HttpPostOptions, HttpResponse, InternalHttpOptions, @@ -30,15 +31,10 @@ export const setBaseUrl = (url: string): void => { baseUrl = url; }; -interface GithubInternalOptions extends InternalHttpOptions { - body?: string; -} - -export interface GithubHttpOptions extends InternalHttpOptions { +export interface GithubHttpOptions extends HttpOptions { paginate?: boolean | string; paginationField?: string; pageLimit?: number; - token?: string; } interface GithubGraphqlRepoData { @@ -274,7 +270,7 @@ export class GithubHttp extends Http { protected override async request( url: string | URL, - options?: GithubInternalOptions & GithubHttpOptions, + options?: InternalHttpOptions & GithubHttpOptions, okToRetry = true ): Promise> { const opts = { diff --git a/lib/util/http/gitlab.ts b/lib/util/http/gitlab.ts index b1487476c1cd3c..cd43052b378138 100644 --- a/lib/util/http/gitlab.ts +++ b/lib/util/http/gitlab.ts @@ -3,7 +3,7 @@ import { PlatformId } from '../../constants'; import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import { parseLinkHeader, parseUrl } from '../url'; -import type { HttpResponse, InternalHttpOptions } from './types'; +import type { HttpOptions, HttpResponse, InternalHttpOptions } from './types'; import { Http } from '.'; let baseUrl = 'https://gitlab.com/api/v4/'; @@ -11,13 +11,8 @@ export const setBaseUrl = (url: string): void => { baseUrl = url; }; -interface GitlabInternalOptions extends InternalHttpOptions { - body?: string; -} - -export interface GitlabHttpOptions extends InternalHttpOptions { +export interface GitlabHttpOptions extends HttpOptions { paginate?: boolean; - token?: string; } export class GitlabHttp extends Http { @@ -27,7 +22,7 @@ export class GitlabHttp extends Http { protected override async request( url: string | URL, - options?: GitlabInternalOptions & GitlabHttpOptions + options?: InternalHttpOptions & GitlabHttpOptions ): Promise> { const opts = { baseUrl, diff --git a/lib/util/http/types.ts b/lib/util/http/types.ts index 7e9a4302ad74dd..5fe79a1c2fe854 100644 --- a/lib/util/http/types.ts +++ b/lib/util/http/types.ts @@ -60,6 +60,8 @@ export interface HttpOptions { noAuth?: boolean; throwHttpErrors?: boolean; + + token?: string; useCache?: boolean; }