From 1013302e0f5bc4b51d346d52421c1c12cbc152dd Mon Sep 17 00:00:00 2001 From: RahulGautamSingh <rahultesnik@gmail.com> Date: Sun, 19 Mar 2023 21:39:46 +0530 Subject: [PATCH] refactor: exactOptionalPropertyTypes (#20761) Co-authored-by: Michael Kriese <michael.kriese@visualon.de> --- lib/config/migrate-validate.spec.ts | 2 +- lib/config/presets/gitea/index.ts | 2 +- lib/config/presets/github/index.ts | 6 +++--- lib/config/presets/gitlab/index.ts | 4 ++-- lib/config/presets/local/common.ts | 4 ++-- lib/config/presets/types.ts | 16 ++++++++-------- lib/config/presets/util.ts | 2 +- lib/instrumentation/decorator.ts | 3 ++- lib/instrumentation/types.ts | 2 +- lib/modules/datasource/datasource.ts | 2 +- lib/modules/datasource/docker/index.ts | 2 +- .../datasource/galaxy-collection/index.ts | 4 ++-- .../__snapshots__/releases-direct.spec.ts.snap | 2 +- lib/modules/datasource/go/releases-direct.ts | 2 +- lib/modules/datasource/go/releases-goproxy.ts | 2 +- lib/modules/datasource/golang-version/index.ts | 2 +- lib/modules/datasource/types.ts | 16 ++++++++-------- lib/modules/platform/types.ts | 1 + lib/util/github/graphql/types.ts | 2 +- lib/workers/repository/onboarding/pr/index.ts | 5 ++++- lib/workers/repository/update/pr/index.ts | 12 ++++++------ 21 files changed, 49 insertions(+), 44 deletions(-) diff --git a/lib/config/migrate-validate.spec.ts b/lib/config/migrate-validate.spec.ts index ff6744efd6..e64b707b59 100644 --- a/lib/config/migrate-validate.spec.ts +++ b/lib/config/migrate-validate.spec.ts @@ -37,7 +37,7 @@ describe('config/migrate-validate', () => { it('isOnboarded', async () => { const input: RenovateConfig = {}; const res = await migrateAndValidate( - { ...config, repoIsOnboarded: true, warnings: undefined }, + { ...config, repoIsOnboarded: true }, input ); expect(res.warnings).toBeUndefined(); diff --git a/lib/config/presets/gitea/index.ts b/lib/config/presets/gitea/index.ts index dfc8884396..8728cf2027 100644 --- a/lib/config/presets/gitea/index.ts +++ b/lib/config/presets/gitea/index.ts @@ -37,7 +37,7 @@ export function getPresetFromEndpoint( filePreset: string, presetPath?: string, endpoint = Endpoint, - tag?: string + tag?: string | undefined ): Promise<Preset | undefined> { return fetchPreset({ repo, diff --git a/lib/config/presets/github/index.ts b/lib/config/presets/github/index.ts index 315c512594..da087ae1c4 100644 --- a/lib/config/presets/github/index.ts +++ b/lib/config/presets/github/index.ts @@ -14,7 +14,7 @@ export async function fetchJSONFile( repo: string, fileName: string, endpoint: string, - tag?: string | null + tag?: string | undefined ): Promise<Preset> { let ref = ''; if (is.nonEmptyString(tag)) { @@ -42,7 +42,7 @@ export function getPresetFromEndpoint( filePreset: string, presetPath?: string, endpoint = Endpoint, - tag?: string + tag?: string | undefined ): Promise<Preset | undefined> { return fetchPreset({ repo, @@ -58,7 +58,7 @@ export function getPreset({ repo, presetName = 'default', presetPath, - tag = undefined, + tag, }: PresetConfig): Promise<Preset | undefined> { return getPresetFromEndpoint(repo, presetName, presetPath, Endpoint, tag); } diff --git a/lib/config/presets/gitlab/index.ts b/lib/config/presets/gitlab/index.ts index 5c2902fc02..b1f4071ccd 100644 --- a/lib/config/presets/gitlab/index.ts +++ b/lib/config/presets/gitlab/index.ts @@ -24,7 +24,7 @@ export async function fetchJSONFile( repo: string, fileName: string, endpoint: string, - tag?: string | null + tag?: string | undefined ): Promise<Preset> { let url = endpoint; let ref = ''; @@ -60,7 +60,7 @@ export function getPresetFromEndpoint( presetName: string, presetPath?: string, endpoint = Endpoint, - tag?: string | null + tag?: string | undefined ): Promise<Preset | undefined> { return fetchPreset({ repo, diff --git a/lib/config/presets/local/common.ts b/lib/config/presets/local/common.ts index 144eada8fa..c22e6f86f3 100644 --- a/lib/config/presets/local/common.ts +++ b/lib/config/presets/local/common.ts @@ -8,7 +8,7 @@ export async function fetchJSONFile( repo: string, fileName: string, _endpoint?: string, - tag?: string | null + tag?: string | undefined ): Promise<Preset> { let raw: string | null; try { @@ -35,7 +35,7 @@ export function getPresetFromEndpoint( filePreset: string, presetPath: string | undefined, endpoint: string, - tag?: string | null + tag?: string | undefined ): Promise<Preset | undefined> { return fetchPreset({ repo, diff --git a/lib/config/presets/types.ts b/lib/config/presets/types.ts index cc31c2e27a..943739dafa 100644 --- a/lib/config/presets/types.ts +++ b/lib/config/presets/types.ts @@ -5,9 +5,9 @@ export type Preset = RenovateConfig & Record<string, unknown>; export type PresetConfig = { repo: string; - presetPath?: string; + presetPath?: string | undefined; presetName?: string; - tag?: string; + tag?: string | undefined; }; export interface PresetApi { @@ -19,24 +19,24 @@ export interface PresetApi { export interface ParsedPreset { presetSource: string; repo: string; - presetPath?: string; + presetPath?: string | undefined; presetName: string; - tag?: string; - params?: string[]; + tag?: string | undefined; + params?: string[] | undefined; } export type PresetFetcher = ( repo: string, fileName: string, endpoint: string, - tag?: string | null + tag?: string | undefined ) => Promise<Preset | null | undefined>; export type FetchPresetConfig = { repo: string; filePreset: string; - presetPath?: string; + presetPath?: string | undefined; endpoint: string; - tag?: string | null; + tag?: string | undefined; fetch: PresetFetcher; }; diff --git a/lib/config/presets/util.ts b/lib/config/presets/util.ts index 270da8757e..8d8382e3d5 100644 --- a/lib/config/presets/util.ts +++ b/lib/config/presets/util.ts @@ -17,7 +17,7 @@ export async function fetchPreset({ filePreset, presetPath, endpoint: _endpoint, - tag = null, + tag, fetch, }: FetchPresetConfig): Promise<Preset | undefined> { // TODO: fix me, can be undefiend #7154 diff --git a/lib/instrumentation/decorator.ts b/lib/instrumentation/decorator.ts index 39f1d365a8..30f8ce6de1 100644 --- a/lib/instrumentation/decorator.ts +++ b/lib/instrumentation/decorator.ts @@ -1,3 +1,4 @@ +import { SpanKind } from '@opentelemetry/api'; import { Decorator, decorate } from '../util/decorator'; import type { SpanParameters } from './types'; import { instrument as instrumentFunc } from '.'; @@ -9,7 +10,7 @@ export function instrument<T>({ name, attributes, ignoreParentSpan, - kind, + kind = SpanKind.INTERNAL, }: SpanParameters): Decorator<T> { return decorate(async ({ callback }) => { return await instrumentFunc(name, callback, { diff --git a/lib/instrumentation/types.ts b/lib/instrumentation/types.ts index 8b312d03d7..a753ecb56d 100644 --- a/lib/instrumentation/types.ts +++ b/lib/instrumentation/types.ts @@ -12,7 +12,7 @@ export interface SpanParameters { /** * Attributes which should be added to the span */ - attributes?: Attributes; + attributes?: Attributes | undefined; /** * Should this span be added to the root span or to the current active span diff --git a/lib/modules/datasource/datasource.ts b/lib/modules/datasource/datasource.ts index a8cb0b3ebc..95d6abf947 100644 --- a/lib/modules/datasource/datasource.ts +++ b/lib/modules/datasource/datasource.ts @@ -22,7 +22,7 @@ export abstract class Datasource implements DatasourceApi { defaultRegistryUrls?: string[] | (() => string[]); - defaultVersioning: string | undefined; + defaultVersioning?: string | undefined; registryStrategy: RegistryStrategy | undefined = 'first'; diff --git a/lib/modules/datasource/docker/index.ts b/lib/modules/datasource/docker/index.ts index c2192fec8d..43e66d2321 100644 --- a/lib/modules/datasource/docker/index.ts +++ b/lib/modules/datasource/docker/index.ts @@ -234,7 +234,7 @@ export async function getAuthHeaders( } async function getECRAuthToken( - region: string | undefined, + region: string, opts: HostRule ): Promise<string | null> { const config: ECRClientConfig = { region }; diff --git a/lib/modules/datasource/galaxy-collection/index.ts b/lib/modules/datasource/galaxy-collection/index.ts index 701536848b..2e71f35433 100644 --- a/lib/modules/datasource/galaxy-collection/index.ts +++ b/lib/modules/datasource/galaxy-collection/index.ts @@ -93,7 +93,7 @@ export class GalaxyCollectionDatasource extends Datasource { try { const release: Release = { version: basicRelease.version, - isDeprecated: basicRelease.isDeprecated, + isDeprecated: !!basicRelease.isDeprecated, downloadUrl: versionDetails.download_url, newDigest: versionDetails.artifact.sha256, dependencies: versionDetails.metadata.dependencies, @@ -118,7 +118,7 @@ export class GalaxyCollectionDatasource extends Datasource { // extract base information which are only provided on the release from the newest release const result: ReleaseResult = { releases: filteredReleases, - sourceUrl: newestVersionDetails?.metadata.repository, + sourceUrl: newestVersionDetails?.metadata.repository ?? null, homepage: newestVersionDetails?.metadata.homepage, tags: newestVersionDetails?.metadata.tags, }; diff --git a/lib/modules/datasource/go/__snapshots__/releases-direct.spec.ts.snap b/lib/modules/datasource/go/__snapshots__/releases-direct.spec.ts.snap index 40b52a688f..4e65ba2770 100644 --- a/lib/modules/datasource/go/__snapshots__/releases-direct.spec.ts.snap +++ b/lib/modules/datasource/go/__snapshots__/releases-direct.spec.ts.snap @@ -31,7 +31,7 @@ exports[`modules/datasource/go/releases-direct getReleases support git 1`] = ` "version": "v2.0.0", }, ], - "sourceUrl": undefined, + "sourceUrl": null, } `; diff --git a/lib/modules/datasource/go/releases-direct.ts b/lib/modules/datasource/go/releases-direct.ts index b9fb0b6130..13950d682f 100644 --- a/lib/modules/datasource/go/releases-direct.ts +++ b/lib/modules/datasource/go/releases-direct.ts @@ -85,7 +85,7 @@ export class GoDirectDatasource extends Datasource { return null; } - const sourceUrl = getSourceUrl(source); + const sourceUrl = getSourceUrl(source) ?? null; /** * github.com/org/mod/submodule should be tagged as submodule/va.b.c diff --git a/lib/modules/datasource/go/releases-goproxy.ts b/lib/modules/datasource/go/releases-goproxy.ts index a541c06c28..7d00bfaa18 100644 --- a/lib/modules/datasource/go/releases-goproxy.ts +++ b/lib/modules/datasource/go/releases-goproxy.ts @@ -92,7 +92,7 @@ export class GoProxyDatasource extends Datasource { const datasource = await BaseGoDatasource.getDatasource( packageName ); - const sourceUrl = getSourceUrl(datasource); + const sourceUrl = getSourceUrl(datasource) ?? null; result = { releases, sourceUrl }; } catch (err) { logger.trace({ err }, `Can't get datasource for ${packageName}`); diff --git a/lib/modules/datasource/golang-version/index.ts b/lib/modules/datasource/golang-version/index.ts index d0cd118bbb..33a9959da8 100644 --- a/lib/modules/datasource/golang-version/index.ts +++ b/lib/modules/datasource/golang-version/index.ts @@ -67,7 +67,7 @@ export class GolangVersionDatasource extends Datasource { lines.splice(0, startOfReleases + 1); // Parse the release list - let release: Omit<Release, 'version'> & { version?: string } = { + let release: Omit<Release, 'version'> & { version?: string | undefined } = { version: undefined, }; let skipFutureRelease = false; diff --git a/lib/modules/datasource/types.ts b/lib/modules/datasource/types.ts index a112d5fd5e..095d9f2ef1 100644 --- a/lib/modules/datasource/types.ts +++ b/lib/modules/datasource/types.ts @@ -48,12 +48,12 @@ export interface Release { isStable?: boolean; releaseTimestamp?: any; version: string; - newDigest?: string; + newDigest?: string | undefined; constraints?: Record<string, string[]>; dependencies?: Record<string, string>; devDependencies?: Record<string, string>; registryUrl?: string; - sourceUrl?: string; + sourceUrl?: string | undefined; sourceDirectory?: string; } @@ -61,11 +61,11 @@ export interface ReleaseResult { deprecationMessage?: string; isPrivate?: boolean; releases: Release[]; - tags?: Record<string, string>; + tags?: Record<string, string> | undefined; // URL metadata changelogUrl?: string; dependencyUrl?: string; - homepage?: string; + homepage?: string | undefined; gitRef?: string; sourceUrl?: string | null; sourceDirectory?: string; @@ -81,8 +81,8 @@ export interface DatasourceApi extends ModuleApi { getDigest?(config: DigestConfig, newValue?: string): Promise<string | null>; getReleases(config: GetReleasesConfig): Promise<ReleaseResult | null>; defaultRegistryUrls?: string[] | (() => string[]); - defaultVersioning?: string; - defaultConfig?: Record<string, unknown>; + defaultVersioning?: string | undefined; + defaultConfig?: Record<string, unknown> | undefined; /** * Strategy to use when multiple registryUrls are available to the datasource. @@ -90,7 +90,7 @@ export interface DatasourceApi extends ModuleApi { * hunt: registryUrls will be tried in order until one returns a result * merge: all registryUrls will be tried and the results merged if more than one returns a result */ - registryStrategy?: RegistryStrategy; + registryStrategy?: RegistryStrategy | undefined; /** * Whether custom registryUrls are allowed. @@ -102,7 +102,7 @@ export interface DatasourceApi extends ModuleApi { * true: datasoure index wrapper should cache all results (based on registryUrl/packageName) * false: caching is not performed, or performed within the datasource implementation */ - caching?: boolean; + caching?: boolean | undefined; /** optional URLs to add to docs as references */ urls?: string[]; diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index eeafd70cd2..06b9fc1896 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -95,6 +95,7 @@ export type PlatformPrOptions = { usePlatformAutomerge?: boolean; forkModeDisallowMaintainerEdits?: boolean; }; + export interface CreatePRConfig { sourceBranch: string; targetBranch: string; diff --git a/lib/util/github/graphql/types.ts b/lib/util/github/graphql/types.ts index 1fbbca8bd8..41344df196 100644 --- a/lib/util/github/graphql/types.ts +++ b/lib/util/github/graphql/types.ts @@ -55,7 +55,7 @@ export interface GithubPackageConfig { /** * Default: https://api.github.com */ - registryUrl?: string; + registryUrl?: string | undefined; } /** diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index d1d7ce2b71..923dec654e 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -171,7 +171,10 @@ If you need any further assistance then you can also [request help here](${ prTitle: config.onboardingPrTitle!, prBody, labels, - platformOptions: getPlatformPrOptions({ ...config, automerge: false }), + platformOptions: getPlatformPrOptions({ + ...config, + automerge: false, + }), }); logger.info( { pr: `Pull Request #${pr!.number}` }, diff --git a/lib/workers/repository/update/pr/index.ts b/lib/workers/repository/update/pr/index.ts index f333e266fc..cc308d54ab 100644 --- a/lib/workers/repository/update/pr/index.ts +++ b/lib/workers/repository/update/pr/index.ts @@ -47,11 +47,11 @@ export function getPlatformPrOptions( ); return { - azureAutoApprove: config.azureAutoApprove, - azureWorkItemId: config.azureWorkItemId, - bbUseDefaultReviewers: config.bbUseDefaultReviewers, - gitLabIgnoreApprovals: config.gitLabIgnoreApprovals, - forkModeDisallowMaintainerEdits: config.forkModeDisallowMaintainerEdits, + azureAutoApprove: !!config.azureAutoApprove, + azureWorkItemId: config.azureWorkItemId ?? 0, + bbUseDefaultReviewers: !!config.bbUseDefaultReviewers, + gitLabIgnoreApprovals: !!config.gitLabIgnoreApprovals, + forkModeDisallowMaintainerEdits: !!config.forkModeDisallowMaintainerEdits, usePlatformAutomerge, }; } @@ -391,7 +391,7 @@ export async function ensurePr( prBody, labels: prepareLabels(config), platformOptions: getPlatformPrOptions(config), - draftPR: config.draftPR, + draftPR: !!config.draftPR, }); incLimitedValue('PullRequests'); -- GitLab