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(enabled-managers): implement custom.<customMgrName> syntax #24079

Merged
merged 28 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3d039fc
custom-syntax for enabled-managers
RahulGautamSingh Aug 25, 2023
f4ca858
Update docs/usage/configuration-options.md
RahulGautamSingh Aug 25, 2023
95a70c0
apply sugggestions
RahulGautamSingh Aug 25, 2023
ef3455f
Merge branch 'main' into custom.-syntax
RahulGautamSingh Aug 25, 2023
e7700fd
fix lint issue
RahulGautamSingh Aug 25, 2023
a5d5d83
Update docs/usage/configuration-options.md
RahulGautamSingh Aug 25, 2023
ee4aa1a
Update lib/workers/repository/extract/index.ts
RahulGautamSingh Aug 25, 2023
20a26e1
revert early return
RahulGautamSingh Aug 25, 2023
0cf0b03
early return
RahulGautamSingh Aug 27, 2023
2b12118
Update lib/config/migrations/custom/enabled-managers-migration.spec.ts
RahulGautamSingh Aug 27, 2023
7358f97
Merge branch 'main' into custom.-syntax
RahulGautamSingh Aug 27, 2023
2e5b695
Merge branch 'main' into custom.-syntax
secustor Aug 29, 2023
0292238
Merge branch 'main' into custom.-syntax
RahulGautamSingh Oct 23, 2023
d1619c4
Update lib/workers/repository/extract/index.spec.ts
RahulGautamSingh Oct 23, 2023
025f80f
Merge branch 'main' into custom.-syntax
RahulGautamSingh Oct 23, 2023
8d72210
Merge branch 'main' into custom.-syntax
RahulGautamSingh Oct 24, 2023
76b1207
Merge branch 'main' into custom.-syntax
RahulGautamSingh Oct 31, 2023
9e77447
remove isCustomManager from EnabledManagersMigration
RahulGautamSingh Oct 31, 2023
3b90405
fix formatting
RahulGautamSingh Oct 31, 2023
bcfe33f
fix lint issues
RahulGautamSingh Oct 31, 2023
d5598f1
fix test
RahulGautamSingh Oct 31, 2023
7fbcd60
fix tests
RahulGautamSingh Oct 31, 2023
5bd271d
add comment to explain getEnabledManagersList logic
RahulGautamSingh Nov 3, 2023
17a6fc5
apply suggestions
RahulGautamSingh Nov 7, 2023
8b973a8
Update lib/workers/repository/extract/extract-fingerprint-config.ts
RahulGautamSingh Nov 7, 2023
a7f80b4
Merge branch 'main' into custom.-syntax
RahulGautamSingh Nov 8, 2023
d2793c4
fix formatting
RahulGautamSingh Nov 8, 2023
b3b4cdd
fix formatting
RahulGautamSingh Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,16 @@ Example:
}
```

To enable custom managers you will need to add `custom.` prefix before their names

Example:

```json
{
"enabledManagers": ["custom.regex"]
}
```

For the full list of available managers, see the [Supported Managers](https://docs.renovatebot.com/modules/manager/#supported-managers) documentation.

## encrypted
Expand Down
14 changes: 12 additions & 2 deletions lib/config/migrations/custom/enabled-managers-migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ describe('config/migrations/custom/enabled-managers-migration', () => {
it('should replace yarn with npm', () => {
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(EnabledManagersMigration).toMigrate(
{
enabledManagers: ['test1', 'yarn', 'test2'],
enabledManagers: ['test1', 'yarn', 'test2', 'regex'],
},
{
enabledManagers: ['test1', 'npm', 'test2'],
enabledManagers: ['test1', 'npm', 'test2', 'custom.regex'],
}
);

// coverage
expect(EnabledManagersMigration).not.toMigrate(
{
enabledManagers: undefined,
},
{
enabledManagers: undefined,
}
);
});
Expand Down
21 changes: 16 additions & 5 deletions lib/config/migrations/custom/enabled-managers-migration.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import is from '@sindresorhus/is';
import { isCustomManager } from '../../../modules/manager/custom';
import { AbstractMigration } from '../base/abstract-migration';

export class EnabledManagersMigration extends AbstractMigration {
override readonly propertyName = 'enabledManagers';

override run(value: unknown): void {
if (is.array(value)) {
const newValue = value.map((manager) =>
manager === 'yarn' ? 'npm' : manager
);
this.rewrite(newValue);
if (!is.array<string>(value, is.string)) {
return;
}

const newValue = value.map((manager) => {
if (manager === 'yarn') {
return 'npm';
}

if (isCustomManager(manager)) {
return `custom.${manager}`;
}

return manager;
});
this.rewrite(newValue);
}
}
2 changes: 1 addition & 1 deletion lib/config/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('config/validation', () => {
[
'multiple enabled managers',
{
enabledManagers: ['npm', 'gradle', 'maven', 'regex'],
enabledManagers: ['npm', 'gradle', 'maven', 'custom.regex'],
},
],
])('validates enabled managers for %s', async (_case, config) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function validatePlainObject(val: Record<string, unknown>): true | string {

function getUnsupportedEnabledManagers(enabledManagers: string[]): string[] {
return enabledManagers.filter(
(manager) => !allManagersList.includes(manager)
(manager) => !allManagersList.includes(manager.replace('custom.', ''))
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/custom/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('modules/manager/custom/index', () => {
it('works', () => {
expect(customManager.isCustomManager('npm')).toBe(false);
expect(customManager.isCustomManager('regex')).toBe(true);
expect(customManager.isCustomManager('custom.regex')).toBe(false);
});
});
});
10 changes: 10 additions & 0 deletions lib/modules/manager/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ describe('modules/manager/index', () => {
});
});

describe('getEnabledManagersList()', () => {
it('works', () => {
expect(manager.getEnabledManagersList()).toEqual(manager.allManagersList);
expect(manager.getEnabledManagersList(['custom.regex', 'npm'])).toEqual([
'regex',
'npm',
]);
});
});

it('validates', () => {
function validate(module: ManagerApi, moduleName: string): boolean {
// no need to validate custom as it is a wrapper and not an actual manager
Expand Down
12 changes: 12 additions & 0 deletions lib/modules/manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,15 @@ export function getRangeStrategy(config: RangeConfig): RangeStrategy | null {

return config.rangeStrategy;
}

export function getEnabledManagersList(enabledManagers?: string[]): string[] {
if (enabledManagers?.length) {
return allManagersList.filter(
(manager) =>
enabledManagers.includes(manager) ||
enabledManagers.includes(`custom.${manager}`)
);
}

return allManagersList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('workers/repository/extract/extract-fingerprint-config', () => {
notStable: 'http://some.link.2',
},
},
enabledManagers: ['npm', 'regex'],
enabledManagers: ['npm', 'custom.regex'],
regexManagers: [
{
customType: 'regex',
Expand Down
12 changes: 4 additions & 8 deletions lib/workers/repository/extract/extract-fingerprint-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
RegexManagerTemplates,
RenovateConfig,
} from '../../../config/types';
import { allManagersList } from '../../../modules/manager';
import { getEnabledManagersList } from '../../../modules/manager';
import { isCustomManager } from '../../../modules/manager/custom';
import { validMatchFields } from '../../../modules/manager/custom/regex/utils';
import type { CustomExtractConfig } from '../../../modules/manager/types';
Expand Down Expand Up @@ -56,13 +56,9 @@ export function generateFingerprintConfig(
config: RenovateConfig
): FingerprintExtractConfig {
const managerExtractConfigs: WorkerExtractConfig[] = [];
let managerList: Set<string>;
const { enabledManagers } = config;
if (enabledManagers?.length) {
managerList = new Set(enabledManagers);
} else {
managerList = new Set(allManagersList);
}
const managerList: Set<string> = new Set(
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
getEnabledManagersList(config.enabledManagers)
);

for (const manager of managerList) {
const managerConfig = getManagerConfig(config, manager);
Expand Down
11 changes: 9 additions & 2 deletions lib/workers/repository/extract/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ describe('workers/repository/extract/index', () => {
});

it('warns if no packages found for a enabled manager', async () => {
config.enabledManagers = ['npm'];
config.enabledManagers = ['npm', 'custom.regex'];
managerFiles.getManagerPackageFiles.mockResolvedValue([]);
expect((await extractAllDependencies(config)).packageFiles).toEqual({});
expect(logger.debug).toHaveBeenCalled();
// expect(logger.debug).toHaveBeenCalledWith(
// { manager: 'npm' },
// `Manager explicitly enabled in "enabledManagers" config, but found no results. Possible config error?`
// );
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
expect(logger.debug).toHaveBeenCalledWith(
{ manager: 'regex' },
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
`Manager explicitly enabled in "enabledManagers" config, but found no results. Possible config error?`
);
});

it('warns if packageFiles is null', async () => {
Expand Down
16 changes: 5 additions & 11 deletions lib/workers/repository/extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import is from '@sindresorhus/is';
import { getManagerConfig, mergeChildConfig } from '../../../config';
import type { ManagerConfig, RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import { allManagersList, hashMap } from '../../../modules/manager';
import { getEnabledManagersList, hashMap } from '../../../modules/manager';
import { isCustomManager } from '../../../modules/manager/custom';
import { scm } from '../../../modules/platform/scm';
import type { ExtractResult, WorkerExtractConfig } from '../../types';
Expand All @@ -12,14 +12,7 @@ import { getManagerPackageFiles } from './manager-files';
export async function extractAllDependencies(
config: RenovateConfig
): Promise<ExtractResult> {
let managerList = allManagersList;
const { enabledManagers } = config;
if (is.nonEmptyArray(enabledManagers)) {
logger.debug('Applying enabledManagers filtering');
managerList = managerList.filter((manager) =>
enabledManagers.includes(manager)
);
}
const managerList = getEnabledManagersList(config.enabledManagers);
const extractList: WorkerExtractConfig[] = [];
const fileList = await scm.getFileList();

Expand Down Expand Up @@ -86,9 +79,10 @@ export async function extractAllDependencies(
// If not, log a warning to indicate possible misconfiguration.
if (is.nonEmptyArray(config.enabledManagers)) {
for (const enabledManager of config.enabledManagers) {
if (!(enabledManager in extractResult.packageFiles)) {
const massagedMgr = enabledManager.replace('custom.', '');
if (!(massagedMgr in extractResult.packageFiles)) {
logger.debug(
{ manager: enabledManager },
{ manager: massagedMgr },
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
`Manager explicitly enabled in "enabledManagers" config, but found no results. Possible config error?`
);
}
Expand Down