From 6ef61c8608c592ed8737cb06b07c261a1e7034c2 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sun, 16 Dec 2018 17:18:00 +0100
Subject: [PATCH] Revert "feat: ensureIssue once"

This reverts commit 3988fb808af3103fbf34471f73f8a1ab876c62e0.
---
 lib/platform/github/index.js                  | 26 ++++------
 lib/workers/repository/process/deprecated.js  |  3 +-
 test/platform/github/index.spec.js            | 49 -------------------
 .../__snapshots__/deprecated.spec.js.snap     |  1 -
 4 files changed, 10 insertions(+), 69 deletions(-)

diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js
index f4992d4030..04dd8c6600 100644
--- a/lib/platform/github/index.js
+++ b/lib/platform/github/index.js
@@ -602,8 +602,8 @@ async function getIssueList() {
     logger.debug('Retrieving issueList');
     const res = await get(
       `repos/${config.parentRepo ||
-        config.repository}/issues?filter=created&state=all&per_page=100&sort=updated`,
-      { paginate: true, useCache: false }
+        config.repository}/issues?filter=created&state=open&per_page=100&sort=updated`,
+      { useCache: false }
     );
     // istanbul ignore if
     if (!is.array(res.body)) {
@@ -612,7 +612,6 @@ async function getIssueList() {
     }
     config.issueList = res.body.map(i => ({
       number: i.number,
-      state: i.state,
       title: i.title,
     }));
     logger.debug('Retrieved ' + config.issueList.length + ' issues');
@@ -623,9 +622,7 @@ async function getIssueList() {
 async function findIssue(title) {
   logger.debug(`findIssue(${title})`);
   try {
-    const [issue] = (await getIssueList()).filter(
-      i => i.state === 'open' && i.title === title
-    );
+    const [issue] = (await getIssueList()).filter(i => i.title === title);
     if (!issue) {
       return null;
     }
@@ -643,25 +640,20 @@ async function findIssue(title) {
   }
 }
 
-async function ensureIssue(title, body, once = false) {
+async function ensureIssue(title, body) {
   logger.debug(`ensureIssue()`);
   try {
     const issueList = await getIssueList();
     const issues = issueList.filter(i => i.title === title).reverse();
     if (issues.length) {
       if (issues.length > 1) {
+        logger.warn('Found duplicate issues');
         for (const issue of issues.slice(1)) {
-          if (issue.state === 'open') {
-            logger.warn('Closing duplicate issue ' + issue.number);
-            await closeIssue(issue.number);
-          }
+          logger.debug('Closing duplicate issue ' + issue.number);
+          await closeIssue(issue.number);
         }
       }
       const [issue] = issues;
-      if (once && issue.state === 'closed') {
-        logger.debug('Issue is closed - skipping');
-        return null;
-      }
       const issueBody = (await get(
         `repos/${config.parentRepo || config.repository}/issues/${issue.number}`
       )).body.body;
@@ -678,13 +670,13 @@ async function ensureIssue(title, body, once = false) {
         return 'updated';
       }
     } else {
+      logger.info('Issue created');
       await get.post(`repos/${config.parentRepo || config.repository}/issues`, {
         body: {
           title,
           body,
         },
       });
-      logger.info('Issue created');
       // reset issueList so that it will be fetched again as-needed
       delete config.issueList;
       return 'created';
@@ -715,7 +707,7 @@ async function ensureIssueClosing(title) {
   logger.debug(`ensureIssueClosing()`);
   const issueList = await getIssueList();
   for (const issue of issueList) {
-    if (issue.state === 'open' && issue.title === title) {
+    if (issue.title === title) {
       await closeIssue(issue.number);
       logger.info({ number: issue.number }, 'Issue closed');
     }
diff --git a/lib/workers/repository/process/deprecated.js b/lib/workers/repository/process/deprecated.js
index 67fe038026..2891c7401d 100644
--- a/lib/workers/repository/process/deprecated.js
+++ b/lib/workers/repository/process/deprecated.js
@@ -49,8 +49,7 @@ async function raiseDeprecationWarnings(config, packageFiles) {
       if (config.dryRun) {
         logger.info('DRY-RUN: Ensure deprecation warning issue for ' + depName);
       } else {
-        const ensureOnce = true;
-        await platform.ensureIssue(issueTitle, issueBody, ensureOnce);
+        await platform.ensureIssue(issueTitle, issueBody);
       }
     }
   }
diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js
index 9545da9b62..94495a99a7 100644
--- a/test/platform/github/index.spec.js
+++ b/test/platform/github/index.spec.js
@@ -1007,12 +1007,10 @@ describe('platform/github', () => {
           {
             number: 1,
             title: 'title-1',
-            state: 'open',
           },
           {
             number: 2,
             title: 'title-2',
-            state: 'open',
           },
         ],
       });
@@ -1028,67 +1026,26 @@ describe('platform/github', () => {
           {
             number: 1,
             title: 'title-1',
-            state: 'open',
           },
           {
             number: 2,
             title: 'title-2',
-            state: 'open',
           },
         ],
       }));
       const res = await github.ensureIssue('new-title', 'new-content');
       expect(res).toEqual('created');
     });
-    it('creates issue if not ensuring only once', async () => {
-      get.mockImplementationOnce(() => ({
-        body: [
-          {
-            number: 1,
-            title: 'title-1',
-            state: 'closed',
-          },
-          {
-            number: 2,
-            title: 'title-2',
-            state: 'open',
-          },
-        ],
-      }));
-      const res = await github.ensureIssue('title-1', 'new-content');
-      expect(res).toEqual(null);
-    });
-    it('does not create issue if ensuring only once', async () => {
-      get.mockImplementationOnce(() => ({
-        body: [
-          {
-            number: 1,
-            title: 'title-1',
-            state: 'closed',
-          },
-          {
-            number: 2,
-            title: 'title-2',
-            state: 'open',
-          },
-        ],
-      }));
-      const once = true;
-      const res = await github.ensureIssue('title-1', 'new-content', once);
-      expect(res).toEqual(null);
-    });
     it('updates issue', async () => {
       get.mockReturnValueOnce({
         body: [
           {
             number: 1,
             title: 'title-1',
-            state: 'open',
           },
           {
             number: 2,
             title: 'title-2',
-            state: 'open',
           },
         ],
       });
@@ -1102,12 +1059,10 @@ describe('platform/github', () => {
           {
             number: 1,
             title: 'title-1',
-            state: 'open',
           },
           {
             number: 2,
             title: 'title-2',
-            state: 'open',
           },
         ],
       });
@@ -1121,12 +1076,10 @@ describe('platform/github', () => {
           {
             number: 1,
             title: 'title-1',
-            state: 'open',
           },
           {
             number: 2,
             title: 'title-1',
-            state: 'open',
           },
         ],
       });
@@ -1142,12 +1095,10 @@ describe('platform/github', () => {
           {
             number: 1,
             title: 'title-1',
-            state: 'open',
           },
           {
             number: 2,
             title: 'title-2',
-            state: 'open',
           },
         ],
       }));
diff --git a/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap b/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap
index 9c947fce9b..ab0d3eaae9 100644
--- a/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap
+++ b/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap
@@ -15,7 +15,6 @@ If you don't care about this, you can close this issue and not be warned about \
 \`\`\`
 
 ",
-    true,
   ],
 ]
 `;
-- 
GitLab