Skip to content
Snippets Groups Projects
Commit 3428b4b1 authored by Guillaume Dedrie's avatar Guillaume Dedrie Committed by Rhys Arkins
Browse files

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
parent 6a3836fa
No related merge requests found
...@@ -718,8 +718,8 @@ async function getPrFiles(mrNo) { ...@@ -718,8 +718,8 @@ async function getPrFiles(mrNo) {
} }
const files = (await get( const files = (await get(
`projects/${config.repository}/merge_requests/${mrNo}/changes` `projects/${config.repository}/merge_requests/${mrNo}/changes`
)).body; )).body.changes;
return files.map(f => f.filename); return files.map(f => f.new_path);
} }
// istanbul ignore next // istanbul ignore next
......
...@@ -870,10 +870,12 @@ describe('platform/gitlab', () => { ...@@ -870,10 +870,12 @@ describe('platform/gitlab', () => {
}); });
it('returns files', async () => { it('returns files', async () => {
get.mockReturnValueOnce({ get.mockReturnValueOnce({
body: [ body: {
{ filename: 'renovate.json' }, changes: [
{ filename: 'not renovate.json' }, { new_path: 'renovate.json' },
], { new_path: 'not renovate.json' },
],
},
}); });
const prFiles = await gitlab.getPrFiles(123); const prFiles = await gitlab.getPrFiles(123);
expect(prFiles).toMatchSnapshot(); expect(prFiles).toMatchSnapshot();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment