diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index 19594b26108f52b82206b7bef61083038bd23b5d..b23555415ca6a53f1ca0f58a328d0af61f19c0ba 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 af0549c3dba99a44dd780fb8da1b87c7f535fd65..5b64f2df75b2696cef38af294879c7a4efc6a734 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 7fd084193157a1e3d0b507299c41950e4dd95c02..b16f5656d2c08f0a87d721977a4712587c138a92 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 13901bdef4d8a93ded572d0cf77bfe58eeb99f11..0543b2fb6e3ccfd68643a64e0609a65c41e530b9 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 19a04807f6ad6fb736ab11461b31c2790e98837b..91fdb424155c2a47c499176150d46a36367fb35f 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 6a49737c84cccded5c2fd99cb0066ac359904933..7b840d9568c82a78a55915c4f5cf51401cda6950 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 a2015e606b436a495c0ee6f420b516ea485b3006..c7de3d06ee1eba7897a0dd07d50322b3af0e6d5d 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 381ca7d157034d2955e0dbf93da402b1e917fa70..eb0a81f047f550554a793ba36b2edc16dc0bb1a7 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); + }); }); });