Skip to content

Commit

Permalink
refactor: cleanup http option interface (#16967)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Aug 4, 2022
1 parent 8c8dceb commit 1bc8fee
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
3 changes: 1 addition & 2 deletions lib/util/http/gitea.ts
Expand Up @@ -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 {
Expand Down
10 changes: 3 additions & 7 deletions lib/util/http/github.ts
Expand Up @@ -18,6 +18,7 @@ import { parseLinkHeader } from '../url';
import type { GotLegacyError } from './legacy';
import type {
GraphqlOptions,
HttpOptions,
HttpPostOptions,
HttpResponse,
InternalHttpOptions,
Expand All @@ -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> {
Expand Down Expand Up @@ -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 = {
Expand Down
11 changes: 3 additions & 8 deletions lib/util/http/gitlab.ts
Expand Up @@ -3,21 +3,16 @@ 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/';
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> {
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/util/http/types.ts
Expand Up @@ -60,6 +60,8 @@ export interface HttpOptions {
noAuth?: boolean;

throwHttpErrors?: boolean;

token?: string;
useCache?: boolean;
}

Expand Down

0 comments on commit 1bc8fee

Please sign in to comment.