fix(github): try large files only if in root dir

This commit is contained in:
Rhys Arkins 2018-07-20 10:47:42 +02:00
parent 4ecbbc77d7
commit 5d0b63bd06
3 changed files with 12 additions and 9 deletions

View file

@ -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 => {

View file

@ -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",

View file

@ -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;
}