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'); logger.info('Cannot retrieve large files from non-master branch');
return null; return null;
} }
let treeUrl = `repos/${config.repository}/git/trees/${config.baseBranch}`; // istanbul ignore if
const parentPath = path.dirname(filePath); if (path.dirname(filePath) !== '.') {
if (parentPath !== '.') { logger.info('Cannot retrieve large files from non-root directories');
treeUrl += `/${parentPath}`; return null;
} }
const treeUrl = `repos/${config.repository}/git/trees/${
config.baseBranch
}`;
const baseName = path.basename(filePath); const baseName = path.basename(filePath);
let fileSha; let fileSha;
(await get(treeUrl)).body.tree.forEach(file => { (await get(treeUrl)).body.tree.forEach(file => {

View file

@ -241,10 +241,10 @@ Array [
"repos/some/repo/git/trees/master?recursive=true", "repos/some/repo/git/trees/master?recursive=true",
], ],
Array [ Array [
"repos/some/repo/contents/backend/package-lock.json?ref=master", "repos/some/repo/contents/package-lock.json?ref=master",
], ],
Array [ Array [
"repos/some/repo/git/trees/master/backend", "repos/some/repo/git/trees/master",
], ],
Array [ Array [
"repos/some/repo/git/blobs/some-sha", "repos/some/repo/git/blobs/some-sha",

View file

@ -74,7 +74,7 @@ describe('platform/github', () => {
}, },
{ {
type: 'blob', 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'), 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(get.mock.calls).toMatchSnapshot();
expect(content).toMatchSnapshot(); expect(content).toMatchSnapshot();
}); });
@ -1663,7 +1663,7 @@ describe('platform/github', () => {
})); }));
let e; let e;
try { try {
await github.getFile('backend/package-lock.json'); await github.getFile('package-lock.json');
} catch (err) { } catch (err) {
e = err; e = err;
} }