diff --git a/lib/manager/docker/detect.js b/lib/manager/docker/detect.js index 3006bfa02e8315303c718549f4fca00e81db568c..a2521a282de9a31571525f537039443f6e4d3964 100644 --- a/lib/manager/docker/detect.js +++ b/lib/manager/docker/detect.js @@ -8,7 +8,7 @@ async function detectPackageFiles(config, fileList) { if (config.docker.enabled) { for (const file of fileList) { if (file === 'Dockerfile' || file.endsWith('/Dockerfile')) { - const content = await platform.getFileContent(file); + const content = await platform.getFile(file); if (content) { const strippedComment = content.replace(/^(#.*?\n)+/, ''); // This means we skip ones with ARG for now diff --git a/lib/manager/docker/resolve.js b/lib/manager/docker/resolve.js index b4842846b158216194e63cc316e401a140007c86..54fd0f30767b81ce3334c58cf616b95df8763494 100644 --- a/lib/manager/docker/resolve.js +++ b/lib/manager/docker/resolve.js @@ -9,7 +9,7 @@ async function resolvePackageFile(config, inputFile) { logger.debug( `Resolving packageFile ${JSON.stringify(packageFile.packageFile)}` ); - packageFile.content = await platform.getFileContent(packageFile.packageFile); + packageFile.content = await platform.getFile(packageFile.packageFile); if (!packageFile.content) { logger.debug('No packageFile content'); return null; diff --git a/lib/manager/index.js b/lib/manager/index.js index 0bd5556b219ffcc3bc9a17ee87dc30da135381b3..8d75c48efab2c2cdf5872373f496c2e44218ebd9 100644 --- a/lib/manager/index.js +++ b/lib/manager/index.js @@ -64,10 +64,7 @@ async function getUpdatedPackageFiles(config) { if (upgrade.type !== 'lockFileMaintenance') { const existingContent = updatedPackageFiles[upgrade.packageFile] || - (await platform.getFileContent( - upgrade.packageFile, - config.parentBranch - )); + (await platform.getFile(upgrade.packageFile, config.parentBranch)); let newContent = existingContent; if (upgrade.packageFile.endsWith('package.json')) { newContent = npmUpdater.setNewValue( diff --git a/lib/manager/meteor/detect.js b/lib/manager/meteor/detect.js index 1272664d8bd6e1d183d212ba0babf0c716280629..079753a5f0c7f3a025a30ece83135b82dc85638d 100644 --- a/lib/manager/meteor/detect.js +++ b/lib/manager/meteor/detect.js @@ -8,7 +8,7 @@ async function detectPackageFiles(config, fileList) { if (config.meteor.enabled) { for (const file of fileList) { if (file === 'package.js' || file.endsWith('/package.js')) { - const content = await platform.getFileContent(file); + const content = await platform.getFile(file); if (content && content.replace(/\s/g, '').includes('Npm.depends({')) { packageFiles.push(file); } diff --git a/lib/manager/npm/monorepos.js b/lib/manager/npm/monorepos.js index 3f7c83c4d9ecbd3e930322e8792c52e3eb301d0d..f20f52f7b23e1ada33605cf3e2734ccd19ca5d9b 100644 --- a/lib/manager/npm/monorepos.js +++ b/lib/manager/npm/monorepos.js @@ -37,7 +37,12 @@ async function checkMonorepos(config) { } } // lerna - const lernaJson = await platform.getFileJson('lerna.json'); + let lernaJson; + try { + lernaJson = JSON.parse(await platform.getFile('lerna.json')); + } catch (err) { + // do nothing + } if (lernaJson && lernaJson.packages) { logger.debug({ lernaJson }, 'Found lerna config'); for (const packageGlob of lernaJson.packages) { diff --git a/lib/manager/resolve.js b/lib/manager/resolve.js index 5f88070c19c6d30d45f3cef23bf594525c8db106..ee1ab6467841f6430e2d80aba83c3425f213c029 100644 --- a/lib/manager/resolve.js +++ b/lib/manager/resolve.js @@ -24,7 +24,7 @@ async function resolvePackageFiles(config) { typeof packageFile === 'string' ? { packageFile } : packageFile; if (packageFile.packageFile.endsWith('package.json')) { logger.debug(`Resolving packageFile ${JSON.stringify(packageFile)}`); - const pFileRaw = await platform.getFileContent(packageFile.packageFile); + const pFileRaw = await platform.getFile(packageFile.packageFile); if (!pFileRaw) { logger.info( { packageFile: packageFile.packageFile }, @@ -49,14 +49,14 @@ async function resolvePackageFiles(config) { } } if (!config.ignoreNpmrcFile) { - packageFile.npmrc = await platform.getFileContent( + packageFile.npmrc = await platform.getFile( path.join(path.dirname(packageFile.packageFile), '.npmrc') ); } if (!packageFile.npmrc) { delete packageFile.npmrc; } - packageFile.yarnrc = await platform.getFileContent( + packageFile.yarnrc = await platform.getFile( path.join(path.dirname(packageFile.packageFile), '.yarnrc') ); if (!packageFile.yarnrc) { @@ -100,7 +100,7 @@ async function resolvePackageFiles(config) { path.dirname(packageFile.packageFile), 'yarn.lock' ); - packageFile.yarnLock = await platform.getFileContent(yarnLockFileName); + packageFile.yarnLock = await platform.getFile(yarnLockFileName); if (packageFile.yarnLock) { logger.debug( { packageFile: packageFile.packageFile }, @@ -111,9 +111,7 @@ async function resolvePackageFiles(config) { path.dirname(packageFile.packageFile), 'package-lock.json' ); - packageFile.packageLock = await platform.getFileContent( - packageLockFileName - ); + packageFile.packageLock = await platform.getFile(packageLockFileName); if (packageFile.packageLock) { logger.debug( { packageFile: packageFile.packageFile }, diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index cf27e3a77f10053c61fd42ffb11505361966eaf7..8024cbc0168a6b0d0485404ddac4d0163cc269cf 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -33,11 +33,8 @@ module.exports = { updatePr, mergePr, // file - getSubDirectories, commitFilesToBranch, getFile, - getFileContent, - getFileJson, // Commits getCommitMessages, }; @@ -642,21 +639,13 @@ async function mergePr(pr) { async function getFile(filePath, branchName) { logger.trace(`getFile(filePath=${filePath}, branchName=${branchName})`); - const res = await get( - `repos/${config.repoName}/contents/${filePath}?ref=${branchName || - config.baseBranch}` - ); - return res.body.content; -} - -async function getFileContent(filePath, branchName) { - logger.trace( - `getFileContent(filePath=${filePath}, branchName=${branchName})` - ); try { - const file = await getFile(filePath, branchName); - if (file) { - return Buffer.from(file, 'base64').toString(); + const res = await get( + `repos/${config.repoName}/contents/${filePath}?ref=${branchName || + config.baseBranch}` + ); + if (res.body.content) { + return Buffer.from(res.body.content, 'base64').toString(); } return null; } catch (error) { @@ -669,29 +658,6 @@ async function getFileContent(filePath, branchName) { } } -async function getFileJson(filePath, branchName) { - logger.trace(`getFileJson(filePath=${filePath}, branchName=${branchName})`); - let fileJson = null; - try { - fileJson = JSON.parse(await getFileContent(filePath, branchName)); - } catch (err) { - logger.debug({ err }, `Failed to parse JSON for ${filePath}`); - } - return fileJson; -} - -async function getSubDirectories(path) { - logger.trace(`getSubDirectories(path=${path})`); - const res = await get(`repos/${config.repoName}/contents/${path}`); - const directoryList = []; - res.body.forEach(item => { - if (item.type === 'dir') { - directoryList.push(item.name); - } - }); - return directoryList; -} - // Add a new commit, create branch if not existing async function commitFilesToBranch( branchName, diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js index 78c7cccd7c8a103a8235f7f15b9c7cd17c84f6e1..adff81942838f0611c1bbec0f17c4b9bdb374553 100644 --- a/lib/platform/gitlab/index.js +++ b/lib/platform/gitlab/index.js @@ -34,11 +34,8 @@ module.exports = { updatePr, mergePr, // file - getSubDirectories, commitFilesToBranch, getFile, - getFileContent, - getFileJson, // commits getCommitMessages, }; @@ -425,19 +422,14 @@ async function mergePr(pr) { // Generic File operations -async function getFile(filePath, branchName = config.baseBranch) { - const url = `projects/${config.repoName}/repository/files/${filePath.replace( - /\//g, - '%2F' - )}?ref=${branchName}`; - const res = await get(url); - return res.body.content; -} - -async function getFileContent(filePath, branchName) { +async function getFile(filePath, branchName) { try { - const file = await getFile(filePath, branchName); - return Buffer.from(file, 'base64').toString(); + const url = `projects/${ + config.repoName + }/repository/files/${filePath.replace(/\//g, '%2F')}?ref=${branchName || + config.baseBranch}`; + const res = await get(url); + return Buffer.from(res.body.content, 'base64').toString(); } catch (error) { if (error.statusCode === 404) { // If file not found, then return null JSON @@ -448,25 +440,6 @@ async function getFileContent(filePath, branchName) { } } -async function getFileJson(filePath, branchName) { - const fileContent = await getFileContent(filePath, branchName); - return JSON.parse(fileContent); -} - -async function getSubDirectories(path) { - logger.trace(`getSubDirectories(path=${path})`); - const res = await get( - `projects/${config.repoName}/repository/tree?path=${path}` - ); - const directoryList = []; - res.body.forEach(item => { - if (item.type === 'tree') { - directoryList.push(item.name); - } - }); - return directoryList; -} - // Add a new commit, create branch if not existing async function commitFilesToBranch( branchName, @@ -493,7 +466,7 @@ async function commitFilesToBranch( } } for (const file of files) { - const existingFile = await getFileContent(file.name, branchName); + const existingFile = await getFile(file.name, branchName); if (existingFile) { logger.debug(`${file.name} exists - updating it`); await updateFile( diff --git a/lib/workers/branch/lock-files.js b/lib/workers/branch/lock-files.js index b484d43708562d47cf113ad7274304a8cbb336aa..1a518bd460e4cbe824d7a7d70ed5e0bc6c026b85 100644 --- a/lib/workers/branch/lock-files.js +++ b/lib/workers/branch/lock-files.js @@ -214,7 +214,7 @@ async function getUpdatedLockFiles(config) { stderr: res.stderr, }); } else { - const existingContent = await platform.getFileContent( + const existingContent = await platform.getFile( lockFileName, config.parentBranch ); @@ -242,7 +242,7 @@ async function getUpdatedLockFiles(config) { stderr: res.stderr, }); } else { - const existingContent = await platform.getFileContent( + const existingContent = await platform.getFile( lockFileName, config.parentBranch ); diff --git a/lib/workers/package-file/index.js b/lib/workers/package-file/index.js index c05ce3c6e057e8f57f93a3d1cc7ebd1673c5fdf4..4762bd858d4a7232f03f77dc0737de560b542002 100644 --- a/lib/workers/package-file/index.js +++ b/lib/workers/package-file/index.js @@ -110,7 +110,7 @@ async function renovateMeteorPackageFile(packageFileConfig) { logger.info('packageFile is disabled'); return upgrades; } - const content = await platform.getFileContent(packageFileConfig.packageFile); + const content = await platform.getFile(packageFileConfig.packageFile); upgrades = upgrades.concat( await depTypeWorker.renovateDepType(content, packageFileConfig) ); diff --git a/lib/workers/repository/init/config.js b/lib/workers/repository/init/config.js index b101ca7d1304b55b7cfdcb88e20b22010186b48c..de05174697b754debefdf2b110c2be76e74f7553 100644 --- a/lib/workers/repository/init/config.js +++ b/lib/workers/repository/init/config.js @@ -8,7 +8,7 @@ const presets = require('../../../config/presets'); // Check for config in `renovate.json` async function mergeRenovateJson(config) { let returnConfig = { ...config }; - const renovateJsonContent = await platform.getFileContent('renovate.json'); + const renovateJsonContent = await platform.getFile('renovate.json'); if (!renovateJsonContent) { logger.debug('No renovate.json found'); return returnConfig; diff --git a/test/_fixtures/config/index.js b/test/_fixtures/config/index.js index c6427b7a8877efab202f67c45fd93e19e422bbc5..2c1950c3f922e7320ca801fb915f4a648290e226 100644 --- a/test/_fixtures/config/index.js +++ b/test/_fixtures/config/index.js @@ -1,7 +1,5 @@ const defaultConfig = require('../../../lib/config/defaults').getConfig(); -const api = jest.genMockFromModule('../../../lib/platform/github'); module.exports = { ...defaultConfig, - api, }; diff --git a/test/manager/__snapshots__/resolve.spec.js.snap b/test/manager/__snapshots__/resolve.spec.js.snap index 0a1375d4a152913fad7f9fc9241d447bd942381f..edab1ee93c3192bbc66b853016fee6962da3b56f 100644 --- a/test/manager/__snapshots__/resolve.spec.js.snap +++ b/test/manager/__snapshots__/resolve.spec.js.snap @@ -2,37 +2,6 @@ exports[`manager/resolve resolvePackageFiles() deetect package.json and warns if cannot parse 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -527,37 +496,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`manager/resolve resolvePackageFiles() detects meteor and docker 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -1272,37 +1210,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`manager/resolve resolvePackageFiles() detects package.json and parses json with renovate config 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -1802,37 +1709,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`manager/resolve resolvePackageFiles() downloads accompanying files 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -2333,37 +2209,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`manager/resolve resolvePackageFiles() skips docker if no content or no match 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -2853,37 +2698,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`manager/resolve resolvePackageFiles() uses packageFiles if already configured and raises error if not found 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, diff --git a/test/manager/index.spec.js b/test/manager/index.spec.js index 123c14a1e2d3f6dab9179f2aad4520c73d9e4424..acf6bd17fb194978039b88b6666431b94d836970 100644 --- a/test/manager/index.spec.js +++ b/test/manager/index.spec.js @@ -29,7 +29,7 @@ describe('manager', () => { platform.getFileList.mockReturnValueOnce([ 'modules/something/package.js', ]); // meteor - platform.getFileContent.mockReturnValueOnce('Npm.depends( {} )'); + platform.getFile.mockReturnValueOnce('Npm.depends( {} )'); const res = await manager.detectPackageFiles(config); expect(res).toMatchSnapshot(); expect(res).toHaveLength(1); @@ -39,7 +39,7 @@ describe('manager', () => { platform.getFileList.mockReturnValueOnce([ 'modules/something/package.js', ]); // meteor - platform.getFileContent.mockReturnValueOnce('Npm.depends(packages)'); + platform.getFile.mockReturnValueOnce('Npm.depends(packages)'); const res = await manager.detectPackageFiles(config); expect(res).toMatchSnapshot(); expect(res).toHaveLength(0); @@ -49,10 +49,10 @@ describe('manager', () => { 'Dockerfile', 'other/Dockerfile', ]); - platform.getFileContent.mockReturnValueOnce( + platform.getFile.mockReturnValueOnce( '### comment\nFROM something\nRUN something' ); - platform.getFileContent.mockReturnValueOnce( + platform.getFile.mockReturnValueOnce( 'ARG foo\nFROM something\nRUN something' ); const res = await manager.detectPackageFiles(config); @@ -61,7 +61,7 @@ describe('manager', () => { }); it('skips Dockerfiles with no content', async () => { platform.getFileList.mockReturnValueOnce(['Dockerfile']); - platform.getFileContent.mockReturnValueOnce(null); + platform.getFile.mockReturnValueOnce(null); const res = await manager.detectPackageFiles(config); expect(res).toHaveLength(0); }); @@ -120,10 +120,10 @@ describe('manager', () => { { packageFile: 'Dockerfile' }, { packageFile: 'packages/foo/package.js' }, ]; - platform.getFileContent.mockReturnValueOnce('old content 1'); - platform.getFileContent.mockReturnValueOnce('old content 1'); - platform.getFileContent.mockReturnValueOnce('old content 2'); - platform.getFileContent.mockReturnValueOnce('old content 3'); + platform.getFile.mockReturnValueOnce('old content 1'); + platform.getFile.mockReturnValueOnce('old content 1'); + platform.getFile.mockReturnValueOnce('old content 2'); + platform.getFile.mockReturnValueOnce('old content 3'); npmUpdater.setNewValue.mockReturnValueOnce('new content 1'); npmUpdater.setNewValue.mockReturnValueOnce('new content 1+'); dockerUpdater.setNewValue.mockReturnValueOnce('new content 2'); diff --git a/test/manager/npm/monorepo.spec.js b/test/manager/npm/monorepo.spec.js index 986e5c459df75a62d03ccfbd7656d00a4b83d63b..85bff2ddc5c12f329eea79ac173352d5e84344b4 100644 --- a/test/manager/npm/monorepo.spec.js +++ b/test/manager/npm/monorepo.spec.js @@ -61,7 +61,7 @@ describe('manager/npm/monorepo', () => { content: { name: '@a/c' }, }, ]; - platform.getFileJson.mockReturnValue({ packages: ['packages/*'] }); + platform.getFile.mockReturnValue('{ "packages": ["packages/*"] }'); const res = await checkMonorepos(config); expect(res.monorepoPackages).toMatchSnapshot(); }); @@ -72,7 +72,7 @@ describe('manager/npm/monorepo', () => { content: {}, }, ]; - platform.getFileJson.mockReturnValue({}); + platform.getFile.mockReturnValue(null); const res = await checkMonorepos(config); expect(res.monorepoPackages).toMatchSnapshot(); }); diff --git a/test/manager/resolve.spec.js b/test/manager/resolve.spec.js index a6d7d17e6c4cda83e88a06cace6b0abddbc2704d..7b959f5158962e8dfd786dc061a7ef3faaa84847 100644 --- a/test/manager/resolve.spec.js +++ b/test/manager/resolve.spec.js @@ -24,7 +24,7 @@ describe('manager/resolve', () => { manager.detectPackageFiles = jest.fn(() => [ { packageFile: 'package.json' }, ]); - platform.getFileContent.mockReturnValueOnce('not json'); + platform.getFile.mockReturnValueOnce('not json'); const res = await resolvePackageFiles(config); expect(res).toMatchSnapshot(); expect(res.warnings).toHaveLength(1); @@ -38,7 +38,7 @@ describe('manager/resolve', () => { automerge: true, }, }; - platform.getFileContent.mockReturnValueOnce(JSON.stringify(pJson)); + platform.getFile.mockReturnValueOnce(JSON.stringify(pJson)); const res = await resolvePackageFiles(config); expect(res).toMatchSnapshot(); expect(res.warnings).toHaveLength(0); @@ -47,26 +47,24 @@ describe('manager/resolve', () => { manager.detectPackageFiles = jest.fn(() => [ { packageFile: 'package.json' }, ]); - platform.getFileContent.mockReturnValueOnce('{"name": "package.json"}'); - platform.getFileContent.mockReturnValueOnce('npmrc'); - platform.getFileContent.mockReturnValueOnce('yarnrc'); - platform.getFileContent.mockReturnValueOnce('# yarn.lock'); - platform.getFileContent.mockReturnValueOnce( - '{"name": "packge-lock.json"}' - ); + platform.getFile.mockReturnValueOnce('{"name": "package.json"}'); + platform.getFile.mockReturnValueOnce('npmrc'); + platform.getFile.mockReturnValueOnce('yarnrc'); + platform.getFile.mockReturnValueOnce('# yarn.lock'); + platform.getFile.mockReturnValueOnce('{"name": "packge-lock.json"}'); const res = await resolvePackageFiles(config); expect(res).toMatchSnapshot(); expect(res.warnings).toHaveLength(0); }); it('detects meteor and docker', async () => { config.packageFiles = ['package.js', 'Dockerfile']; - platform.getFileContent.mockReturnValueOnce('# comment\nFROM node:8\n'); // Dockerfile + platform.getFile.mockReturnValueOnce('# comment\nFROM node:8\n'); // Dockerfile const res = await resolvePackageFiles(config); expect(res).toMatchSnapshot(); }); it('skips docker if no content or no match', async () => { config.packageFiles = ['Dockerfile', 'other/Dockerfile']; - platform.getFileContent.mockReturnValueOnce('# comment\n'); // Dockerfile + platform.getFile.mockReturnValueOnce('# comment\n'); // Dockerfile const res = await resolvePackageFiles(config); expect(res).toMatchSnapshot(); }); diff --git a/test/platform/__snapshots__/index.spec.js.snap b/test/platform/__snapshots__/index.spec.js.snap index dcd05f52756e6d50aba02e19fb85ccf0a277fa5d..a639fe6db34435d797416c08c07c4d9d50e4f622 100644 --- a/test/platform/__snapshots__/index.spec.js.snap +++ b/test/platform/__snapshots__/index.spec.js.snap @@ -25,11 +25,8 @@ Array [ "getPr", "updatePr", "mergePr", - "getSubDirectories", "commitFilesToBranch", "getFile", - "getFileContent", - "getFileJson", "getCommitMessages", ] `; @@ -59,11 +56,8 @@ Array [ "getPr", "updatePr", "mergePr", - "getSubDirectories", "commitFilesToBranch", "getFile", - "getFileContent", - "getFileJson", "getCommitMessages", ] `; diff --git a/test/platform/github/__snapshots__/index.spec.js.snap b/test/platform/github/__snapshots__/index.spec.js.snap index 59251e98469eb2cdc3f55cf9748e1d62358434b4..8534a8171583b5fb2e3dc679ccf5f75e93f592b6 100644 --- a/test/platform/github/__snapshots__/index.spec.js.snap +++ b/test/platform/github/__snapshots__/index.spec.js.snap @@ -508,7 +508,7 @@ Array [ ] `; -exports[`platform/github getFile(filePatch, branchName) should return the encoded file content 1`] = ` +exports[`platform/github getFile(filePatch, branchName) should return null if GitHub returns a 404 1`] = ` Array [ Array [ "repos/some/repo", @@ -535,7 +535,7 @@ Array [ ] `; -exports[`platform/github getFileContent(filePatch, branchName) should return null if GitHub returns a 404 1`] = ` +exports[`platform/github getFile(filePatch, branchName) should return null if getFile returns nothing 1`] = ` Array [ Array [ "repos/some/repo", @@ -562,88 +562,7 @@ Array [ ] `; -exports[`platform/github getFileContent(filePatch, branchName) should return null if getFile returns nothing 1`] = ` -Array [ - Array [ - "repos/some/repo", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/git/refs/heads/master", - ], - Array [ - "repos/some/repo/branches/master/protection/required_status_checks", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/contents/package.json?ref=master", - ], -] -`; - -exports[`platform/github getFileContent(filePatch, branchName) should return the encoded file content 1`] = ` -Array [ - Array [ - "repos/some/repo", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/git/refs/heads/master", - ], - Array [ - "repos/some/repo/branches/master/protection/required_status_checks", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/contents/package.json?ref=master", - ], -] -`; - -exports[`platform/github getFileJson(filePatch, branchName) should return null if invalid JSON 1`] = ` -Array [ - Array [ - "repos/some/repo", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/git/refs/heads/master", - ], - Array [ - "repos/some/repo/branches/master/protection/required_status_checks", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/contents/package.json?ref=master", - ], -] -`; - -exports[`platform/github getFileJson(filePatch, branchName) should return the file contents parsed as JSON 1`] = ` +exports[`platform/github getFile(filePatch, branchName) should return the encoded file content 1`] = ` Array [ Array [ "repos/some/repo", @@ -670,12 +589,6 @@ Array [ ] `; -exports[`platform/github getFileJson(filePatch, branchName) should return the file contents parsed as JSON 2`] = ` -Object { - "hello": "world", -} -`; - exports[`platform/github getFileList should return the files matching the fileName 1`] = ` Array [ "package.json", @@ -800,39 +713,6 @@ Array [ ] `; -exports[`platform/github getSubDirectories(path) should return subdirectories 1`] = ` -Array [ - Array [ - "repos/some/repo", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/git/refs/heads/master", - ], - Array [ - "repos/some/repo/branches/master/protection/required_status_checks", - Object { - "headers": Object { - "accept": "application/vnd.github.loki-preview+json", - }, - }, - ], - Array [ - "repos/some/repo/contents/some-path", - ], -] -`; - -exports[`platform/github getSubDirectories(path) should return subdirectories 2`] = ` -Array [ - "a", -] -`; - exports[`platform/github initRepo should detect repoForceRebase 1`] = ` Object { "isFork": false, diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js index 175779c5d0858b8d7535fb4784d0ceb308dba542..c52bee229be4b964962db77bf8e7e9a4aa5374a1 100644 --- a/test/platform/github/index.spec.js +++ b/test/platform/github/index.spec.js @@ -1266,19 +1266,6 @@ describe('platform/github', () => { }); }); describe('getFile(filePatch, branchName)', () => { - it('should return the encoded file content', async () => { - await initRepo('some/repo', 'token'); - get.mockImplementationOnce(() => ({ - body: { - content: 'hello', - }, - })); - const content = await github.getFile('package.json'); - expect(get.mock.calls).toMatchSnapshot(); - expect(content).toBe('hello'); - }); - }); - describe('getFileContent(filePatch, branchName)', () => { it('should return the encoded file content', async () => { await initRepo('some/repo', 'token'); get.mockImplementationOnce(() => ({ @@ -1286,7 +1273,7 @@ describe('platform/github', () => { content: Buffer.from('hello world').toString('base64'), }, })); - const content = await github.getFileContent('package.json'); + const content = await github.getFile('package.json'); expect(get.mock.calls).toMatchSnapshot(); expect(content).toBe('hello world'); }); @@ -1297,7 +1284,7 @@ describe('platform/github', () => { statusCode: 404, }) ); - const content = await github.getFileContent('package.json'); + const content = await github.getFile('package.json'); expect(get.mock.calls).toMatchSnapshot(); expect(content).toBe(null); }); @@ -1306,7 +1293,7 @@ describe('platform/github', () => { get.mockImplementationOnce(() => ({ body: {}, })); - const content = await github.getFileContent('package.json'); + const content = await github.getFile('package.json'); expect(get.mock.calls).toMatchSnapshot(); expect(content).toBe(null); }); @@ -1317,51 +1304,13 @@ describe('platform/github', () => { }); let err; try { - await github.getFileContent('package.json'); + await github.getFile('package.json'); } catch (e) { err = e; } expect(err.message).toBe('Something went wrong'); }); }); - describe('getFileJson(filePatch, branchName)', () => { - it('should return the file contents parsed as JSON', async () => { - await initRepo('some/repo', 'token'); - get.mockImplementationOnce(() => ({ - body: { - content: Buffer.from('{"hello": "world"}').toString('base64'), - }, - })); - const content = await github.getFileJson('package.json'); - expect(get.mock.calls).toMatchSnapshot(); - expect(content).toMatchSnapshot(); - }); - }); - describe('getFileJson(filePatch, branchName)', () => { - it('should return null if invalid JSON', async () => { - await initRepo('some/repo', 'token'); - get.mockImplementationOnce(() => ({ - body: { - content: Buffer.from('{hello: "world"}').toString('base64'), - }, - })); - const content = await github.getFileJson('package.json'); - expect(get.mock.calls).toMatchSnapshot(); - expect(content).toBeNull(); - }); - }); - describe('getSubDirectories(path)', () => { - it('should return subdirectories', async () => { - await initRepo('some/repo', 'token'); - get.mockImplementationOnce(() => ({ - body: [{ type: 'dir', name: 'a' }, { type: 'file', name: 'b' }], - })); - const dirList = await github.getSubDirectories('some-path'); - expect(get.mock.calls).toMatchSnapshot(); - expect(dirList).toHaveLength(1); - expect(dirList).toMatchSnapshot(); - }); - }); describe('commitFilesToBranch(branchName, files, message, parentBranch)', () => { beforeEach(async () => { await initRepo('some/repo', 'token'); diff --git a/test/platform/gitlab/__snapshots__/index.spec.js.snap b/test/platform/gitlab/__snapshots__/index.spec.js.snap index aeedf165a6c11c0572ef7fc1fc0a947af07ec0bc..5377e60cda61d807108e8f3b8cf99aaa25b0f676 100644 --- a/test/platform/gitlab/__snapshots__/index.spec.js.snap +++ b/test/platform/gitlab/__snapshots__/index.spec.js.snap @@ -135,11 +135,9 @@ Array [ ] `; -exports[`platform/gitlab getFile(filePath, branchName) gets the file 1`] = `"foo"`; +exports[`platform/gitlab getFile(filePath, branchName) gets the file 1`] = `"~�"`; -exports[`platform/gitlab getFileContent(filePath, branchName) gets the file 1`] = `"~�"`; - -exports[`platform/gitlab getFileContent(filePath, branchName) throws error for non-404 1`] = ` +exports[`platform/gitlab getFile(filePath, branchName) throws error for non-404 1`] = ` Object { "statusCode": 403, } @@ -207,26 +205,6 @@ Array [ ] `; -exports[`platform/gitlab getSubDirectories(path) should return subdirectories 1`] = ` -Array [ - Array [ - "projects/some%2Frepo", - ], - Array [ - "user", - ], - Array [ - "projects/some%2Frepo/repository/tree?path=some-path", - ], -] -`; - -exports[`platform/gitlab getSubDirectories(path) should return subdirectories 2`] = ` -Array [ - "a", -] -`; - exports[`platform/gitlab initRepo should initialise the config for the repo - 0 1`] = ` Array [ Array [ diff --git a/test/platform/gitlab/index.spec.js b/test/platform/gitlab/index.spec.js index d04c3f102861c4e55b9c4b28771753123d85a60f..b003cca8a8d5bf715d2b68b11c8af3abaf8ea42a 100644 --- a/test/platform/gitlab/index.spec.js +++ b/test/platform/gitlab/index.spec.js @@ -581,56 +581,25 @@ describe('platform/gitlab', () => { content: 'foo', }, }); - const res = await gitlab.getFile('some/path'); - expect(res).toMatchSnapshot(); - expect(get.mock.calls[0][0].indexOf('some%2Fpath')).not.toBe(-1); - }); - }); - describe('getFileContent(filePath, branchName)', () => { - it('gets the file', async () => { - get.mockReturnValueOnce({ - body: { - content: 'foo', - }, - }); - const res = await gitlab.getFileContent('some-path', 'some-branch'); + const res = await gitlab.getFile('some-path'); expect(res).toMatchSnapshot(); }); it('returns null for 404', async () => { get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 })); - const res = await gitlab.getFileContent('some-path', 'some-branch'); + const res = await gitlab.getFile('some-path', 'some-branch'); expect(res).toBe(null); }); it('throws error for non-404', async () => { get.mockImplementationOnce(() => Promise.reject({ statusCode: 403 })); let e; try { - await gitlab.getFileContent('some-path', 'some-branch'); + await gitlab.getFile('some-path', 'some-branch'); } catch (err) { e = err; } expect(e).toMatchSnapshot(); }); }); - describe('getFileJson(filePath, branchName)', () => { - it('returns null for 404', async () => { - get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 })); - const res = await gitlab.getFileJson('some-path', 'some-branch'); - expect(res).toBe(null); - }); - }); - describe('getSubDirectories(path)', () => { - it('should return subdirectories', async () => { - await initRepo('some/repo', 'token'); - get.mockImplementationOnce(() => ({ - body: [{ type: 'tree', name: 'a' }, { type: 'file', name: 'b' }], - })); - const dirList = await gitlab.getSubDirectories('some-path'); - expect(get.mock.calls).toMatchSnapshot(); - expect(dirList).toHaveLength(1); - expect(dirList).toMatchSnapshot(); - }); - }); describe('commitFilesToBranch(branchName, files, message, parentBranch)', () => { it('creates branch', async () => { get.mockReturnValueOnce({ statusCode: 404 }); diff --git a/test/workers/branch/lock-files.spec.js b/test/workers/branch/lock-files.spec.js index ce6a16826a0590066e94b873c501aa3e801eb2a4..7309f621180314350867c313e86f4bc4c690d67d 100644 --- a/test/workers/branch/lock-files.spec.js +++ b/test/workers/branch/lock-files.spec.js @@ -273,7 +273,7 @@ describe('workers/branch/lock-files', () => { ...defaultConfig, tmpDir: { path: 'some-tmp-dir' }, }; - platform.getFileContent.mockReturnValue('some lock file contents'); + platform.getFile.mockReturnValue('some lock file contents'); npm.generateLockFile = jest.fn(); npm.generateLockFile.mockReturnValue({ lockFile: 'some lock file contents', @@ -316,7 +316,7 @@ describe('workers/branch/lock-files', () => { expect(res.updatedLockFiles).toHaveLength(0); expect(npm.generateLockFile.mock.calls).toHaveLength(2); expect(yarn.generateLockFile.mock.calls).toHaveLength(2); - expect(platform.getFileContent.mock.calls).toHaveLength(4); + expect(platform.getFile.mock.calls).toHaveLength(4); }); it('sets error if receiving null', async () => { lockFiles.determineLockFileDirs.mockReturnValueOnce({ @@ -331,7 +331,7 @@ describe('workers/branch/lock-files', () => { expect(res.updatedLockFiles).toHaveLength(0); expect(npm.generateLockFile.mock.calls).toHaveLength(2); expect(yarn.generateLockFile.mock.calls).toHaveLength(2); - expect(platform.getFileContent.mock.calls).toHaveLength(2); + expect(platform.getFile.mock.calls).toHaveLength(2); }); it('adds multiple lock files', async () => { lockFiles.determineLockFileDirs.mockReturnValueOnce({ @@ -346,7 +346,7 @@ describe('workers/branch/lock-files', () => { expect(res.updatedLockFiles).toHaveLength(2); expect(npm.generateLockFile.mock.calls).toHaveLength(2); expect(yarn.generateLockFile.mock.calls).toHaveLength(2); - expect(platform.getFileContent.mock.calls).toHaveLength(4); + expect(platform.getFile.mock.calls).toHaveLength(4); }); }); }); diff --git a/test/workers/repository/init/config.spec.js b/test/workers/repository/init/config.spec.js index db13dd9b8622854efda753171c2368fec74234f8..8edf2a1d1a567bf2cea81a35dc7aa818c2dc4955 100644 --- a/test/workers/repository/init/config.spec.js +++ b/test/workers/repository/init/config.spec.js @@ -17,15 +17,13 @@ describe('workers/repository/init/config', () => { expect(res).toMatchObject(config); }); it('returns error if cannot parse', async () => { - platform.getFileContent.mockReturnValue('cannot parse'); + platform.getFile.mockReturnValue('cannot parse'); const res = await mergeRenovateJson(config); expect(res.errors).toHaveLength(1); expect(res.errors[0]).toMatchSnapshot(); }); it('returns error if duplicate keys', async () => { - platform.getFileContent.mockReturnValue( - '{ "enabled": true, "enabled": false }' - ); + platform.getFile.mockReturnValue('{ "enabled": true, "enabled": false }'); const res = await mergeRenovateJson(config); expect(res.errors).toHaveLength(1); expect(res.errors[0]).toMatchSnapshot(); diff --git a/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap b/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap index ae13a92323579b51acc7620eec489f63c08f7a60..ddd01de6432380f1e0a6fb73f1fc78078333ee9c 100644 --- a/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap +++ b/test/workers/repository/updates/__snapshots__/branchify.spec.js.snap @@ -2,37 +2,6 @@ exports[`workers/repository/updates/branchify branchifyUpgrades() does not group if different compiled branch names 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -566,37 +535,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`workers/repository/updates/branchify branchifyUpgrades() groups if same compiled branch names 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -1122,37 +1060,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`workers/repository/updates/branchify branchifyUpgrades() groups if same compiled group name 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -1684,37 +1591,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`workers/repository/updates/branchify branchifyUpgrades() mixes errors and warnings 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false, @@ -2241,37 +2117,6 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht exports[`workers/repository/updates/branchify branchifyUpgrades() returns one branch if one input 1`] = ` Object { - "api": Object { - "addAssignees": [Function], - "addReviewers": [Function], - "branchExists": [Function], - "commitFilesToBranch": [Function], - "createPr": [Function], - "deleteBranch": [Function], - "ensureComment": [Function], - "ensureCommentRemoval": [Function], - "findPr": [Function], - "getAllRenovateBranches": [Function], - "getBranchLastCommitTime": [Function], - "getBranchPr": [Function], - "getBranchStatus": [Function], - "getBranchStatusCheck": [Function], - "getCommitMessages": [Function], - "getFile": [Function], - "getFileContent": [Function], - "getFileJson": [Function], - "getFileList": [Function], - "getPr": [Function], - "getRepos": [Function], - "getSubDirectories": [Function], - "initRepo": [Function], - "isBranchStale": [Function], - "mergeBranch": [Function], - "mergePr": [Function], - "setBaseBranch": [Function], - "setBranchStatus": [Function], - "updatePr": [Function], - }, "assignees": Array [], "autodiscover": false, "automerge": false,