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,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';

Check failure on line 3 in lib/config/migrations/custom/regex-managers-migration.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

`../../../modules/manager/custom/types` type import should occur before import of `../base/abstract-migration`

export class RegexManagersMigration extends AbstractMigration {
override readonly propertyName = 'regexManagers';
Expand Down
21 changes: 1 addition & 20 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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';

Check failure on line 6 in lib/config/types.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

`../modules/manager/custom/types` type import should occur before type import of `../types`

export type RenovateConfigStage =
| 'global'
Expand Down Expand Up @@ -183,26 +184,6 @@
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
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,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';

Check failure on line 5 in lib/modules/manager/custom/regex/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

`../types` type import should occur before import of `.`

const dockerfileContent = Fixtures.get(`Dockerfile`);
const ansibleYamlContent = Fixtures.get(`ansible.yml`);
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
2 changes: 1 addition & 1 deletion lib/modules/manager/custom/regex/strategies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
if (regexes.length === index) {
const result = createDependency(
{
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
17 changes: 17 additions & 0 deletions lib/modules/manager/custom/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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...
// 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
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
// ie. options necessary for the function extractPackageFile
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
Loading