From d011e848a451dfea02b7a9357296a8ee85bc134b Mon Sep 17 00:00:00 2001 From: RahulGautamSingh <rahultesnik@gmail.com> Date: Tue, 9 Aug 2022 10:56:35 +0530 Subject: [PATCH] refactor: merge extract config types (#16204) --- lib/modules/manager/helmv3/extract.spec.ts | 74 ++++++---------------- lib/modules/manager/regex/index.ts | 20 ++++-- lib/modules/manager/regex/strategies.ts | 10 +-- lib/modules/manager/regex/types.ts | 4 ++ lib/modules/manager/types.ts | 8 +-- lib/workers/types.ts | 5 +- 6 files changed, 45 insertions(+), 76 deletions(-) diff --git a/lib/modules/manager/helmv3/extract.spec.ts b/lib/modules/manager/helmv3/extract.spec.ts index cc9d2d2025..eb0d004177 100644 --- a/lib/modules/manager/helmv3/extract.spec.ts +++ b/lib/modules/manager/helmv3/extract.spec.ts @@ -1,8 +1,14 @@ -import { fs } from '../../../../test/util'; +import { fs, partial } from '../../../../test/util'; import { DockerDatasource } from '../../datasource/docker'; +import type { ExtractConfig } from '../types'; import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); +const config = partial<ExtractConfig>({ + registryAliases: { + stable: 'https://charts.helm.sh/stable', + }, +}); describe('modules/manager/helmv3/extract', () => { describe('extractPackageFile()', () => { @@ -29,11 +35,7 @@ describe('modules/manager/helmv3/extract', () => { version: 0.8.1 `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); expect(result?.deps.every((dep) => dep.skipReason)).toBe(true); @@ -57,11 +59,7 @@ describe('modules/manager/helmv3/extract', () => { condition: postgresql.enabled `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toMatchSnapshot({ deps: [ { depName: 'redis', currentValue: '0.9.0' }, @@ -90,11 +88,7 @@ describe('modules/manager/helmv3/extract', () => { condition: postgresql.enabled `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toMatchSnapshot({ deps: [ { @@ -145,11 +139,7 @@ describe('modules/manager/helmv3/extract', () => { [ `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toBeNull(); }); @@ -169,11 +159,7 @@ describe('modules/manager/helmv3/extract', () => { repository: file:///some/local/path/ `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toMatchSnapshot({ deps: [ { depName: 'redis' }, @@ -194,11 +180,7 @@ describe('modules/manager/helmv3/extract', () => { hello: world `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toBeNull(); }); @@ -214,11 +196,7 @@ describe('modules/manager/helmv3/extract', () => { dependencies: [] `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toBeNull(); }); @@ -234,22 +212,14 @@ describe('modules/manager/helmv3/extract', () => { [ `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toBeNull(); }); it('returns null if Chart.yaml is empty', async () => { const content = ''; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toBeNull(); }); @@ -262,11 +232,7 @@ describe('modules/manager/helmv3/extract', () => { version: 0.1.0 `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toBeNull(); }); @@ -283,11 +249,7 @@ describe('modules/manager/helmv3/extract', () => { alias: "test" `; const fileName = 'Chart.yaml'; - const result = await extractPackageFile(content, fileName, { - registryAliases: { - stable: 'https://charts.helm.sh/stable', - }, - }); + const result = await extractPackageFile(content, fileName, config); expect(result).toBeNull(); }); }); diff --git a/lib/modules/manager/regex/index.ts b/lib/modules/manager/regex/index.ts index 6a316d9b17..ac4c5323c7 100644 --- a/lib/modules/manager/regex/index.ts +++ b/lib/modules/manager/regex/index.ts @@ -1,36 +1,44 @@ import is from '@sindresorhus/is'; import type { RegexManagerTemplates } from '../../../config/types'; import type { - CustomExtractConfig, + ExtractConfig, PackageDependency, PackageFile, Result, } from '../types'; import { handleAny, handleCombination, handleRecursive } from './strategies'; +import type { RegexManagerConfig } from './types'; import { validMatchFields } from './utils'; export const defaultConfig = { pinDigests: false, }; - export const supportedDatasources = ['*']; export function extractPackageFile( content: string, packageFile: string, - config: CustomExtractConfig + config: ExtractConfig ): Result<PackageFile | null> { let deps: PackageDependency[]; switch (config.matchStringsStrategy) { default: case 'any': - deps = handleAny(content, packageFile, config); + deps = handleAny(content, packageFile, config as RegexManagerConfig); break; case 'combination': - deps = handleCombination(content, packageFile, config); + deps = handleCombination( + content, + packageFile, + config as RegexManagerConfig + ); break; case 'recursive': - deps = handleRecursive(content, packageFile, config); + deps = handleRecursive( + content, + packageFile, + config as RegexManagerConfig + ); break; } diff --git a/lib/modules/manager/regex/strategies.ts b/lib/modules/manager/regex/strategies.ts index 22d06d5415..d64f151c03 100644 --- a/lib/modules/manager/regex/strategies.ts +++ b/lib/modules/manager/regex/strategies.ts @@ -1,7 +1,7 @@ import is from '@sindresorhus/is'; import { regEx } from '../../../util/regex'; -import type { CustomExtractConfig, PackageDependency } from '../types'; -import type { RecursionParameter } from './types'; +import type { PackageDependency } from '../types'; +import type { RecursionParameter, RegexManagerConfig } from './types'; import { createDependency, isValidDependency, @@ -13,7 +13,7 @@ import { export function handleAny( content: string, packageFile: string, - config: CustomExtractConfig + config: RegexManagerConfig ): PackageDependency[] { return config.matchStrings .map((matchString) => regEx(matchString, 'g')) @@ -31,7 +31,7 @@ export function handleAny( export function handleCombination( content: string, packageFile: string, - config: CustomExtractConfig + config: RegexManagerConfig ): PackageDependency[] { const matches = config.matchStrings .map((matchString) => regEx(matchString, 'g')) @@ -55,7 +55,7 @@ export function handleCombination( export function handleRecursive( content: string, packageFile: string, - config: CustomExtractConfig + config: RegexManagerConfig ): PackageDependency[] { const regexes = config.matchStrings.map((matchString) => regEx(matchString, 'g') diff --git a/lib/modules/manager/regex/types.ts b/lib/modules/manager/regex/types.ts index f0840a4e86..aaf0f8c4dd 100644 --- a/lib/modules/manager/regex/types.ts +++ b/lib/modules/manager/regex/types.ts @@ -13,3 +13,7 @@ export interface RecursionParameter { index: number; combinedGroups: Record<string, string>; } + +export interface RegexManagerConfig extends CustomExtractConfig { + matchStrings: string[]; +} diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index 45797482dd..97db4c823f 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -15,18 +15,16 @@ export interface ManagerData<T> { managerData?: T; } -export interface ExtractConfig { +export interface ExtractConfig extends CustomExtractConfig { registryAliases?: Record<string, string>; npmrc?: string; npmrcMerge?: boolean; skipInstalls?: boolean; } -export interface CustomExtractConfig - extends ExtractConfig, - RegexManagerTemplates { +export interface CustomExtractConfig extends RegexManagerTemplates { autoReplaceStringTemplate?: string; - matchStrings: string[]; + matchStrings?: string[]; matchStringsStrategy?: MatchStringsStrategy; } diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 87f3cc36b9..32c036afef 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -10,7 +10,6 @@ import type { import type { Release } from '../modules/datasource/types'; import type { ArtifactError, - CustomExtractConfig, ExtractConfig, LookupUpdate, PackageDependency, @@ -129,9 +128,7 @@ export interface BranchConfig isConflicted?: boolean; } -export interface WorkerExtractConfig - extends ExtractConfig, - Partial<CustomExtractConfig> { +export interface WorkerExtractConfig extends ExtractConfig { manager: string; fileList: string[]; fileMatch?: string[]; -- GitLab