From 3428b4b183473ac0a55f0501f7cde6aabcaa62e2 Mon Sep 17 00:00:00 2001
From: Guillaume Dedrie <guillaumededrie@users.noreply.github.com>
Date: Wed, 7 Nov 2018 13:17:32 +0100
Subject: [PATCH] fix(gitlab): getPrFiles throw `TypeError: files.map is not a
 function`. (#2761)

In `getPrFiles` function, when requesting MR changes to GitLab API
(in order to return files modified by the MR), we should iterate over
`changes` property in the HTTP body response, and return `new_path` as
the filename.
See: https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr-changes
---
 lib/platform/gitlab/index.js       |  4 ++--
 test/platform/gitlab/index.spec.js | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js
index 2cb7f7e945..91ada455bd 100644
--- a/lib/platform/gitlab/index.js
+++ b/lib/platform/gitlab/index.js
@@ -718,8 +718,8 @@ async function getPrFiles(mrNo) {
   }
   const files = (await get(
     `projects/${config.repository}/merge_requests/${mrNo}/changes`
-  )).body;
-  return files.map(f => f.filename);
+  )).body.changes;
+  return files.map(f => f.new_path);
 }
 
 // istanbul ignore next
diff --git a/test/platform/gitlab/index.spec.js b/test/platform/gitlab/index.spec.js
index 25c55c2b9e..4fc3658727 100644
--- a/test/platform/gitlab/index.spec.js
+++ b/test/platform/gitlab/index.spec.js
@@ -870,10 +870,12 @@ describe('platform/gitlab', () => {
     });
     it('returns files', async () => {
       get.mockReturnValueOnce({
-        body: [
-          { filename: 'renovate.json' },
-          { filename: 'not renovate.json' },
-        ],
+        body: {
+          changes: [
+            { new_path: 'renovate.json' },
+            { new_path: 'not renovate.json' },
+          ],
+        },
       });
       const prFiles = await gitlab.getPrFiles(123);
       expect(prFiles).toMatchSnapshot();
-- 
GitLab