From bc074aff02b2ebb1fe7e5a8d6e8b8bcf27eff00a Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 16 Aug 2018 12:15:56 +0200
Subject: [PATCH] fix: check PR is closed when finding blocking PR

Closes #2391
---
 lib/workers/branch/check-existing.js       | 6 ++++++
 test/workers/branch/check-existing.spec.js | 1 +
 2 files changed, 7 insertions(+)

diff --git a/lib/workers/branch/check-existing.js b/lib/workers/branch/check-existing.js
index c5b8ad9116..144525d611 100644
--- a/lib/workers/branch/check-existing.js
+++ b/lib/workers/branch/check-existing.js
@@ -13,6 +13,12 @@ async function prAlreadyExisted(config) {
   const pr = await platform.findPr(config.branchName, config.prTitle, '!open');
   if (pr) {
     logger.debug('Found closed PR with current title');
+    const prDetails = await platform.getPr(pr.number);
+    // istanbul ignore if
+    if (prDetails.state === 'open') {
+      logger.debug('PR reopened');
+      throw new Error('repository-changed');
+    }
     return pr;
   }
   logger.debug('prAlreadyExisted=false');
diff --git a/test/workers/branch/check-existing.spec.js b/test/workers/branch/check-existing.spec.js
index 4cc88374a3..675f17dae0 100644
--- a/test/workers/branch/check-existing.spec.js
+++ b/test/workers/branch/check-existing.spec.js
@@ -26,6 +26,7 @@ describe('workers/branch/check-existing', () => {
     });
     it('returns true if first check hits', async () => {
       platform.findPr.mockReturnValueOnce({ number: 12 });
+      platform.getPr.mockReturnValueOnce({ number: 12, state: 'closed' });
       expect(await prAlreadyExisted(config)).toEqual({ number: 12 });
       expect(platform.findPr.mock.calls.length).toBe(1);
     });
-- 
GitLab