Skip to content

Commit

Permalink
Merge branch 'feat/filter-unavailable-users' of https://github.com/fg…
Browse files Browse the repository at this point in the history
…reinacher/renovate into pr/fgreinacher/9406
  • Loading branch information
fgreinacher committed Apr 19, 2021
2 parents e1edc49 + 013691e commit 35bb528
Show file tree
Hide file tree
Showing 35 changed files with 229 additions and 1,198 deletions.
2 changes: 1 addition & 1 deletion docs/usage/self-hosted-configuration.md
Expand Up @@ -81,7 +81,7 @@ e.g.

```json
{
"autodiscoverFilter": "project/*"
"autodiscoverFilter": ["project/*"]
}
```

Expand Down
1 change: 1 addition & 0 deletions lib/config/__snapshots__/migration.spec.ts.snap
Expand Up @@ -95,6 +95,7 @@ Object {
"dependencyDashboardTitle": "foo",
"enabled": true,
"extends": Array [
":automergeBranch",
"config:js-app",
"config:js-lib",
":dependencyDashboard",
Expand Down
5 changes: 3 additions & 2 deletions lib/config/definitions.ts
Expand Up @@ -579,7 +579,9 @@ const options: RenovateOptions[] = [
name: 'autodiscoverFilter',
description: 'Filter the list of autodiscovered repositories.',
stage: 'global',
type: 'string',
type: 'array',
subType: 'string',
allowString: true,
default: null,
},
{
Expand Down Expand Up @@ -1082,7 +1084,6 @@ const options: RenovateOptions[] = [
stage: 'package',
type: 'object',
default: {
recreateClosed: true,
rebaseWhen: 'behind-base-branch',
groupName: 'Pin Dependencies',
groupSlug: 'pin-dependencies',
Expand Down
8 changes: 7 additions & 1 deletion lib/config/migration.spec.ts
Expand Up @@ -30,7 +30,13 @@ describe(getName(__filename), () => {
compatibility: {
python: '3.7',
},
extends: [':js-app', 'config:library', ':masterIssue'],
extends: [
':automergeBranchMergeCommit',
'default:js-app',
'config:library',
':masterIssue',
'helpers:oddIsUnstable',
],
maintainYarnLock: true,
onboarding: 'false' as never,
multipleMajorPrs: true,
Expand Down
18 changes: 6 additions & 12 deletions lib/config/migration.ts
Expand Up @@ -5,6 +5,7 @@ import { logger } from '../logger';
import type { HostRule } from '../types';
import { clone } from '../util/clone';
import { getOptions } from './definitions';
import { removedPresets } from './presets/common';
import type { PackageRule, RenovateConfig, RenovateOptions } from './types';
import { mergeChildConfig } from './utils';

Expand Down Expand Up @@ -245,22 +246,15 @@ export function migrateConfig(
}
const presets = migratedConfig.extends;
for (let i = 0; i < presets.length; i += 1) {
let preset = presets[i];
const preset = presets[i];
if (is.string(preset)) {
if (preset === 'config:application' || preset === ':js-app') {
preset = 'config:js-app';
} else if (preset === ':library' || preset === 'config:library') {
preset = 'config:js-lib';
} else if (preset.startsWith(':masterIssue')) {
preset = preset.replace('masterIssue', 'dependencyDashboard');
} else if (
[':unpublishSafe', 'default:unpublishSafe'].includes(preset)
) {
preset = 'npm:unpublishSafe';
const newPreset = removedPresets[preset];
if (newPreset !== undefined) {
presets[i] = newPreset;
}
presets[i] = preset;
}
}
migratedConfig.extends = migratedConfig.extends.filter(Boolean);
} else if (key === 'unpublishSafe') {
if (val === true) {
migratedConfig.extends = migratedConfig.extends || [];
Expand Down
13 changes: 10 additions & 3 deletions lib/config/presets/__snapshots__/index.spec.ts.snap
Expand Up @@ -46,9 +46,7 @@ Object {
],
"packageRules": Array [
Object {
"extends": Array [
"",
],
"extends": Array [],
"groupName": "{{arg1}}",
},
],
Expand All @@ -67,6 +65,15 @@ exports[`config/presets/index getPreset handles preset not found 2`] = `undefine

exports[`config/presets/index getPreset handles preset not found 3`] = `undefined`;

exports[`config/presets/index getPreset handles removed presets with a migration 1`] = `
Object {
"dependencyDashboard": true,
"description": Array [
"Enable Renovate Dependency Dashboard creation",
],
}
`;

exports[`config/presets/index getPreset handles throw errors 1`] = `undefined`;

exports[`config/presets/index getPreset handles throw errors 2`] = `undefined`;
Expand Down
23 changes: 23 additions & 0 deletions lib/config/presets/common.ts
@@ -0,0 +1,23 @@
export const removedPresets = {
':automergeBranchMergeCommit': ':automergeBranch',
':automergeBranchPush': ':automergeBranch',
':base': 'config:base',
':app': 'config:js-app',
':js-app': 'config:js-app',
':library': 'config:js-lib',
':masterIssue': ':dependencyDashboard',
':masterIssueApproval': ':dependencyDashboardApproval',
':unpublishSafe': 'npm:unpublishSafe',
'config:application': 'config:js-app',
'config:base-js': 'config:base',
'config:library': 'config:js-lib',
'default:automergeBranchMergeCommit': ':automergeBranch',
'default:automergeBranchPush': ':automergeBranch',
'default:base': 'config:base',
'default:app': 'config:js-app',
'default:js-app': 'config:js-app',
'default:library': 'config:js-lib',
'default:unpublishSafe': 'npm:unpublishSafe',
'helpers:oddIsUnstable': null,
'helpers:oddIsUnstablePackages': null,
};
19 changes: 16 additions & 3 deletions lib/config/presets/index.spec.ts
Expand Up @@ -3,6 +3,11 @@ import { getName, mocked } from '../../../test/util';
import presetIkatyang from './__fixtures__/renovate-config-ikatyang.json';
import * as _local from './local';
import * as _npm from './npm';
import {
PRESET_DEP_NOT_FOUND,
PRESET_NOT_FOUND,
PRESET_RENOVATE_CONFIG_NOT_FOUND,
} from './util';
import * as presets from '.';

jest.mock('./npm');
Expand All @@ -19,16 +24,16 @@ npm.getPreset = jest.fn(({ packageName, presetName }) => {
][presetName];
}
if (packageName === 'renovate-config-notfound') {
throw new Error('dep not found');
throw new Error(PRESET_DEP_NOT_FOUND);
}
if (packageName === 'renovate-config-noconfig') {
throw new Error('preset renovate-config not found');
throw new Error(PRESET_RENOVATE_CONFIG_NOT_FOUND);
}
if (packageName === 'renovate-config-throw') {
throw new Error('whoops');
}
if (packageName === 'renovate-config-wrongpreset') {
throw new Error('preset not found');
throw new Error(PRESET_NOT_FOUND);
}
return null;
});
Expand Down Expand Up @@ -387,6 +392,14 @@ describe(getName(__filename), () => {
});
});
describe('getPreset', () => {
it('handles removed presets with a migration', async () => {
const res = await presets.getPreset(':masterIssue', {});
expect(res).toMatchSnapshot();
});
it('handles removed presets with no migration', async () => {
const res = await presets.getPreset('helpers:oddIsUnstable', {});
expect(res).toEqual({});
});
it('gets linters', async () => {
const res = await presets.getPreset('packages:linters', {});
expect(res).toMatchSnapshot();
Expand Down
29 changes: 22 additions & 7 deletions lib/config/presets/index.ts
Expand Up @@ -10,14 +10,21 @@ import * as massage from '../massage';
import * as migration from '../migration';
import type { GlobalConfig, RenovateConfig } from '../types';
import { mergeChildConfig } from '../utils';
import { removedPresets } from './common';
import * as gitea from './gitea';
import * as github from './github';
import * as gitlab from './gitlab';
import * as internal from './internal';
import * as local from './local';
import * as npm from './npm';
import type { PresetApi } from './types';
import { PRESET_DEP_NOT_FOUND } from './util';
import {
PRESET_DEP_NOT_FOUND,
PRESET_INVALID,
PRESET_NOT_FOUND,
PRESET_PROHIBITED_SUBPRESET,
PRESET_RENOVATE_CONFIG_NOT_FOUND,
} from './util';

const presetSources: Record<string, PresetApi> = {
github,
Expand Down Expand Up @@ -134,10 +141,10 @@ export function parsePreset(input: string): ParsedPreset {

// Validation
if (str.includes(':')) {
throw new Error('prohibited sub-preset');
throw new Error(PRESET_PROHIBITED_SUBPRESET);
}
if (!re.test(str)) {
throw new Error('invalid preset');
throw new Error(PRESET_INVALID);
}
[, packageName, presetPath, presetName] = re.exec(str);
} else {
Expand All @@ -159,6 +166,14 @@ export async function getPreset(
baseConfig?: RenovateConfig
): Promise<RenovateConfig> {
logger.trace(`getPreset(${preset})`);
// Check if the preset has been removed or replaced
const newPreset = removedPresets[preset];
if (newPreset) {
return getPreset(newPreset, baseConfig);
}
if (newPreset === null) {
return {};
}
const {
presetSource,
packageName,
Expand Down Expand Up @@ -255,13 +270,13 @@ export async function resolveConfigPresets(
const error = new Error(CONFIG_VALIDATION);
if (err.message === PRESET_DEP_NOT_FOUND) {
error.validationError = `Cannot find preset's package (${preset})`;
} else if (err.message === 'preset renovate-config not found') {
} else if (err.message === PRESET_RENOVATE_CONFIG_NOT_FOUND) {
error.validationError = `Preset package is missing a renovate-config entry (${preset})`;
} else if (err.message === 'preset not found') {
} else if (err.message === PRESET_NOT_FOUND) {
error.validationError = `Preset name not found within published preset config (${preset})`;
} else if (err.message === 'invalid preset') {
} else if (err.message === PRESET_INVALID) {
error.validationError = `Preset is invalid (${preset})`;
} else if (err.message === 'prohibited sub-preset') {
} else if (err.message === PRESET_PROHIBITED_SUBPRESET) {
error.validationError = `Sub-presets cannot be combined with a custom path (${preset})`;
}
// istanbul ignore if
Expand Down
4 changes: 0 additions & 4 deletions lib/config/presets/internal/config.ts
Expand Up @@ -21,10 +21,6 @@ export const presets: Record<string, Preset> = {
'workarounds:all',
],
},
'base-js': {
description: 'Base configuration for Javascript (deprecated)',
extends: ['config:base'],
},
'js-app': {
description: 'Default configuration for webapps',
extends: ['config:base', ':pinAllExceptPeerDependencies'],
Expand Down
22 changes: 0 additions & 22 deletions lib/config/presets/internal/default.ts
Expand Up @@ -304,16 +304,6 @@ export const presets: Record<string, Preset> = {
'If automerging, push the new commit directly to base branch (no PR)',
automergeType: 'branch',
},
automergeBranchMergeCommit: {
description:
'If automerging, perform a merge-commit on branch (no PR) - deprecated, use :automergeBranch instead',
automergeType: 'branch-merge-commit',
},
automergeBranchPush: {
description:
'If automerging, push the new commit directly to base branch (no PR) - deprecated, use :automergeBranch instead',
automergeType: 'branch-push',
},
automergePr: {
description: 'Raise a PR first before any automerging',
automergeType: 'pr',
Expand Down Expand Up @@ -572,18 +562,6 @@ export const presets: Record<string, Preset> = {
},
],
},
base: {
description: 'deprecated alias for config:base',
extends: ['config:base'],
},
app: {
description: 'deprecated alias for config:js-app',
extends: ['config:js-app'],
},
library: {
description: 'deprecated alias for config:js-lib',
extends: ['config:js-lib'],
},
disablePrControls: {
description: 'Remove the checkbox controls from PRs',
prBodyTemplate:
Expand Down
7 changes: 0 additions & 7 deletions lib/config/presets/internal/helpers.ts
Expand Up @@ -10,13 +10,6 @@ export const presets: Record<string, Preset> = {
},
],
},
oddIsUnstable: {
description: 'DEPRECATED: Odd version numbers are classified as unstable',
},
oddIsUnstablePackages: {
description:
'DEPRECATED: Preconfigure dependencies where an odd major version indicates unstable (Docker-only)',
},
followTypescriptNext: {
description:
'Keep <typescript> version in sync with the <code>next</code> tag',
Expand Down
11 changes: 8 additions & 3 deletions lib/config/presets/npm/index.ts
Expand Up @@ -3,6 +3,11 @@ import { NpmResponse } from '../../../datasource/npm/types';
import { logger } from '../../../logger';
import { Http } from '../../../util/http';
import type { Preset, PresetConfig } from '../types';
import {
PRESET_DEP_NOT_FOUND,
PRESET_NOT_FOUND,
PRESET_RENOVATE_CONFIG_NOT_FOUND,
} from '../util';

const id = 'npm';

Expand All @@ -19,10 +24,10 @@ export async function getPreset({
.body;
dep = body.versions[body['dist-tags'].latest];
} catch (err) {
throw new Error('dep not found');
throw new Error(PRESET_DEP_NOT_FOUND);
}
if (!dep['renovate-config']) {
throw new Error('preset renovate-config not found');
throw new Error(PRESET_RENOVATE_CONFIG_NOT_FOUND);
}
const presetConfig = dep['renovate-config'][presetName];
if (!presetConfig) {
Expand All @@ -31,7 +36,7 @@ export async function getPreset({
{ presetNames, presetName },
'Preset not found within renovate-config'
);
throw new Error('preset not found');
throw new Error(PRESET_NOT_FOUND);
}
return presetConfig;
}
6 changes: 5 additions & 1 deletion lib/config/presets/util.ts
Expand Up @@ -3,8 +3,12 @@ import { ensureTrailingSlash } from '../../util/url';
import type { Preset } from './types';

export const PRESET_DEP_NOT_FOUND = 'dep not found';
export const PRESET_NOT_FOUND = 'preset not found';
export const PRESET_INVALID = 'invalid preset';
export const PRESET_INVALID_JSON = 'invalid preset JSON';
export const PRESET_NOT_FOUND = 'preset not found';
export const PRESET_PROHIBITED_SUBPRESET = 'prohibited sub-preset';
export const PRESET_RENOVATE_CONFIG_NOT_FOUND =
'preset renovate-config not found';

export type PresetFetcher = (
repo: string,
Expand Down
21 changes: 20 additions & 1 deletion lib/config/types.ts
Expand Up @@ -68,7 +68,7 @@ export interface RenovateSharedConfig {
// The below should contain config options where stage=global
export interface GlobalOnlyConfig {
autodiscover?: boolean;
autodiscoverFilter?: string;
autodiscoverFilter?: string[];
baseDir?: string;
forceCli?: boolean;
gitPrivateKey?: string;
Expand Down Expand Up @@ -332,3 +332,22 @@ export type RenovateOptions =
| RenovateBooleanOption
| RenovateArrayOption
| RenovateObjectOption;

export interface PackageRuleInputConfig extends Record<string, unknown> {
versioning?: string;
packageFile?: string;
depType?: string;
depTypes?: string[];
depName?: string;
currentValue?: string;
currentVersion?: string;
lockedVersion?: string;
updateType?: UpdateType;
isBump?: boolean;
sourceUrl?: string;
language?: string;
baseBranch?: string;
manager?: string;
datasource?: string;
packageRules?: (PackageRule & PackageRuleInputConfig)[];
}

0 comments on commit 35bb528

Please sign in to comment.