From 1bc8fee4947d65acd18113069b977cc91a9be4cc Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
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 62defee036..a3305b6cc7 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<T = unknown>(body: unknown): T[] | null {
diff --git a/lib/util/http/github.ts b/lib/util/http/github.ts
index 0d3a143d1c..45021b32d4 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<T = unknown> {
@@ -274,7 +270,7 @@ export class GithubHttp extends Http<GithubHttpOptions, GithubHttpOptions> {
 
   protected override async request<T>(
     url: string | URL,
-    options?: GithubInternalOptions & GithubHttpOptions,
+    options?: InternalHttpOptions & GithubHttpOptions,
     okToRetry = true
   ): Promise<HttpResponse<T>> {
     const opts = {
diff --git a/lib/util/http/gitlab.ts b/lib/util/http/gitlab.ts
index b1487476c1..cd43052b37 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<GitlabHttpOptions, GitlabHttpOptions> {
@@ -27,7 +22,7 @@ export class GitlabHttp extends Http<GitlabHttpOptions, GitlabHttpOptions> {
 
   protected override async request<T>(
     url: string | URL,
-    options?: GitlabInternalOptions & GitlabHttpOptions
+    options?: InternalHttpOptions & GitlabHttpOptions
   ): Promise<HttpResponse<T>> {
     const opts = {
       baseUrl,
diff --git a/lib/util/http/types.ts b/lib/util/http/types.ts
index 7e9a4302ad..5fe79a1c2f 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;
 }
 
-- 
GitLab