refactor: pass branches explicitly to repo onboarding

This commit is contained in:
Rhys Arkins 2018-05-07 07:02:08 +02:00
parent 7189f4682f
commit 4a4feb35ab
5 changed files with 18 additions and 14 deletions

View file

@ -71,7 +71,7 @@ async function renovateRepository(repoConfig) {
});
res = config.repoIsOnboarded
? await writeUpdates(config)
: await ensureOnboardingPr(config);
: await ensureOnboardingPr(config, config.branches);
logger.setMeta({ repository: config.repository });
config.branchPrefix = commonConfig
? commonConfig.branchPrefix

View file

@ -3,8 +3,11 @@ const { getErrors, getWarnings } = require('./errors-warnings');
const { getBaseBranchDesc } = require('./base-branch');
const { getPrList } = require('./pr-list');
async function ensureOnboardingPr(config) {
async function ensureOnboardingPr(config, branches) {
logger.debug('ensureOnboardingPr()');
if (config.repoIsOnboarded) {
return null;
}
logger.trace({ config });
const onboardingBranch = `renovate/configure`;
const onboardingPrTitle = 'Configure Renovate';
@ -41,7 +44,7 @@ You can post questions in [our Config Help repository](https://github.com/renova
prBody = prBody.replace('{{WARNINGS}}\n', getWarnings(config));
prBody = prBody.replace('{{ERRORS}}\n', getErrors(config));
prBody = prBody.replace('{{BASEBRANCH}}\n', getBaseBranchDesc(config));
prBody = prBody.replace('{{PRLIST}}\n', getPrList(config));
prBody = prBody.replace('{{PRLIST}}\n', getPrList(config, branches));
// istanbul ignore if
if (config.global) {
if (config.global.prBanner) {

View file

@ -1,5 +1,4 @@
function getPrList(config) {
const { branches } = config;
function getPrList(config, branches) {
logger.debug('getPrList()');
logger.trace({ config });
let prDesc = `\n### What to Expect\n\n`;

View file

@ -11,18 +11,20 @@ describe('workers/repository/onboarding/pr', () => {
jest.resetAllMocks();
config = {
...defaultConfig,
errors: [],
warnings: [],
description: [],
branches: [],
packageFiles: [{ packageFile: 'package.json' }],
};
platform.createPr.mockReturnValue({});
});
let createPrBody;
it('returns if onboarded', async () => {
config.repoIsOnboarded = true;
expect(await ensureOnboardingPr(config, [])).toBe(null);
});
it('creates PR', async () => {
await ensureOnboardingPr(config);
await ensureOnboardingPr(config, []);
expect(platform.createPr.mock.calls).toHaveLength(1);
createPrBody = platform.createPr.mock.calls[0][2];
});
@ -31,7 +33,7 @@ describe('workers/repository/onboarding/pr', () => {
title: 'Configure Renovate',
body: createPrBody,
});
await ensureOnboardingPr(config);
await ensureOnboardingPr(config, []);
expect(platform.createPr.mock.calls).toHaveLength(0);
expect(platform.updatePr.mock.calls).toHaveLength(0);
});
@ -41,7 +43,7 @@ describe('workers/repository/onboarding/pr', () => {
title: 'Configure Renovate',
body: createPrBody,
});
await ensureOnboardingPr(config);
await ensureOnboardingPr(config, []);
expect(platform.createPr.mock.calls).toHaveLength(0);
expect(platform.updatePr.mock.calls).toHaveLength(1);
});

View file

@ -14,7 +14,7 @@ describe('workers/repository/onboarding/pr/pr-list', () => {
};
});
it('has special lock file maintenance description', () => {
config.branches = [
const branches = [
{
prTitle: 'Lock file maintenance',
schedule: ['before 5am'],
@ -26,11 +26,11 @@ describe('workers/repository/onboarding/pr/pr-list', () => {
],
},
];
const res = getPrList(config);
const res = getPrList(config, branches);
expect(res).toMatchSnapshot();
});
it('handles multiple', () => {
config.branches = [
const branches = [
{
prTitle: 'Pin dependencies',
branchName: 'renovate/pin-dependencies',
@ -63,7 +63,7 @@ describe('workers/repository/onboarding/pr/pr-list', () => {
],
},
];
const res = getPrList(config);
const res = getPrList(config, branches);
expect(res).toMatchSnapshot();
});
});