renovate/lib/workers/repository/onboarding.js

69 lines
2.4 KiB
JavaScript

const stringify = require('json-stringify-pretty-compact');
const defaultsParser = require('../../config/defaults');
module.exports = {
onboardRepository,
getOnboardingStatus,
};
async function onboardRepository(config) {
const defaultConfig = defaultsParser.getOnboardingConfig();
const prBody = `Welcome to [Renovate](https://keylocation.sg/our-tech/renovate)! Once you close this Pull Request, we will begin keeping your dependencies up-to-date via automated Pull Requests.
The [Configuration](https://github.com/singapore/renovate/blob/master/docs/configuration.md) and [Configuration FAQ](https://github.com/singapore/renovate/blob/master/docs/faq.md) documents should be helpful.
#### Important!
You do not need to *merge* this Pull Request - renovate will begin even if it's closed *unmerged*.
In fact, you only need to add a \`renovate.json\` file to your repository if you wish to override any default settings. The file is included as part of this PR only in case you wish to change default settings before you start.
If the default settings are all suitable for you, simply close this Pull Request unmerged and your first renovation will begin the next time the program is run.`;
const defaultConfigString = `${stringify(defaultConfig)}\n`;
await config.api.commitFilesToBranch(
'renovate/configure',
[
{
name: 'renovate.json',
contents: defaultConfigString,
},
],
'Add renovate.json'
);
const pr = await config.api.createPr(
'renovate/configure',
'Configure Renovate',
prBody
);
config.logger.debug(`Created ${pr.displayNumber} for configuration`);
}
async function getOnboardingStatus(config) {
config.logger.debug('Checking if repo is configured');
// Check if repository is configured
if (config.onboarding === false) {
config.logger.debug('Repo onboarding is disabled');
return true;
}
if (config.renovateJsonPresent) {
config.logger.debug('Repo onboarded');
return true;
}
const pr = await config.api.findPr(
'renovate/configure',
'Configure Renovate'
);
if (pr) {
if (pr.isClosed) {
config.logger.debug('Found closed Configure Renovate PR');
return true;
}
// PR exists but hasn't been closed yet
config.logger.debug(
`PR #${pr.displayNumber} needs to be closed to enable renovate to continue`
);
return false;
}
await module.exports.onboardRepository(config);
return false;
}