Skip to content

Commit

Permalink
refactor(managers): move regex in custom folder (#23715)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Aug 6, 2023
1 parent 6488bcd commit 9dc51d0
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 51 deletions.
2 changes: 1 addition & 1 deletion lib/config/presets/internal/regex-managers.spec.ts
@@ -1,6 +1,6 @@
import { codeBlock } from 'common-tags';
import { regexMatches } from '../../../../test/util';
import { extractPackageFile } from '../../../modules/manager/regex';
import { extractPackageFile } from '../../../modules/manager/custom/regex';
import { presets } from './regex-managers';

describe('config/presets/internal/regex-managers', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/api.ts
Expand Up @@ -21,6 +21,7 @@ import * as cocoapods from './cocoapods';
import * as composer from './composer';
import * as conan from './conan';
import * as cpanfile from './cpanfile';
import * as regex from './custom/regex';
import * as depsEdn from './deps-edn';
import * as dockerCompose from './docker-compose';
import * as dockerfile from './dockerfile';
Expand Down Expand Up @@ -70,7 +71,6 @@ import * as preCommit from './pre-commit';
import * as pub from './pub';
import * as puppet from './puppet';
import * as pyenv from './pyenv';
import * as regex from './regex';
import * as rubyVersion from './ruby-version';
import * as sbt from './sbt';
import * as setupCfg from './setup-cfg';
Expand Down
15 changes: 15 additions & 0 deletions lib/modules/manager/custom/index.spec.ts
@@ -0,0 +1,15 @@
import * as customManager from '.';

describe('modules/manager/custom/index', () => {
it('has default config', () => {
expect(customManager.defaultConfig).toEqual({});
});

it('gets supportedDatasources', () => {
expect(customManager.supportedDatasources).toEqual(['*']);
});

it('extractPackageFile', () => {
expect(customManager.extractPackageFile('', '', {})).toEqual({ deps: [] });
});
});
12 changes: 12 additions & 0 deletions lib/modules/manager/custom/index.ts
@@ -0,0 +1,12 @@
import type { ExtractConfig, PackageFileContent, Result } from '../types';

// export hollow functions for validation as manager
export const defaultConfig = {};
export const supportedDatasources = ['*'];
export function extractPackageFile(
content: string,
packageFile: string,
config: ExtractConfig
): Result<PackageFileContent | null> {
return { deps: [] };
}
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`modules/manager/regex/index extracts and applies a registryUrlTemplate 1`] = `
exports[`modules/manager/custom/regex/index extracts and applies a registryUrlTemplate 1`] = `
{
"deps": [
{
Expand All @@ -22,7 +22,7 @@ exports[`modules/manager/regex/index extracts and applies a registryUrlTemplate
}
`;

exports[`modules/manager/regex/index extracts and does not apply a registryUrlTemplate if the result is an invalid url 1`] = `
exports[`modules/manager/custom/regex/index extracts and does not apply a registryUrlTemplate if the result is an invalid url 1`] = `
{
"deps": [
{
Expand All @@ -41,7 +41,7 @@ exports[`modules/manager/regex/index extracts and does not apply a registryUrlTe
}
`;

exports[`modules/manager/regex/index extracts dependency with autoReplaceStringTemplate 1`] = `
exports[`modules/manager/custom/regex/index extracts dependency with autoReplaceStringTemplate 1`] = `
{
"autoReplaceStringTemplate": "image: {{{depName}}}:{{{newValue}}}",
"datasourceTemplate": "docker",
Expand All @@ -60,7 +60,7 @@ exports[`modules/manager/regex/index extracts dependency with autoReplaceStringT
}
`;

exports[`modules/manager/regex/index extracts extractVersion 1`] = `
exports[`modules/manager/custom/regex/index extracts extractVersion 1`] = `
{
"deps": [
{
Expand All @@ -79,7 +79,7 @@ exports[`modules/manager/regex/index extracts extractVersion 1`] = `
}
`;

exports[`modules/manager/regex/index extracts multiple dependencies 1`] = `
exports[`modules/manager/custom/regex/index extracts multiple dependencies 1`] = `
{
"depTypeTemplate": "final",
"deps": [
Expand Down Expand Up @@ -163,7 +163,7 @@ exports[`modules/manager/regex/index extracts multiple dependencies 1`] = `
}
`;

exports[`modules/manager/regex/index extracts multiple dependencies with multiple matchStrings 1`] = `
exports[`modules/manager/custom/regex/index extracts multiple dependencies with multiple matchStrings 1`] = `
{
"deps": [
{
Expand Down Expand Up @@ -191,7 +191,7 @@ exports[`modules/manager/regex/index extracts multiple dependencies with multipl
}
`;

exports[`modules/manager/regex/index extracts registryUrl 1`] = `
exports[`modules/manager/custom/regex/index extracts registryUrl 1`] = `
{
"datasourceTemplate": "helm",
"deps": [
Expand Down Expand Up @@ -219,7 +219,7 @@ exports[`modules/manager/regex/index extracts registryUrl 1`] = `
}
`;
exports[`modules/manager/regex/index extracts with combination strategy 1`] = `
exports[`modules/manager/custom/regex/index extracts with combination strategy 1`] = `
{
"datasourceTemplate": "docker",
"deps": [
Expand All @@ -238,7 +238,7 @@ exports[`modules/manager/regex/index extracts with combination strategy 1`] = `
}
`;
exports[`modules/manager/regex/index extracts with combination strategy and multiple matches 1`] = `
exports[`modules/manager/custom/regex/index extracts with combination strategy and multiple matches 1`] = `
{
"datasourceTemplate": "docker",
"deps": [
Expand All @@ -257,7 +257,7 @@ exports[`modules/manager/regex/index extracts with combination strategy and mult
}
`;
exports[`modules/manager/regex/index extracts with combination strategy and non standard capture groups 1`] = `
exports[`modules/manager/custom/regex/index extracts with combination strategy and non standard capture groups 1`] = `
{
"datasourceTemplate": "docker",
"depNameTemplate": "{{{ registry }}}/{{{ repository }}}",
Expand All @@ -279,7 +279,7 @@ exports[`modules/manager/regex/index extracts with combination strategy and non
}
`;
exports[`modules/manager/regex/index extracts with combination strategy and registry url 1`] = `
exports[`modules/manager/custom/regex/index extracts with combination strategy and registry url 1`] = `
{
"datasourceTemplate": "helm",
"deps": [
Expand All @@ -304,7 +304,7 @@ exports[`modules/manager/regex/index extracts with combination strategy and regi
}
`;
exports[`modules/manager/regex/index extracts with combination strategy and templates 1`] = `
exports[`modules/manager/custom/regex/index extracts with combination strategy and templates 1`] = `
{
"datasourceTemplate": "helm",
"depNameTemplate": "helm_repo/{{{ depName }}}",
Expand All @@ -329,7 +329,7 @@ exports[`modules/manager/regex/index extracts with combination strategy and temp
}
`;
exports[`modules/manager/regex/index extracts with recursive strategy and merged groups 1`] = `
exports[`modules/manager/custom/regex/index extracts with recursive strategy and merged groups 1`] = `
{
"depNameTemplate": "{{{ first }}}/{{{ second }}}/{{{ depName }}}",
"deps": [
Expand Down Expand Up @@ -375,7 +375,7 @@ exports[`modules/manager/regex/index extracts with recursive strategy and merged
}
`;
exports[`modules/manager/regex/index extracts with recursive strategy and multiple layers 1`] = `
exports[`modules/manager/custom/regex/index extracts with recursive strategy and multiple layers 1`] = `
{
"deps": [
{
Expand All @@ -396,7 +396,7 @@ exports[`modules/manager/regex/index extracts with recursive strategy and multip
}
`;
exports[`modules/manager/regex/index extracts with recursive strategy and multiple matches 1`] = `
exports[`modules/manager/custom/regex/index extracts with recursive strategy and multiple matches 1`] = `
{
"deps": [
{
Expand Down Expand Up @@ -424,7 +424,7 @@ exports[`modules/manager/regex/index extracts with recursive strategy and multip
}
`;
exports[`modules/manager/regex/index extracts with recursive strategy and single match 1`] = `
exports[`modules/manager/custom/regex/index extracts with recursive strategy and single match 1`] = `
{
"deps": [
{
Expand Down
@@ -1,15 +1,15 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { logger } from '../../../logger';
import type { CustomExtractConfig } from '../types';
import { Fixtures } from '../../../../../test/fixtures';
import { logger } from '../../../../logger';
import type { CustomExtractConfig } from '../../types';
import { defaultConfig, extractPackageFile } from '.';

const dockerfileContent = Fixtures.get(`Dockerfile`);
const ansibleYamlContent = Fixtures.get(`ansible.yml`);
const exampleJsonContent = Fixtures.get(`example.json`);
const exampleGitlabCiYml = Fixtures.get(`gitlab-ci.yml`);

describe('modules/manager/regex/index', () => {
describe('modules/manager/custom/regex/index', () => {
it('has default config', () => {
expect(defaultConfig).toEqual({
pinDigests: false,
Expand Down Expand Up @@ -144,7 +144,6 @@ describe('modules/manager/regex/index', () => {
});

it('extracts and does not apply a registryUrlTemplate if the result is an invalid url', async () => {
jest.mock('../../../logger');
const config = {
matchStrings: [
'ENV GRADLE_VERSION=(?<currentValue>.*) # (?<datasource>.*?)/(?<depName>.*?)(\\&versioning=(?<versioning>.*?))?\\s',
Expand Down
@@ -1,11 +1,11 @@
import is from '@sindresorhus/is';
import type { RegexManagerTemplates } from '../../../config/types';
import type { RegexManagerTemplates } from '../../../../config/types';
import type {
ExtractConfig,
PackageDependency,
PackageFileContent,
Result,
} from '../types';
} from '../../types';
import { handleAny, handleCombination, handleRecursive } from './strategies';
import type { RegexManagerConfig } from './types';
import { validMatchFields } from './utils';
Expand Down
File renamed without changes.
@@ -1,6 +1,6 @@
import is from '@sindresorhus/is';
import { regEx } from '../../../util/regex';
import type { PackageDependency } from '../types';
import { regEx } from '../../../../util/regex';
import type { PackageDependency } from '../../types';
import type { RecursionParameter, RegexManagerConfig } from './types';
import {
createDependency,
Expand Down
@@ -1,4 +1,4 @@
import type { CustomExtractConfig } from '../types';
import type { CustomExtractConfig } from '../../types';

export interface ExtractionTemplate {
groups: Record<string, string>;
Expand Down
@@ -1,7 +1,7 @@
import { regEx } from '../../../util/regex';
import { regEx } from '../../../../util/regex';
import * as utils from './utils';

describe('modules/manager/regex/utils', () => {
describe('modules/manager/custom/regex/utils', () => {
it('does not crash for lazy regex', () => {
const lazyMatch = regEx('(?<currentDigest>.*?)', 'g');
expect(
Expand Down
@@ -1,10 +1,10 @@
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 { 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';

export const validMatchFields = [
Expand Down
12 changes: 9 additions & 3 deletions lib/modules/manager/index.spec.ts
@@ -1,3 +1,4 @@
import { join } from 'upath';
import { loadModules } from '../../util/modules';
import { getDatasourceList } from '../datasource';
import type { ManagerApi } from './types';
Expand Down Expand Up @@ -27,7 +28,8 @@ describe('modules/manager/index', () => {

describe('get()', () => {
it('gets something', () => {
expect(manager.get('dockerfile', 'extractPackageFile')).not.toBeNull();
expect(manager.get('dockerfile', 'extractPackageFile')).not.toBeNull(); // gets built-in manager
expect(manager.get('regex', 'extractPackageFile')).not.toBeNull(); // gets custom manager
});
});

Expand All @@ -52,8 +54,12 @@ describe('modules/manager/index', () => {
}
const mgrs = manager.getManagers();

const loadedMgr = loadModules(__dirname, validate);
expect(Array.from(mgrs.keys())).toEqual(Object.keys(loadedMgr));
const loadedMgr = {
...loadModules(__dirname, validate), // validate built-in managers
...loadModules(join(__dirname, 'custom'), validate), // validate custom managers
};
delete loadedMgr['custom'];
expect(Array.from(mgrs.keys())).toEqual(Object.keys(loadedMgr).sort());

for (const name of mgrs.keys()) {
const mgr = mgrs.get(name)!;
Expand Down
9 changes: 7 additions & 2 deletions lib/modules/manager/metadata.spec.ts
Expand Up @@ -5,13 +5,18 @@ describe('modules/manager/metadata', () => {
.readdirSync(__dirname, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name)
.filter((name) => !name.startsWith('__'))
.filter((name) => !name.startsWith('__') || name === 'custom')
.sort();

it.each(managerList)('%s has readme with no h1 or h2', async (manager) => {
let readme: string | undefined;
try {
readme = await fs.readFile(`${__dirname}/${manager}/readme.md`, 'utf8');
readme = await fs.readFile(
`${__dirname}/${
manager === 'custom' ? 'custom/regex' : manager
}/readme.md`,
'utf8'
);
} catch (err) {
// do nothing
}
Expand Down
Expand Up @@ -4,7 +4,7 @@ import type {
RenovateConfig,
} from '../../../config/types';
import { getManagerList } from '../../../modules/manager';
import { validMatchFields } from '../../../modules/manager/regex/utils';
import { validMatchFields } from '../../../modules/manager/custom/regex/utils';
import type { CustomExtractConfig } from '../../../modules/manager/types';
import type { WorkerExtractConfig } from '../../types';

Expand Down
4 changes: 3 additions & 1 deletion tools/docs/manager.ts
Expand Up @@ -133,7 +133,9 @@ sidebar_label: ${displayName}
md += '```\n\n';
}
const managerReadmeContent = await readFile(
`lib/modules/manager/${manager}/readme.md`
`lib/modules/manager/${
manager === 'regex' ? 'custom/regex' : manager
}/readme.md`
);
if (manager !== 'regex') {
md += '\n## Additional Information\n\n';
Expand Down

0 comments on commit 9dc51d0

Please sign in to comment.