From 4104e810050313887d23172d95d2bcfb84f26f6f Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 6 Mar 2018 12:18:35 +0100
Subject: [PATCH] Revert "chore: remove unused getPrFiles functions"

This reverts commit d5984a3cadab84fd9a3b62b09695a59ade99dc7f.
---
 lib/platform/github/index.js                    | 13 +++++++++++++
 lib/platform/gitlab/index.js                    |  6 ++++++
 lib/platform/vsts/index.js                      |  7 +++++++
 test/platform/__snapshots__/index.spec.js.snap  |  3 +++
 .../github/__snapshots__/index.spec.js.snap     |  7 +++++++
 test/platform/github/index.spec.js              | 17 +++++++++++++++++
 test/platform/gitlab/index.spec.js              |  6 ++++++
 test/platform/vsts/index.spec.js                |  6 ++++++
 8 files changed, 65 insertions(+)

diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js
index 19594b2610..b23555415c 100644
--- a/lib/platform/github/index.js
+++ b/lib/platform/github/index.js
@@ -39,6 +39,7 @@ module.exports = {
   findPr,
   createPr,
   getPr,
+  getPrFiles,
   updatePr,
   mergePr,
   // file
@@ -830,6 +831,18 @@ async function getPr(prNo) {
   return pr;
 }
 
+// Return a list of all modified files in a PR
+async function getPrFiles(prNo) {
+  logger.debug({ prNo }, 'getPrFiles');
+  if (!prNo) {
+    return [];
+  }
+  const files = (await get(
+    `repos/${config.parentRepo || config.repository}/pulls/${prNo}/files`
+  )).body;
+  return files.map(f => f.filename);
+}
+
 async function updatePr(prNo, title, body) {
   logger.debug(`updatePr(${prNo}, ${title}, body)`);
   const patchBody = { title };
diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js
index af0549c3db..5b64f2df75 100644
--- a/lib/platform/gitlab/index.js
+++ b/lib/platform/gitlab/index.js
@@ -34,6 +34,7 @@ module.exports = {
   findPr,
   createPr,
   getPr,
+  getPrFiles,
   updatePr,
   mergePr,
   // file
@@ -483,6 +484,11 @@ async function getPr(iid) {
   return pr;
 }
 
+function getPrFiles() {
+  // TODO
+  return [];
+}
+
 async function updatePr(iid, title, description) {
   await get.put(`projects/${config.repository}/merge_requests/${iid}`, {
     body: {
diff --git a/lib/platform/vsts/index.js b/lib/platform/vsts/index.js
index 7fd0841931..b16f5656d2 100644
--- a/lib/platform/vsts/index.js
+++ b/lib/platform/vsts/index.js
@@ -36,6 +36,7 @@ module.exports = {
   findPr,
   createPr,
   getPr,
+  getPrFiles,
   updatePr,
   mergePr,
   // file
@@ -556,3 +557,9 @@ async function addReviewers(prNo, reviewers) {
     })
   );
 }
+
+// to become async?
+function getPrFiles(prNo) {
+  logger.info(`getPrFiles(prNo)(${prNo}) - Not supported by VSTS (yet!)`);
+  return [];
+}
diff --git a/test/platform/__snapshots__/index.spec.js.snap b/test/platform/__snapshots__/index.spec.js.snap
index 13901bdef4..0543b2fb6e 100644
--- a/test/platform/__snapshots__/index.spec.js.snap
+++ b/test/platform/__snapshots__/index.spec.js.snap
@@ -27,6 +27,7 @@ Array [
   "findPr",
   "createPr",
   "getPr",
+  "getPrFiles",
   "updatePr",
   "mergePr",
   "commitFilesToBranch",
@@ -62,6 +63,7 @@ Array [
   "findPr",
   "createPr",
   "getPr",
+  "getPrFiles",
   "updatePr",
   "mergePr",
   "commitFilesToBranch",
@@ -97,6 +99,7 @@ Array [
   "findPr",
   "createPr",
   "getPr",
+  "getPrFiles",
   "updatePr",
   "mergePr",
   "commitFilesToBranch",
diff --git a/test/platform/github/__snapshots__/index.spec.js.snap b/test/platform/github/__snapshots__/index.spec.js.snap
index 19a04807f6..91fdb42415 100644
--- a/test/platform/github/__snapshots__/index.spec.js.snap
+++ b/test/platform/github/__snapshots__/index.spec.js.snap
@@ -523,6 +523,13 @@ Object {
 }
 `;
 
+exports[`platform/github getPrFiles() returns files 1`] = `
+Array [
+  "renovate.json",
+  "not renovate.json",
+]
+`;
+
 exports[`platform/github getRepos should return an array of repos 1`] = `
 Array [
   Array [
diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js
index 6a49737c84..7b840d9568 100644
--- a/test/platform/github/index.spec.js
+++ b/test/platform/github/index.spec.js
@@ -1309,6 +1309,23 @@ describe('platform/github', () => {
       expect(pr).toMatchSnapshot();
     });
   });
+  describe('getPrFiles()', () => {
+    it('should return empty if no prNo is passed', async () => {
+      const prFiles = await github.getPrFiles(null);
+      expect(prFiles).toEqual([]);
+    });
+    it('returns files', async () => {
+      get.mockReturnValueOnce({
+        body: [
+          { filename: 'renovate.json' },
+          { filename: 'not renovate.json' },
+        ],
+      });
+      const prFiles = await github.getPrFiles(123);
+      expect(prFiles).toMatchSnapshot();
+      expect(prFiles).toHaveLength(2);
+    });
+  });
   describe('updatePr(prNo, title, body)', () => {
     it('should update the PR', async () => {
       await initRepo({ repository: 'some/repo', token: 'token' });
diff --git a/test/platform/gitlab/index.spec.js b/test/platform/gitlab/index.spec.js
index a2015e606b..c7de3d06ee 100644
--- a/test/platform/gitlab/index.spec.js
+++ b/test/platform/gitlab/index.spec.js
@@ -624,6 +624,12 @@ describe('platform/gitlab', () => {
       expect(pr).toMatchSnapshot();
     });
   });
+  describe('getPrFiles()', () => {
+    it('should return empty', async () => {
+      const prFiles = await gitlab.getPrFiles();
+      expect(prFiles).toEqual([]);
+    });
+  });
   describe('updatePr(prNo, title, body)', () => {
     jest.resetAllMocks();
     it('updates the PR', async () => {
diff --git a/test/platform/vsts/index.spec.js b/test/platform/vsts/index.spec.js
index 381ca7d157..eb0a81f047 100644
--- a/test/platform/vsts/index.spec.js
+++ b/test/platform/vsts/index.spec.js
@@ -691,5 +691,11 @@ describe('platform/vsts', () => {
       const res = await vsts.mergePr();
       expect(res).toBeUndefined();
     });
+
+    // to become async?
+    it('getPrFiles', () => {
+      const res = vsts.getPrFiles(46);
+      expect(res.length).toBe(0);
+    });
   });
 });
-- 
GitLab