From fe2e612a093fe70d1621ecdc4d6241b67f598b24 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 18 May 2020 21:37:47 +0200
Subject: [PATCH] fix: branch writer use branch config, not main config

---
 lib/workers/repository/process/write.spec.ts | 11 +++++++++--
 lib/workers/repository/process/write.ts      |  6 +++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/workers/repository/process/write.spec.ts b/lib/workers/repository/process/write.spec.ts
index 3fdb37d395..f6c85a32bc 100644
--- a/lib/workers/repository/process/write.spec.ts
+++ b/lib/workers/repository/process/write.spec.ts
@@ -30,13 +30,20 @@ describe('workers/repository/write', () => {
       expect(branchWorker.processBranch).toHaveBeenCalledTimes(2);
     });
     it('stops after automerge', async () => {
-      const branches: BranchConfig[] = [{}, {}, {}, {}] as never;
+      const branches: BranchConfig[] = [
+        {},
+        {},
+        { automergeType: 'pr-comment', requiredStatusChecks: null },
+        {},
+        {},
+      ] as never;
       branchWorker.processBranch.mockResolvedValueOnce('pr-created');
       branchWorker.processBranch.mockResolvedValueOnce('already-existed');
       branchWorker.processBranch.mockResolvedValueOnce('automerged');
+      branchWorker.processBranch.mockResolvedValueOnce('automerged');
       const res = await writeUpdates(config, branches);
       expect(res).toEqual('automerged');
-      expect(branchWorker.processBranch).toHaveBeenCalledTimes(3);
+      expect(branchWorker.processBranch).toHaveBeenCalledTimes(4);
     });
   });
 });
diff --git a/lib/workers/repository/process/write.ts b/lib/workers/repository/process/write.ts
index cc41caa8e3..432b3b6cab 100644
--- a/lib/workers/repository/process/write.ts
+++ b/lib/workers/repository/process/write.ts
@@ -36,7 +36,7 @@ export async function writeUpdates(
       prsRemaining <= 0 || getLimitRemaining('prCommitsPerRunLimit') <= 0
     );
     branch.res = res;
-    if (res === 'automerged' && config.automergeType !== 'pr-comment') {
+    if (res === 'automerged' && branch.automergeType !== 'pr-comment') {
       // Stop procesing other branches because base branch has been changed
       return res;
     }
@@ -47,8 +47,8 @@ export async function writeUpdates(
     // istanbul ignore if
     if (
       res === 'automerged' &&
-      config.automergeType === 'pr-comment' &&
-      config.requiredStatusChecks === null
+      branch.automergeType === 'pr-comment' &&
+      branch.requiredStatusChecks === null
     ) {
       deductPrRemainingCount = 1;
     }
-- 
GitLab