From fb8ebc95bab1a55a49a5f8b04e5602d8ff3da3c5 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Wed, 6 Sep 2023 17:29:13 +0545 Subject: [PATCH 1/6] move custom manager types to /custom distribute types CustomManager and RegexManager --- .../custom/regex-managers-migration.spec.ts | 2 +- .../custom/regex-managers-migration.ts | 2 +- lib/config/types.ts | 21 +-------------- .../manager/custom/regex/index.spec.ts | 2 +- lib/modules/manager/custom/regex/index.ts | 3 +-- .../manager/custom/regex/strategies.ts | 2 +- lib/modules/manager/custom/regex/types.ts | 26 ++++++++++++++----- lib/modules/manager/custom/regex/utils.ts | 11 +++++--- lib/modules/manager/custom/types.ts | 17 ++++++++++++ lib/modules/manager/types.ts | 8 +----- .../extract/extract-fingerprint-config.ts | 8 +++--- 11 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 lib/modules/manager/custom/types.ts diff --git a/lib/config/migrations/custom/regex-managers-migration.spec.ts b/lib/config/migrations/custom/regex-managers-migration.spec.ts index 8311265bd50e55..be49c6bcf3c077 100644 --- a/lib/config/migrations/custom/regex-managers-migration.spec.ts +++ b/lib/config/migrations/custom/regex-managers-migration.spec.ts @@ -1,5 +1,5 @@ import { partial } from '../../../../test/util'; -import type { CustomManager } from '../../types'; +import type { CustomManager } from '../../../modules/manager/custom/types'; import { RegexManagersMigration } from './regex-managers-migration'; describe('config/migrations/custom/regex-managers-migration', () => { diff --git a/lib/config/migrations/custom/regex-managers-migration.ts b/lib/config/migrations/custom/regex-managers-migration.ts index ee23c0f6da01d3..4858762e7f17b3 100644 --- a/lib/config/migrations/custom/regex-managers-migration.ts +++ b/lib/config/migrations/custom/regex-managers-migration.ts @@ -1,6 +1,6 @@ import is from '@sindresorhus/is'; -import type { CustomManager } from '../../types'; import { AbstractMigration } from '../base/abstract-migration'; +import type { CustomManager } from '../../../modules/manager/custom/types'; export class RegexManagersMigration extends AbstractMigration { override readonly propertyName = 'regexManagers'; diff --git a/lib/config/types.ts b/lib/config/types.ts index 1f2ac991c4f7be..ebbe249f427190 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -3,6 +3,7 @@ import type { PlatformId } from '../constants'; import type { HostRule } from '../types'; import type { GitNoVerifyOption } from '../util/git/types'; import type { MergeConfidence } from '../util/merge-confidence/types'; +import type { CustomManager } from '../modules/manager/custom/types'; export type RenovateConfigStage = | 'global' @@ -183,26 +184,6 @@ export type RenovateRepository = repository: string; secrets?: Record; }; -export interface RegexManagerTemplates { - depNameTemplate?: string; - packageNameTemplate?: string; - datasourceTemplate?: string; - versioningTemplate?: string; - depTypeTemplate?: string; - currentValueTemplate?: string; - currentDigestTemplate?: string; - extractVersionTemplate?: string; - registryUrlTemplate?: string; -} - -export type CustomManagerName = 'regex'; -export interface CustomManager extends RegexManagerTemplates { - customType: CustomManagerName; - fileMatch: string[]; - matchStrings: string[]; - matchStringsStrategy?: MatchStringsStrategy; - autoReplaceStringTemplate?: string; -} export type UseBaseBranchConfigType = 'merge' | 'none'; export type ConstraintsFilter = 'strict' | 'none'; diff --git a/lib/modules/manager/custom/regex/index.spec.ts b/lib/modules/manager/custom/regex/index.spec.ts index e3fe7d34261279..bf836b8b338b40 100644 --- a/lib/modules/manager/custom/regex/index.spec.ts +++ b/lib/modules/manager/custom/regex/index.spec.ts @@ -1,8 +1,8 @@ import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../../test/fixtures'; import { logger } from '../../../../logger'; -import type { CustomExtractConfig } from '../../types'; import { defaultConfig, displayName, extractPackageFile } from '.'; +import type { CustomExtractConfig } from '../types'; const dockerfileContent = Fixtures.get(`Dockerfile`); const ansibleYamlContent = Fixtures.get(`ansible.yml`); diff --git a/lib/modules/manager/custom/regex/index.ts b/lib/modules/manager/custom/regex/index.ts index 58a36d3b748f32..2860ba4bc3887f 100644 --- a/lib/modules/manager/custom/regex/index.ts +++ b/lib/modules/manager/custom/regex/index.ts @@ -1,5 +1,4 @@ import is from '@sindresorhus/is'; -import type { RegexManagerTemplates } from '../../../../config/types'; import type { ExtractConfig, PackageDependency, @@ -7,7 +6,7 @@ import type { Result, } from '../../types'; import { handleAny, handleCombination, handleRecursive } from './strategies'; -import type { RegexManagerConfig } from './types'; +import type { RegexManagerConfig, RegexManagerTemplates } from './types'; import { validMatchFields } from './utils'; export const defaultConfig = { diff --git a/lib/modules/manager/custom/regex/strategies.ts b/lib/modules/manager/custom/regex/strategies.ts index 182c43e6936849..01a48a333391d8 100644 --- a/lib/modules/manager/custom/regex/strategies.ts +++ b/lib/modules/manager/custom/regex/strategies.ts @@ -84,7 +84,7 @@ function processRecursive(parameters: RecursionParameter): PackageDependency[] { regexes, config, }: RecursionParameter = parameters; - // abort if we have no matchString anymore + // abort if we have no matched strings anymore if (regexes.length === index) { const result = createDependency( { diff --git a/lib/modules/manager/custom/regex/types.ts b/lib/modules/manager/custom/regex/types.ts index 2f9682ce8c0ab7..ed5f3105e10eb9 100644 --- a/lib/modules/manager/custom/regex/types.ts +++ b/lib/modules/manager/custom/regex/types.ts @@ -1,19 +1,33 @@ -import type { CustomExtractConfig } from '../../types'; +import type { MatchStringsStrategy } from '../../../../config/types'; export interface ExtractionTemplate { groups: Record; replaceString: string | undefined; } +export interface RegexManagerTemplates { + depNameTemplate?: string; + packageNameTemplate?: string; + datasourceTemplate?: string; + versioningTemplate?: string; + depTypeTemplate?: string; + currentValueTemplate?: string; + currentDigestTemplate?: string; + extractVersionTemplate?: string; + registryUrlTemplate?: string; +} + +export interface RegexManagerConfig extends RegexManagerTemplates { + matchStrings: string[]; + matchStringsStrategy?: MatchStringsStrategy; + autoReplaceStringTemplate?: string; +} + export interface RecursionParameter { content: string; packageFile: string; - config: CustomExtractConfig; + config: RegexManagerConfig; regexes: RegExp[]; index: number; combinedGroups: Record; } - -export interface RegexManagerConfig extends CustomExtractConfig { - matchStrings: string[]; -} diff --git a/lib/modules/manager/custom/regex/utils.ts b/lib/modules/manager/custom/regex/utils.ts index 1f30b592e80153..37759af74f8a82 100644 --- a/lib/modules/manager/custom/regex/utils.ts +++ b/lib/modules/manager/custom/regex/utils.ts @@ -1,11 +1,14 @@ import { URL } from 'node:url'; import is from '@sindresorhus/is'; import { migrateDatasource } from '../../../../config/migrations/custom/datasource-migration'; -import type { RegexManagerTemplates } from '../../../../config/types'; import { logger } from '../../../../logger'; import * as template from '../../../../util/template'; -import type { CustomExtractConfig, PackageDependency } from '../../types'; -import type { ExtractionTemplate } from './types'; +import type { PackageDependency } from '../../types'; +import type { + ExtractionTemplate, + RegexManagerConfig, + RegexManagerTemplates, +} from './types'; export const validMatchFields = [ 'depName', @@ -51,7 +54,7 @@ function updateDependency( export function createDependency( extractionTemplate: ExtractionTemplate, - config: CustomExtractConfig, + config: RegexManagerConfig, dep?: PackageDependency ): PackageDependency | null { const dependency = dep ?? {}; diff --git a/lib/modules/manager/custom/types.ts b/lib/modules/manager/custom/types.ts new file mode 100644 index 00000000000000..27c494b151f438 --- /dev/null +++ b/lib/modules/manager/custom/types.ts @@ -0,0 +1,17 @@ +import type { RegexManagerConfig } from './regex/types'; + +export interface CustomExtractConfig extends Partial {} + +export type CustomManagerName = 'regex'; + +export interface CustomManager extends Partial { + customType: CustomManagerName; + fileMatch: string[]; +} + +// NOTE: +// the two interfaces might seem similar but they have different usage... +// CustomManager interface consists of all fields that a custom manager can have +// whereas +// CustomExtractConfig consists of the fields that custom managers need when performing extraction +// ie. options necessary for the function extractPackageFile diff --git a/lib/modules/manager/types.ts b/lib/modules/manager/types.ts index 9312bcd6069166..8cfdba235b92ee 100644 --- a/lib/modules/manager/types.ts +++ b/lib/modules/manager/types.ts @@ -1,7 +1,6 @@ import type { ReleaseType } from 'semver'; import type { MatchStringsStrategy, - RegexManagerTemplates, UpdateType, ValidationMessage, } from '../../config/types'; @@ -9,6 +8,7 @@ import type { Category } from '../../constants'; import type { ModuleApi, RangeStrategy, SkipReason } from '../../types'; import type { FileChange } from '../../util/git/types'; import type { MergeConfidence } from '../../util/merge-confidence/types'; +import type { CustomExtractConfig } from './custom/types'; export type Result = T | Promise; @@ -23,12 +23,6 @@ export interface ExtractConfig extends CustomExtractConfig { skipInstalls?: boolean | null; } -export interface CustomExtractConfig extends RegexManagerTemplates { - autoReplaceStringTemplate?: string; - matchStrings?: string[]; - matchStringsStrategy?: MatchStringsStrategy; -} - export interface UpdateArtifactsConfig { isLockFileMaintenance?: boolean; constraints?: Record; diff --git a/lib/workers/repository/extract/extract-fingerprint-config.ts b/lib/workers/repository/extract/extract-fingerprint-config.ts index 8f17505cee8582..8f3bf56a2fbf33 100644 --- a/lib/workers/repository/extract/extract-fingerprint-config.ts +++ b/lib/workers/repository/extract/extract-fingerprint-config.ts @@ -1,12 +1,10 @@ import { getManagerConfig, mergeChildConfig } from '../../../config'; -import type { - RegexManagerTemplates, - RenovateConfig, -} from '../../../config/types'; +import type { RenovateConfig } from '../../../config/types'; import { allManagersList } from '../../../modules/manager'; import { isCustomManager } from '../../../modules/manager/custom'; +import type { RegexManagerTemplates } from '../../../modules/manager/custom/regex/types'; import { validMatchFields } from '../../../modules/manager/custom/regex/utils'; -import type { CustomExtractConfig } from '../../../modules/manager/types'; +import type { CustomExtractConfig } from '../../../modules/manager/custom/types'; import type { WorkerExtractConfig } from '../../types'; export interface FingerprintExtractConfig { From 9ea19ccdecc0864daecd4138f086697d56d47645 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 8 Sep 2023 16:50:17 +0545 Subject: [PATCH 2/6] Update lib/modules/manager/custom/types.ts --- lib/modules/manager/custom/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/custom/types.ts b/lib/modules/manager/custom/types.ts index 27c494b151f438..4c30d465345f29 100644 --- a/lib/modules/manager/custom/types.ts +++ b/lib/modules/manager/custom/types.ts @@ -13,5 +13,5 @@ export interface CustomManager extends Partial { // the two interfaces might seem similar but they have different usage... // CustomManager interface consists of all fields that a custom manager can have // whereas -// CustomExtractConfig consists of the fields that custom managers need when performing extraction +// CustomExtractConfig consists of the fields that custom managers need to extract deps from a package file // ie. options necessary for the function extractPackageFile From 28677d92b52c3709934014c4cd115c8d1e3c01d8 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 8 Sep 2023 17:02:59 +0545 Subject: [PATCH 3/6] fix imports --- lib/config/migrations/custom/regex-managers-migration.ts | 2 +- lib/config/types.ts | 2 +- lib/modules/manager/custom/regex/index.spec.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/config/migrations/custom/regex-managers-migration.ts b/lib/config/migrations/custom/regex-managers-migration.ts index 4858762e7f17b3..afaad6c80537b2 100644 --- a/lib/config/migrations/custom/regex-managers-migration.ts +++ b/lib/config/migrations/custom/regex-managers-migration.ts @@ -1,6 +1,6 @@ import is from '@sindresorhus/is'; -import { AbstractMigration } from '../base/abstract-migration'; import type { CustomManager } from '../../../modules/manager/custom/types'; +import { AbstractMigration } from '../base/abstract-migration'; export class RegexManagersMigration extends AbstractMigration { override readonly propertyName = 'regexManagers'; diff --git a/lib/config/types.ts b/lib/config/types.ts index ebbe249f427190..e71265f9555a3d 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -1,9 +1,9 @@ import type { LogLevel } from 'bunyan'; import type { PlatformId } from '../constants'; +import type { CustomManager } from '../modules/manager/custom/types'; import type { HostRule } from '../types'; import type { GitNoVerifyOption } from '../util/git/types'; import type { MergeConfidence } from '../util/merge-confidence/types'; -import type { CustomManager } from '../modules/manager/custom/types'; export type RenovateConfigStage = | 'global' diff --git a/lib/modules/manager/custom/regex/index.spec.ts b/lib/modules/manager/custom/regex/index.spec.ts index bf836b8b338b40..608ba97fadb830 100644 --- a/lib/modules/manager/custom/regex/index.spec.ts +++ b/lib/modules/manager/custom/regex/index.spec.ts @@ -1,8 +1,8 @@ import { codeBlock } from 'common-tags'; import { Fixtures } from '../../../../../test/fixtures'; import { logger } from '../../../../logger'; -import { defaultConfig, displayName, extractPackageFile } from '.'; import type { CustomExtractConfig } from '../types'; +import { defaultConfig, displayName, extractPackageFile } from '.'; const dockerfileContent = Fixtures.get(`Dockerfile`); const ansibleYamlContent = Fixtures.get(`ansible.yml`); From cfb9fb921ffcf6509f1a5bb5227b91815b2cc535 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 8 Sep 2023 17:04:26 +0545 Subject: [PATCH 4/6] Update lib/modules/manager/custom/types.ts --- lib/modules/manager/custom/types.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/modules/manager/custom/types.ts b/lib/modules/manager/custom/types.ts index 4c30d465345f29..de387685f80717 100644 --- a/lib/modules/manager/custom/types.ts +++ b/lib/modules/manager/custom/types.ts @@ -10,8 +10,4 @@ export interface CustomManager extends Partial { } // NOTE: -// the two interfaces might seem similar but they have different usage... -// CustomManager interface consists of all fields that a custom manager can have -// whereas -// CustomExtractConfig consists of the fields that custom managers need to extract deps from a package file -// ie. options necessary for the function extractPackageFile +// the two interfaces might seem similar but they have different usage similar to ManagerConfig and ExtractConfig From 24e9d22caf7712c8c90f889b90c28bcee6a25daa Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Wed, 13 Sep 2023 00:40:50 +0545 Subject: [PATCH 5/6] Update lib/modules/manager/custom/regex/strategies.ts --- lib/modules/manager/custom/regex/strategies.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/custom/regex/strategies.ts b/lib/modules/manager/custom/regex/strategies.ts index 743204652a10a9..a77c072be4748f 100644 --- a/lib/modules/manager/custom/regex/strategies.ts +++ b/lib/modules/manager/custom/regex/strategies.ts @@ -89,7 +89,7 @@ function processRecursive(parameters: RecursionParameter): PackageDependency[] { regexes, config, }: RecursionParameter = parameters; - // abort if we have no matched strings anymore + // abort if we have no matchString anymore if (regexes.length === index) { const result = createDependency( { From b0e6d9816ea97dc75b2f9aed48cabaab60c4f6fa Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Wed, 13 Sep 2023 01:36:02 +0545 Subject: [PATCH 6/6] fix build issue --- lib/config/validation.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/config/validation.ts b/lib/config/validation.ts index 7679a7379a3dd7..d63a47aaaa2cbf 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -1,7 +1,11 @@ import is from '@sindresorhus/is'; import { allManagersList, getManagerList } from '../modules/manager'; import { isCustomManager } from '../modules/manager/custom'; -import type { RegexManagerConfig } from '../modules/manager/custom/regex/types'; +import type { + RegexManagerConfig, + RegexManagerTemplates, +} from '../modules/manager/custom/regex/types'; +import type { CustomManager } from '../modules/manager/custom/types'; import { configRegexPredicate, isConfigRegex, regEx } from '../util/regex'; import * as template from '../util/template'; import { @@ -12,8 +16,6 @@ import { migrateConfig } from './migration'; import { getOptions } from './options'; import { resolveConfigPresets } from './presets'; import type { - CustomManager, - RegexManagerTemplates, RenovateConfig, RenovateOptions, ValidationMessage, @@ -657,7 +659,7 @@ export async function validateConfig( } function validateRegexManagerFields( - regexManager: RegexManagerConfig, + regexManager: Partial, currentPath: string, errors: ValidationMessage[] ): void { @@ -684,7 +686,7 @@ function validateRegexManagerFields( const templateField = `${field}Template` as keyof RegexManagerTemplates; if ( !regexManager[templateField] && - !regexManager.matchStrings.some((matchString) => + !regexManager.matchStrings?.some((matchString) => matchString.includes(`(?<${field}>`) ) ) {