From 285c977cf7dbb14729163d25c0ee26c94a11ddfc Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Wed, 28 Jun 2017 12:16:25 +0200 Subject: [PATCH] Use package.json renovate config when onboarding (#370) * Store repoIsOnboarded in config * Use package file renovate config for onboarding Closes #368 --- lib/workers/package-file/index.js | 7 ++++++- lib/workers/repository/index.js | 6 +++--- lib/workers/repository/onboarding.js | 1 + test/workers/package-file/index.spec.js | 12 ++++++++++++ .../repository/__snapshots__/onboarding.spec.js.snap | 2 ++ test/workers/repository/onboarding.spec.js | 1 + 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/workers/package-file/index.js b/lib/workers/package-file/index.js index ff27680413..8df9fb6e63 100644 --- a/lib/workers/package-file/index.js +++ b/lib/workers/package-file/index.js @@ -10,7 +10,12 @@ module.exports = { async function findUpgrades(config) { logger = config.logger || logger; logger.info(`Processing package file`); - const packageContent = await config.api.getFileJson(config.packageFile); + // If onboarding, use the package.json in onboarding branch + const branchName = config.repoIsOnboarded ? null : 'renovate/configure'; + const packageContent = await config.api.getFileJson( + config.packageFile, + branchName + ); if (!packageContent) { logger.warn('No package.json content found - skipping'); diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js index 82b8a3b84e..e9644b614e 100644 --- a/lib/workers/repository/index.js +++ b/lib/workers/repository/index.js @@ -15,8 +15,8 @@ async function renovateRepository(packageFileConfig) { try { config = await apis.initApis(config); config = await apis.mergeRenovateJson(config); - const repoIsOnboarded = await onboarding.getOnboardingStatus(config); - if (!repoIsOnboarded) { + config.repoIsOnboarded = await onboarding.getOnboardingStatus(config); + if (!config.repoIsOnboarded) { config = await apis.mergeRenovateJson(config, 'renovate/configure'); } const hasConfiguredPackageFiles = config.packageFiles.length > 0; @@ -35,7 +35,7 @@ async function renovateRepository(packageFileConfig) { config.logger.debug( `Updating ${Object.keys(branchUpgrades).length} branch(es)` ); - if (repoIsOnboarded) { + if (config.repoIsOnboarded) { for (const branchName of Object.keys(branchUpgrades)) { await branchWorker.updateBranch(branchUpgrades[branchName]); } diff --git a/lib/workers/repository/onboarding.js b/lib/workers/repository/onboarding.js index da6be62894..67ee579f20 100644 --- a/lib/workers/repository/onboarding.js +++ b/lib/workers/repository/onboarding.js @@ -32,6 +32,7 @@ async function ensurePr(config, branchUpgrades) { let prBody = `Welcome to [Renovate](https://keylocation.sg/our-tech/renovate)! This is an onboarding PR to help you understand and configure Renovate before any changes are made to any \`package.json\` files. Once you close this Pull Request, we will begin keeping your dependencies up-to-date via automated Pull Requests. + --- {{PRDESCRIPTION}} diff --git a/test/workers/package-file/index.spec.js b/test/workers/package-file/index.spec.js index 231e52fe51..1de452a443 100644 --- a/test/workers/package-file/index.spec.js +++ b/test/workers/package-file/index.spec.js @@ -8,6 +8,7 @@ describe('packageFileWorker', () => { let config; beforeEach(() => { config = { + repoIsOnboarded: true, api: { getFileJson: jest.fn(), }, @@ -23,6 +24,17 @@ describe('packageFileWorker', () => { config.enabled = false; config.api.getFileJson.mockReturnValueOnce({}); const res = await packageFileWorker.findUpgrades(config); + expect(config.api.getFileJson.mock.calls[0][1]).toBe(null); + expect(res).toEqual([]); + }); + it('uses onboarding branch', async () => { + config.enabled = false; + config.repoIsOnboarded = false; + config.api.getFileJson.mockReturnValueOnce({}); + const res = await packageFileWorker.findUpgrades(config); + expect(config.api.getFileJson.mock.calls[0][1]).toEqual( + 'renovate/configure' + ); expect(res).toEqual([]); }); it('returns empty array if config disabled', async () => { diff --git a/test/workers/repository/__snapshots__/onboarding.spec.js.snap b/test/workers/repository/__snapshots__/onboarding.spec.js.snap index 9e171f0f9b..0c471d7f38 100644 --- a/test/workers/repository/__snapshots__/onboarding.spec.js.snap +++ b/test/workers/repository/__snapshots__/onboarding.spec.js.snap @@ -8,6 +8,7 @@ Array [ "Welcome to [Renovate](https://keylocation.sg/our-tech/renovate)! This is an onboarding PR to help you understand and configure Renovate before any changes are made to any \`package.json\` files. Once you close this Pull Request, we will begin keeping your dependencies up-to-date via automated Pull Requests. + --- @@ -46,6 +47,7 @@ Array [ "Welcome to [Renovate](https://keylocation.sg/our-tech/renovate)! This is an onboarding PR to help you understand and configure Renovate before any changes are made to any \`package.json\` files. Once you close this Pull Request, we will begin keeping your dependencies up-to-date via automated Pull Requests. + --- It looks like your repository dependencies are already up-to-date and no initial Pull Requests will be necessary. diff --git a/test/workers/repository/onboarding.spec.js b/test/workers/repository/onboarding.spec.js index ee0f2865cd..1b3868cb27 100644 --- a/test/workers/repository/onboarding.spec.js +++ b/test/workers/repository/onboarding.spec.js @@ -30,6 +30,7 @@ describe('lib/workers/repository/onboarding', () => { const existingPrBody = `Welcome to [Renovate](https://keylocation.sg/our-tech/renovate)! This is an onboarding PR to help you understand and configure Renovate before any changes are made to any \`package.json\` files. Once you close this Pull Request, we will begin keeping your dependencies up-to-date via automated Pull Requests. + --- It looks like your repository dependencies are already up-to-date and no initial Pull Requests will be necessary. -- GitLab