diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index 00e0a6acb1..2eb8d3ac22 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -1141,11 +1141,14 @@ async function getFile(filePath, branchName) { logger.info('Cannot retrieve large files from non-master branch'); return null; } - let treeUrl = `repos/${config.repository}/git/trees/${config.baseBranch}`; - const parentPath = path.dirname(filePath); - if (parentPath !== '.') { - treeUrl += `/${parentPath}`; + // istanbul ignore if + if (path.dirname(filePath) !== '.') { + logger.info('Cannot retrieve large files from non-root directories'); + return null; } + const treeUrl = `repos/${config.repository}/git/trees/${ + config.baseBranch + }`; const baseName = path.basename(filePath); let fileSha; (await get(treeUrl)).body.tree.forEach(file => { diff --git a/test/platform/github/__snapshots__/index.spec.js.snap b/test/platform/github/__snapshots__/index.spec.js.snap index a28409a4d1..2352841cfe 100644 --- a/test/platform/github/__snapshots__/index.spec.js.snap +++ b/test/platform/github/__snapshots__/index.spec.js.snap @@ -241,10 +241,10 @@ Array [ "repos/some/repo/git/trees/master?recursive=true", ], Array [ - "repos/some/repo/contents/backend/package-lock.json?ref=master", + "repos/some/repo/contents/package-lock.json?ref=master", ], Array [ - "repos/some/repo/git/trees/master/backend", + "repos/some/repo/git/trees/master", ], Array [ "repos/some/repo/git/blobs/some-sha", diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js index 2e69f9a33e..245138fb3c 100644 --- a/test/platform/github/index.spec.js +++ b/test/platform/github/index.spec.js @@ -74,7 +74,7 @@ describe('platform/github', () => { }, { type: 'blob', - path: 'backend/package-lock.json', + path: 'package-lock.json', }, ], }, @@ -1644,7 +1644,7 @@ describe('platform/github', () => { content: Buffer.from('{"hello":"workd"}').toString('base64'), }, })); - const content = await github.getFile('backend/package-lock.json'); + const content = await github.getFile('package-lock.json'); expect(get.mock.calls).toMatchSnapshot(); expect(content).toMatchSnapshot(); }); @@ -1663,7 +1663,7 @@ describe('platform/github', () => { })); let e; try { - await github.getFile('backend/package-lock.json'); + await github.getFile('package-lock.json'); } catch (err) { e = err; }