From a4bdc8b066f6df8a3df7f0b023fb4e26548b44bc Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Thu, 26 Sep 2024 01:56:14 -0300 Subject: [PATCH] refactor: Restrict `postprocessRelease` method types (#31626) --- lib/modules/datasource/datasource.ts | 11 +++++++++++ lib/modules/datasource/postprocess-release.spec.ts | 8 ++++---- lib/modules/datasource/postprocess-release.ts | 6 +++++- lib/modules/datasource/types.ts | 2 +- .../repository/process/lookup/filter-checks.spec.ts | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/modules/datasource/datasource.ts b/lib/modules/datasource/datasource.ts index fce5596441..0e6c8c2c12 100644 --- a/lib/modules/datasource/datasource.ts +++ b/lib/modules/datasource/datasource.ts @@ -4,7 +4,10 @@ import type { DatasourceApi, DigestConfig, GetReleasesConfig, + PostprocessReleaseConfig, + PostprocessReleaseResult, RegistryStrategy, + Release, ReleaseResult, SourceUrlSupport, } from './types'; @@ -61,4 +64,12 @@ export abstract class Datasource implements DatasourceApi { throw err; } + + // istanbul ignore next: no-op implementation, never called + postprocessRelease( + _config: PostprocessReleaseConfig, + release: Release, + ): Promise<PostprocessReleaseResult> { + return Promise.resolve(release); + } } diff --git a/lib/modules/datasource/postprocess-release.spec.ts b/lib/modules/datasource/postprocess-release.spec.ts index 2f3c014ade..3ec6de9abd 100644 --- a/lib/modules/datasource/postprocess-release.spec.ts +++ b/lib/modules/datasource/postprocess-release.spec.ts @@ -59,7 +59,7 @@ describe('modules/datasource/postprocess-release', () => { it('returns original release for datasource with missing `packageName` field', async () => { class SomeDatasource extends DummyDatasource { - postprocessRelease( + override postprocessRelease( _config: PostprocessReleaseConfig, release: Release, ): Promise<PostprocessReleaseResult> { @@ -82,7 +82,7 @@ describe('modules/datasource/postprocess-release', () => { const releaseOrig: Release = { version: '1.2.3' }; class SomeDatasource extends DummyDatasource { - postprocessRelease( + override postprocessRelease( _config: PostprocessReleaseConfig, release: Release, ): Promise<PostprocessReleaseResult> { @@ -107,7 +107,7 @@ describe('modules/datasource/postprocess-release', () => { const releaseOrig: Release = { version: '1.2.3' }; class SomeDatasource extends DummyDatasource { - postprocessRelease( + override postprocessRelease( _config: PostprocessReleaseConfig, _release: Release, ): Promise<PostprocessReleaseResult> { @@ -128,7 +128,7 @@ describe('modules/datasource/postprocess-release', () => { const releaseOrig: Release = { version: '1.2.3' }; class SomeDatasource extends DummyDatasource { - postprocessRelease( + override postprocessRelease( _config: PostprocessReleaseConfig, _release: Release, ): Promise<PostprocessReleaseResult> { diff --git a/lib/modules/datasource/postprocess-release.ts b/lib/modules/datasource/postprocess-release.ts index fe203752c1..ef4a34131f 100644 --- a/lib/modules/datasource/postprocess-release.ts +++ b/lib/modules/datasource/postprocess-release.ts @@ -4,6 +4,7 @@ import type { UpdateResult, } from '../../workers/repository/process/lookup/types'; import { getDatasourceFor } from './common'; +import { Datasource } from './datasource'; import type { Release } from './types'; type Config = Partial<LookupUpdateConfig & UpdateResult>; @@ -23,7 +24,10 @@ export async function postprocessRelease( return release; } - if (!ds.postprocessRelease) { + if ( + ds.constructor.prototype.postprocessRelease === + Datasource.prototype.postprocessRelease + ) { return release; } diff --git a/lib/modules/datasource/types.ts b/lib/modules/datasource/types.ts index 60b9832585..d4e8ed0b32 100644 --- a/lib/modules/datasource/types.ts +++ b/lib/modules/datasource/types.ts @@ -160,7 +160,7 @@ export interface DatasourceApi extends ModuleApi { * * In other cases, the original `Release` parameter should be returned. */ - postprocessRelease?( + postprocessRelease( config: PostprocessReleaseConfig, release: Release, ): Promise<PostprocessReleaseResult>; diff --git a/lib/workers/repository/process/lookup/filter-checks.spec.ts b/lib/workers/repository/process/lookup/filter-checks.spec.ts index fcdef36cb7..aa1f3d63fe 100644 --- a/lib/workers/repository/process/lookup/filter-checks.spec.ts +++ b/lib/workers/repository/process/lookup/filter-checks.spec.ts @@ -91,7 +91,7 @@ describe('workers/repository/process/lookup/filter-checks', () => { config.internalChecksFilter = 'strict'; class SomeDatasource extends DummyDatasource { - postprocessRelease( + override postprocessRelease( _: PostprocessReleaseConfig, release: Release, ): Promise<PostprocessReleaseResult> { -- GitLab