From 2ff90b23965fbed706529a6caae76e1bec0d8fe6 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 5 May 2020 19:46:35 +0200
Subject: [PATCH] fix: packageFiles per baseBranch (#6136)

---
 lib/workers/branch/index.ts                         | 13 ++++++-------
 lib/workers/common.ts                               |  2 ++
 lib/workers/repository/index.ts                     |  2 +-
 .../repository/process/extract-update.spec.ts       |  6 +++---
 lib/workers/repository/process/extract-update.ts    |  6 ++----
 lib/workers/repository/process/index.spec.ts        |  2 +-
 lib/workers/repository/process/index.ts             |  5 ++---
 lib/workers/repository/process/write.spec.ts        |  5 ++---
 lib/workers/repository/process/write.ts             |  6 +-----
 lib/workers/repository/updates/branchify.ts         |  1 +
 10 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts
index 12b80646b0..f85663bee0 100644
--- a/lib/workers/branch/index.ts
+++ b/lib/workers/branch/index.ts
@@ -22,10 +22,7 @@ import {
   PR_STATE_OPEN,
 } from '../../constants/pull-requests';
 import { logger } from '../../logger';
-import {
-  AdditionalPackageFiles,
-  getAdditionalFiles,
-} from '../../manager/npm/post-update';
+import { getAdditionalFiles } from '../../manager/npm/post-update';
 import { platform } from '../../platform';
 import { BranchStatus } from '../../types';
 import { emojify } from '../../util/emoji';
@@ -55,8 +52,7 @@ function rebaseCheck(config: RenovateConfig, branchPr: any): boolean {
 
 export async function processBranch(
   branchConfig: BranchConfig,
-  prHourlyLimitReached?: boolean,
-  packageFiles?: AdditionalPackageFiles
+  prHourlyLimitReached?: boolean
 ): Promise<ProcessBranchResult> {
   const config: BranchConfig = { ...branchConfig };
   const dependencies = config.upgrades
@@ -303,7 +299,10 @@ export async function processBranch(
     } else {
       logger.debug('No package files need updating');
     }
-    const additionalFiles = await getAdditionalFiles(config, packageFiles);
+    const additionalFiles = await getAdditionalFiles(
+      config,
+      branchConfig.packageFiles
+    );
     config.artifactErrors = (config.artifactErrors || []).concat(
       additionalFiles.artifactErrors
     );
diff --git a/lib/workers/common.ts b/lib/workers/common.ts
index 051c3b4721..53eec7aefa 100644
--- a/lib/workers/common.ts
+++ b/lib/workers/common.ts
@@ -10,6 +10,7 @@ import {
   ArtifactError,
   LookupUpdate,
   PackageDependency,
+  PackageFile,
 } from '../manager/common';
 import { File, PlatformPrOptions } from '../platform';
 import { ChangeLogResult } from './pr/changelog/common';
@@ -95,4 +96,5 @@ export interface BranchConfig
 
   res?: ProcessBranchResult;
   upgrades: BranchUpgradeConfig[];
+  packageFiles?: Record<string, PackageFile[]>;
 }
diff --git a/lib/workers/repository/index.ts b/lib/workers/repository/index.ts
index 2d4bfc3322..468da70d7f 100644
--- a/lib/workers/repository/index.ts
+++ b/lib/workers/repository/index.ts
@@ -33,7 +33,7 @@ export async function renovateRepository(
     config = await initRepo(config);
     const { branches, branchList, packageFiles } = await processRepo(config);
     await ensureOnboardingPr(config, packageFiles, branches);
-    const res = await updateRepo(config, branches, branchList, packageFiles);
+    const res = await updateRepo(config, branches, branchList);
     if (res !== 'automerged') {
       await ensureMasterIssue(config, branches);
     }
diff --git a/lib/workers/repository/process/extract-update.spec.ts b/lib/workers/repository/process/extract-update.spec.ts
index 02a007da87..a090e48360 100644
--- a/lib/workers/repository/process/extract-update.spec.ts
+++ b/lib/workers/repository/process/extract-update.spec.ts
@@ -11,8 +11,8 @@ jest.mock('../extract');
 const branchify = mocked(_branchify);
 
 branchify.branchifyUpgrades.mockResolvedValueOnce({
-  branches: [],
-  branchList: [],
+  branches: [{ branchName: 'some-branch', upgrades: [] }],
+  branchList: ['branchName'],
 });
 
 describe('workers/repository/process/extract-update', () => {
@@ -23,7 +23,7 @@ describe('workers/repository/process/extract-update', () => {
         suppressNotifications: ['deprecationWarningIssues'],
       };
       const res = await extract(config);
-      await update(config, res.branches, res.branchList, res.packageFiles);
+      await update(config, res.branches);
     });
   });
 });
diff --git a/lib/workers/repository/process/extract-update.ts b/lib/workers/repository/process/extract-update.ts
index b446cfc52e..0f5e45afad 100644
--- a/lib/workers/repository/process/extract-update.ts
+++ b/lib/workers/repository/process/extract-update.ts
@@ -64,14 +64,12 @@ export async function extract(config: RenovateConfig): Promise<ExtractResult> {
 
 export async function update(
   config: RenovateConfig,
-  branches: BranchConfig[],
-  branchList: string[],
-  packageFiles: Record<string, PackageFile[]>
+  branches: BranchConfig[]
 ): Promise<WriteUpdateResult | undefined> {
   let res: WriteUpdateResult | undefined;
   // istanbul ignore else
   if (config.repoIsOnboarded) {
-    res = await writeUpdates(config, packageFiles, branches);
+    res = await writeUpdates(config, branches);
   }
 
   return res;
diff --git a/lib/workers/repository/process/index.spec.ts b/lib/workers/repository/process/index.spec.ts
index 67a8045ed6..f89830223b 100644
--- a/lib/workers/repository/process/index.spec.ts
+++ b/lib/workers/repository/process/index.spec.ts
@@ -22,7 +22,7 @@ describe('workers/repository/process/index', () => {
       extract.mockResolvedValue({} as never);
       config.baseBranches = ['branch1', 'branch2'];
       const res = await processRepo(config);
-      await updateRepo(config, res.branches, res.branchList, res.packageFiles);
+      await updateRepo(config, res.branches, res.branchList);
       expect(res).toMatchSnapshot();
     });
   });
diff --git a/lib/workers/repository/process/index.ts b/lib/workers/repository/process/index.ts
index b28502d389..6b986d2e96 100644
--- a/lib/workers/repository/process/index.ts
+++ b/lib/workers/repository/process/index.ts
@@ -71,10 +71,9 @@ export async function processRepo(
 export async function updateRepo(
   config: RenovateConfig,
   branches: BranchConfig[],
-  branchList: string[],
-  packageFiles?: Record<string, PackageFile[]>
+  branchList: string[]
 ): Promise<WriteUpdateResult | undefined> {
   logger.debug('processRepo()');
 
-  return update(config, branches, branchList, packageFiles);
+  return update(config, branches);
 }
diff --git a/lib/workers/repository/process/write.spec.ts b/lib/workers/repository/process/write.spec.ts
index e80a5212cb..3fdb37d395 100644
--- a/lib/workers/repository/process/write.spec.ts
+++ b/lib/workers/repository/process/write.spec.ts
@@ -19,14 +19,13 @@ beforeEach(() => {
 
 describe('workers/repository/write', () => {
   describe('writeUpdates()', () => {
-    const packageFiles = {};
     it('skips branches blocked by pin', async () => {
       const branches: BranchConfig[] = [
         { updateType: 'pin' },
         { blockedByPin: true },
         {},
       ] as never;
-      const res = await writeUpdates(config, packageFiles, branches);
+      const res = await writeUpdates(config, branches);
       expect(res).toEqual('done');
       expect(branchWorker.processBranch).toHaveBeenCalledTimes(2);
     });
@@ -35,7 +34,7 @@ describe('workers/repository/write', () => {
       branchWorker.processBranch.mockResolvedValueOnce('pr-created');
       branchWorker.processBranch.mockResolvedValueOnce('already-existed');
       branchWorker.processBranch.mockResolvedValueOnce('automerged');
-      const res = await writeUpdates(config, packageFiles, branches);
+      const res = await writeUpdates(config, branches);
       expect(res).toEqual('automerged');
       expect(branchWorker.processBranch).toHaveBeenCalledTimes(3);
     });
diff --git a/lib/workers/repository/process/write.ts b/lib/workers/repository/process/write.ts
index 97ebdb9036..28d0af9826 100644
--- a/lib/workers/repository/process/write.ts
+++ b/lib/workers/repository/process/write.ts
@@ -1,7 +1,5 @@
 import { RenovateConfig } from '../../../config';
 import { addMeta, logger, removeMeta } from '../../../logger';
-import { PackageFile } from '../../../manager/common';
-import { AdditionalPackageFiles } from '../../../manager/npm/post-update';
 import { processBranch } from '../../branch';
 import { BranchConfig } from '../../common';
 import { getLimitRemaining } from '../../global/limits';
@@ -11,7 +9,6 @@ export type WriteUpdateResult = 'done' | 'automerged';
 
 export async function writeUpdates(
   config: RenovateConfig,
-  packageFiles: Record<string, PackageFile[]> | AdditionalPackageFiles,
   allBranches: BranchConfig[]
 ): Promise<WriteUpdateResult> {
   let branches = allBranches;
@@ -35,8 +32,7 @@ export async function writeUpdates(
     addMeta({ branch: branch.branchName });
     const res = await processBranch(
       branch,
-      prsRemaining <= 0 || getLimitRemaining('prCommitsPerRunLimit') <= 0,
-      packageFiles
+      prsRemaining <= 0 || getLimitRemaining('prCommitsPerRunLimit') <= 0
     );
     branch.res = res;
     if (res === 'automerged' && config.automergeType !== 'pr-comment') {
diff --git a/lib/workers/repository/updates/branchify.ts b/lib/workers/repository/updates/branchify.ts
index c7bdbc7e6e..06a302b97d 100644
--- a/lib/workers/repository/updates/branchify.ts
+++ b/lib/workers/repository/updates/branchify.ts
@@ -150,6 +150,7 @@ export async function branchifyUpgrades(
     );
     const branch = generateBranchConfig(branchUpgrades[branchName]);
     branch.branchName = branchName;
+    branch.packageFiles = packageFiles;
     branches.push(branch);
   }
   removeMeta(['branch']);
-- 
GitLab