From 23d0290384b53fcb66a63cfd148f3fd1dd6c0a01 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 15 Mar 2018 07:06:18 +0100
Subject: [PATCH] fix: raise PR immediately if there are lock file errors
 (#1664)

fix: raise PR immediately if there are lock file errors
---
 lib/workers/pr/index.js       | 17 +++++++++++++++--
 test/workers/pr/index.spec.js |  8 ++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lib/workers/pr/index.js b/lib/workers/pr/index.js
index 33bc4afefc..e0025cbc0e 100644
--- a/lib/workers/pr/index.js
+++ b/lib/workers/pr/index.js
@@ -28,8 +28,17 @@ async function ensurePr(prConfig) {
     config.requiredStatusChecks
   );
 
+  if (config.lockFileErrors && config.lockFileErrors.length) {
+    logger.debug('Forcing PR because of lock file errors');
+    config.forcePr = true;
+  }
+
   // Only create a PR if a branch automerge has failed
-  if (config.automerge === true && config.automergeType.startsWith('branch')) {
+  if (
+    config.automerge === true &&
+    config.automergeType.startsWith('branch') &&
+    !config.forcePr
+  ) {
     logger.debug(
       `Branch is configured for branch automerge, branchStatus is: ${branchStatus}`
     );
@@ -59,7 +68,11 @@ async function ensurePr(prConfig) {
       return null;
     }
     logger.debug('Branch status success');
-  } else if (config.prCreation === 'not-pending' && !existingPr) {
+  } else if (
+    config.prCreation === 'not-pending' &&
+    !existingPr &&
+    !config.forcePr
+  ) {
     logger.debug('Checking branch combined status');
     if (branchStatus === 'pending' || branchStatus === 'running') {
       logger.debug(`Branch status is "${branchStatus}" - checking timeout`);
diff --git a/test/workers/pr/index.spec.js b/test/workers/pr/index.spec.js
index 7cc6320285..c321185e96 100644
--- a/test/workers/pr/index.spec.js
+++ b/test/workers/pr/index.spec.js
@@ -325,5 +325,13 @@ describe('workers/pr', () => {
       expect(platform.createPr.mock.calls[0]).toMatchSnapshot();
       existingPr.body = platform.createPr.mock.calls[0][2];
     });
+    it('should create PR if waiting for not pending but lockFileErrors', async () => {
+      platform.getBranchStatus.mockReturnValueOnce('pending');
+      platform.getBranchLastCommitTime.mockImplementationOnce(() => new Date());
+      config.prCreation = 'not-pending';
+      config.lockFileErrors = [{}];
+      const pr = await prWorker.ensurePr(config);
+      expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
+    });
   });
 });
-- 
GitLab