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

feat: force, forceCli #2145

Merged
merged 6 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion lib/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ const options = [
cli: false,
env: false,
},
{
name: 'force',
description:
'Any configuration defined within this object will force override existing settings',
stage: 'repository',
admin: true,
type: 'json',
cli: false,
env: false,
},
{
name: 'forceCli',
description:
'Whether CLI configuration options should be moved to the `force` config section',
stage: 'global',
type: 'boolean',
default: false,
},
// Log options
{
name: 'logLevel',
Expand Down Expand Up @@ -147,7 +165,7 @@ const options = [
description: 'Times of day/week to renovate',
type: 'list',
allowString: true,
cli: false,
cli: true,
env: false,
},
{
Expand Down
4 changes: 4 additions & 0 deletions lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ async function parseConfigs(env, argv) {
config = mergeChildConfig(config, envConfig);
config = mergeChildConfig(config, cliConfig);

if (config.forceCli) {
config = mergeChildConfig(config, { force: { ...cliConfig } });
}

// Set log level
logger.levels('stdout', config.logLevel);

Expand Down
20 changes: 20 additions & 0 deletions lib/workers/repository/init/force.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { mergeChildConfig } = require('../../../config');

function applyForceConfig(input) {
let config = { ...input };
if (config.force && Object.keys(config.force).length) {
logger.debug('Applying forced config');
config = mergeChildConfig(config, config.force);
config.packageRules = config.packageRules || [];
config.packageRules.push({
...config.force,
packagePatterns: ['.*'],
});
delete config.force;
}
return config;
}

module.exports = {
applyForceConfig,
};
2 changes: 2 additions & 0 deletions lib/workers/repository/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { initApis } = require('../init/apis');
const { checkBaseBranch } = require('./base');
const { mergeRenovateConfig } = require('./config');
const { detectSemanticCommits } = require('./semantic');
const { applyForceConfig } = require('./force');

async function initRepo(input) {
let config = {
Expand All @@ -16,6 +17,7 @@ async function initRepo(input) {
config = await initApis(config);
config = await checkOnboardingBranch(config);
config = await mergeRenovateConfig(config);
config = await applyForceConfig(config);
checkIfConfigured(config);
config = await checkBaseBranch(config);
config.semanticCommits = await detectSemanticCommits(config);
Expand Down
5 changes: 5 additions & 0 deletions test/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ describe('config/index', () => {
const env = {};
await configParser.parseConfigs(env, defaultArgv);
});
it('supports forceCli', async () => {
defaultArgv = defaultArgv.concat(['--force-cli=true']);
const env = { GITHUB_TOKEN: 'abc' };
await configParser.parseConfigs(env, defaultArgv);
});
it('autodiscovers github platform', async () => {
const env = {};
defaultArgv = defaultArgv.concat(['--autodiscover', '--token=abc']);
Expand Down
17 changes: 17 additions & 0 deletions test/workers/repository/init/__snapshots__/force.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`workers/repository/init/flatten flattenPackageRules() forces 1`] = `
Object {
"a": 2,
"b": 2,
"packageRules": Array [
Object {
"a": 2,
"b": 2,
"packagePatterns": Array [
".*",
],
},
],
}
`;
18 changes: 18 additions & 0 deletions test/workers/repository/init/force.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const {
applyForceConfig,
} = require('../../../../lib/workers/repository/init/force');

describe('workers/repository/init/flatten', () => {
describe('flattenPackageRules()', () => {
it('returns empty', () => {
expect(applyForceConfig({})).toEqual({});
});
it('forces', () => {
const res = applyForceConfig({ a: 1, force: { a: 2, b: 2 } });
expect(res).toMatchSnapshot();
expect(res.a).toEqual(2);
expect(res.b).toEqual(2);
expect(res.force).toBeUndefined();
});
});
});
10 changes: 10 additions & 0 deletions website/docs/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Be cautious when using this option - it will run Renovate over _every_ repositor

## exposeEnv

## force

This object is used as a "force override" when you need to make sure certain configuration overrides whatever is configured in the repository. For example, forcing a null (no) schedule to make sure Renovate raises PRs on a run even if the repository itself or its preset defines a schedule that's currently in active.

In practice, it is implemented by converting the `force` configuration into a `packageRule` that matches all packages.

## forceCli

This is set to true by default, meaning that any settings (such as `schedule`) take maximum priority even against custom settings existing inside individual repositories.

## forkMode

You probably have no need for this option - it is an experimental setting for the Renovate hosted GitHub App.
Expand Down