From 49447989e1f67cd645ca8616d1594bdef13ead50 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sat, 27 Jun 2020 09:55:02 +0200
Subject: [PATCH] fix(gitlab): fetch all open issues (#6597)

---
 .../gitlab/__snapshots__/index.spec.ts.snap   | 12 +++++-----
 lib/platform/gitlab/index.spec.ts             | 24 ++++++++++++++-----
 lib/platform/gitlab/index.ts                  |  8 ++++++-
 3 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
index 0fb8a41deb..5945db02f7 100644
--- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
+++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap
@@ -714,7 +714,7 @@ Array [
       "user-agent": "https://github.com/renovatebot/renovate",
     },
     "method": "GET",
-    "url": "https://gitlab.com/api/v4/projects/undefined/issues?state=opened",
+    "url": "https://gitlab.com/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened",
   },
   Object {
     "body": "{\\"title\\":\\"new-title\\",\\"description\\":\\"new-content\\"}",
@@ -744,7 +744,7 @@ Array [
       "user-agent": "https://github.com/renovatebot/renovate",
     },
     "method": "GET",
-    "url": "https://gitlab.com/api/v4/projects/undefined/issues?state=opened",
+    "url": "https://gitlab.com/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened",
   },
   Object {
     "headers": Object {
@@ -771,7 +771,7 @@ Array [
       "user-agent": "https://github.com/renovatebot/renovate",
     },
     "method": "GET",
-    "url": "https://gitlab.com/api/v4/projects/undefined/issues?state=opened",
+    "url": "https://gitlab.com/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened",
   },
   Object {
     "headers": Object {
@@ -812,7 +812,7 @@ Array [
       "user-agent": "https://github.com/renovatebot/renovate",
     },
     "method": "GET",
-    "url": "https://gitlab.com/api/v4/projects/undefined/issues?state=opened",
+    "url": "https://gitlab.com/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened",
   },
   Object {
     "body": "{\\"state_event\\":\\"close\\"}",
@@ -842,7 +842,7 @@ Array [
       "user-agent": "https://github.com/renovatebot/renovate",
     },
     "method": "GET",
-    "url": "https://gitlab.com/api/v4/projects/undefined/issues?state=opened",
+    "url": "https://gitlab.com/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened",
   },
   Object {
     "headers": Object {
@@ -869,7 +869,7 @@ Array [
       "user-agent": "https://github.com/renovatebot/renovate",
     },
     "method": "GET",
-    "url": "https://gitlab.com/api/v4/projects/undefined/issues?state=opened",
+    "url": "https://gitlab.com/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened",
   },
 ]
 `;
diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts
index 209d621031..4fdfdf8cd0 100644
--- a/lib/platform/gitlab/index.spec.ts
+++ b/lib/platform/gitlab/index.spec.ts
@@ -712,7 +712,9 @@ describe('platform/gitlab', () => {
     it('returns null if no issue', async () => {
       httpMock
         .scope(gitlabApiHost)
-        .get('/api/v4/projects/undefined/issues?state=opened')
+        .get(
+          '/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened'
+        )
         .reply(200, [
           {
             iid: 1,
@@ -730,7 +732,9 @@ describe('platform/gitlab', () => {
     it('finds issue', async () => {
       httpMock
         .scope(gitlabApiHost)
-        .get('/api/v4/projects/undefined/issues?state=opened')
+        .get(
+          '/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened'
+        )
         .reply(200, [
           {
             iid: 1,
@@ -752,7 +756,9 @@ describe('platform/gitlab', () => {
     it('creates issue', async () => {
       httpMock
         .scope(gitlabApiHost)
-        .get('/api/v4/projects/undefined/issues?state=opened')
+        .get(
+          '/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened'
+        )
         .reply(200, [
           {
             iid: 1,
@@ -775,7 +781,9 @@ describe('platform/gitlab', () => {
     it('updates issue', async () => {
       httpMock
         .scope(gitlabApiHost)
-        .get('/api/v4/projects/undefined/issues?state=opened')
+        .get(
+          '/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened'
+        )
         .reply(200, [
           {
             iid: 1,
@@ -800,7 +808,9 @@ describe('platform/gitlab', () => {
     it('skips update if unchanged', async () => {
       httpMock
         .scope(gitlabApiHost)
-        .get('/api/v4/projects/undefined/issues?state=opened')
+        .get(
+          '/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened'
+        )
         .reply(200, [
           {
             iid: 1,
@@ -825,7 +835,9 @@ describe('platform/gitlab', () => {
     it('closes issue', async () => {
       httpMock
         .scope(gitlabApiHost)
-        .get('/api/v4/projects/undefined/issues?state=opened')
+        .get(
+          '/api/v4/projects/undefined/issues?per_page=100&author_id=undefined&state=opened'
+        )
         .reply(200, [
           {
             iid: 1,
diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts
index 02e3fbf2a4..e7e5b37a40 100644
--- a/lib/platform/gitlab/index.ts
+++ b/lib/platform/gitlab/index.ts
@@ -742,10 +742,16 @@ export async function setBranchStatus({
 
 export async function getIssueList(): Promise<any[]> {
   if (!config.issueList) {
+    const query = new URLSearchParams({
+      per_page: '100',
+      author_id: `${authorId}`,
+      state: 'opened',
+    }).toString();
     const res = await gitlabApi.getJson<{ iid: number; title: string }[]>(
-      `projects/${config.repository}/issues?state=opened`,
+      `projects/${config.repository}/issues?${query}`,
       {
         useCache: false,
+        paginate: true,
       }
     );
     // istanbul ignore if
-- 
GitLab