diff --git a/docs/configuration.md b/docs/configuration.md index c5fcd1bd06b62d33ae58df2cef9234c0ae3fa0fb..4ead02823729fd31299434937285fa7282eeb9fe 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -6,10 +6,11 @@ Configuration is supported via any or all of the below: - Configuration file - Environment - CLI -- `package.json` of target repository +- `renovate.json` in target repository +- `renovate` field of `package.json` in target repository The above are listed in reverse order of preference. -i.e. `package.json` options will override, CLI, which overrides env, which overrides the config file, which overrides defaults. +i.e. `package.json` settings will override `renovate.json` settings, CLI, which overrides env, which overrides the config file, which overrides defaults. ### Default Configuration @@ -75,6 +76,11 @@ $ node renovate --help $ renovate singapore/lint-condo singapore/package-test ``` +### renovate.json + +If you add a `renovate.json` file to the root of your repository, you can use this to override default settings. +If you leave the `packageFiles` field empty then `renovate` will still auto-discover all `package.json` files in the repository. + ### package.json If you add configuration options to your `package.json` then these will override any other settings above. diff --git a/lib/api/github.js b/lib/api/github.js index f8df50dff5b6407530fcb5bebf7e9af79e079d81..01f52e506acca45439e70534be03a8956acd1c61 100644 --- a/lib/api/github.js +++ b/lib/api/github.js @@ -20,7 +20,7 @@ module.exports = { updatePr, // file getFile, - getFileContents, + getFileJson, writeFile, }; @@ -146,9 +146,17 @@ function getFile(filePath, branchName = config.defaultBranch) { return ghGot(`repos/${config.repoName}/contents/${filePath}?ref=${branchName}`); } -function getFileContents(filePath, branchName) { +function getFileJson(filePath, branchName = config.baseBranch) { return getFile(filePath, branchName) - .then(res => JSON.parse(new Buffer(res.body.content, 'base64').toString())); + .then(res => JSON.parse(new Buffer(res.body.content, 'base64').toString())) + .catch((error) => { + if (error.statusCode === 404) { + // If file not found, then return null JSON + return null; + } + // Propagate if it's any other error + throw error; + }); } function writeFile(branchName, oldFileSHA, filePath, fileContents, message) { diff --git a/lib/index.js b/lib/index.js index f2202a89f7dc49447db5886d24852aaa8721238d..003968ed162ec7af9aedce6e8cbc6ac86c828f8a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,4 @@ +const stringify = require('json-stringify-pretty-compact'); const logger = require('./logger'); const config = require('./config'); const github = require('./api/github'); @@ -31,10 +32,24 @@ function start() { process.env.GITHUB_TOKEN = repo.token || globalConfig.token; // Initialize repo return github.initRepo(repo.repository) - .then(() => ensurePackageFiles(repo)) + .then(() => checkForRenovateJson(repo)) + .then(ensurePackageFiles) .then(getWorkers); } + // Check for config in `renovate.json` + function checkForRenovateJson(repo) { + return github.getFileJson('renovate.json') + .then((contents) => { + if (!contents) { + logger.debug('No renovate.json found'); + return repo; + } + logger.debug(`renovate.json config: ${stringify(contents)}`); + return Object.assign(repo, contents); + }); + } + // Ensure repo contains packageFiles function ensurePackageFiles(repo) { // Check for manually configured package files diff --git a/lib/worker.js b/lib/worker.js index d4e14e847e7b1beffcd8e8114f857af1afa68da2..ecaba9a8af197e08b3e38d735eb813a0af929023 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -1,5 +1,6 @@ const logger = require('winston'); const changelog = require('changelog'); +const stringify = require('json-stringify-pretty-compact'); const github = require('./api/github'); const handlebars = require('./helpers/handlebars'); const versionsHelper = require('./helpers/versions'); @@ -19,7 +20,7 @@ function renovate(repoName, packageFile, setConfig) { logger.info(`Processing ${repoName} ${packageFile}`); // Start the chain - return github.getFileContents(packageFile) + return github.getFileJson(packageFile) .then(checkforRenovateConfig) .then(contents => packageJson.extractDependencies(contents, config.depTypes)) .then(filterIgnoredDependencies) @@ -35,7 +36,7 @@ function renovate(repoName, packageFile, setConfig) { function checkforRenovateConfig(packageContent) { if (packageContent.renovate) { - logger.debug('Found renovate configuration in package file'); + logger.debug(`package.json>renovate config: ${stringify(packageContent.renovate)}`); Object.assign(config, packageContent.renovate); logger.debug(`Updated config: ${JSON.stringify(config)}`); }