Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(types): move custom manager types #24324

Merged
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/migrations/custom/regex-managers-migration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import is from '@sindresorhus/is';
import type { CustomManager } from '../../types';
import type { CustomManager } from '../../../modules/manager/custom/types';
import { AbstractMigration } from '../base/abstract-migration';

export class RegexManagersMigration extends AbstractMigration {
Expand Down
21 changes: 1 addition & 20 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
Expand Down Expand Up @@ -184,26 +185,6 @@ export type RenovateRepository =
repository: string;
secrets?: Record<string, string>;
};
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';
Expand Down
12 changes: 7 additions & 5 deletions lib/config/validation.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,8 +16,6 @@ import { migrateConfig } from './migration';
import { getOptions } from './options';
import { resolveConfigPresets } from './presets';
import type {
CustomManager,
RegexManagerTemplates,
RenovateConfig,
RenovateOptions,
ValidationMessage,
Expand Down Expand Up @@ -657,7 +659,7 @@ export async function validateConfig(
}

function validateRegexManagerFields(
regexManager: RegexManagerConfig,
regexManager: Partial<RegexManagerConfig>,
currentPath: string,
errors: ValidationMessage[]
): void {
Expand All @@ -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}>`)
)
) {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/custom/regex/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../../test/fixtures';
import { logger } from '../../../../logger';
import type { CustomExtractConfig } from '../../types';
import type { CustomExtractConfig } from '../types';
import { defaultConfig, displayName, extractPackageFile } from '.';

const dockerfileContent = Fixtures.get(`Dockerfile`);
Expand Down
3 changes: 1 addition & 2 deletions lib/modules/manager/custom/regex/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import is from '@sindresorhus/is';
import type { RegexManagerTemplates } from '../../../../config/types';
import type {
ExtractConfig,
PackageDependency,
PackageFileContent,
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 = {
Expand Down
26 changes: 20 additions & 6 deletions lib/modules/manager/custom/regex/types.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import type { CustomExtractConfig } from '../../types';
import type { MatchStringsStrategy } from '../../../../config/types';

export interface ExtractionTemplate {
groups: Record<string, string>;
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<string, string>;
}

export interface RegexManagerConfig extends CustomExtractConfig {
matchStrings: string[];
}
11 changes: 7 additions & 4 deletions lib/modules/manager/custom/regex/utils.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -51,7 +54,7 @@ function updateDependency(

export function createDependency(
extractionTemplate: ExtractionTemplate,
config: CustomExtractConfig,
config: RegexManagerConfig,
dep?: PackageDependency
): PackageDependency | null {
const dependency = dep ?? {};
Expand Down
13 changes: 13 additions & 0 deletions lib/modules/manager/custom/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { RegexManagerConfig } from './regex/types';

export interface CustomExtractConfig extends Partial<RegexManagerConfig> {}

export type CustomManagerName = 'regex';

export interface CustomManager extends Partial<RegexManagerConfig> {
customType: CustomManagerName;
fileMatch: string[];
}

// NOTE:
// the two interfaces might seem similar but they have different usage similar to ManagerConfig and ExtractConfig
8 changes: 1 addition & 7 deletions lib/modules/manager/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { ReleaseType } from 'semver';
import type {
MatchStringsStrategy,
RegexManagerTemplates,
UpdateType,
ValidationMessage,
} from '../../config/types';
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> = T | Promise<T>;

Expand All @@ -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<string, string>;
Expand Down
8 changes: 3 additions & 5 deletions lib/workers/repository/extract/extract-fingerprint-config.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down