From ab0ebfeeb47fcb03b89b182eea6932d863f337fd Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sat, 4 Jul 2020 14:28:49 +0200 Subject: [PATCH] refactor: remove getFile/getFileList from platform (#6674) --- lib/manager/cargo/artifacts.spec.ts | 7 +- lib/manager/npm/post-update/index.ts | 16 +- lib/manager/npm/post-update/lerna.spec.ts | 17 +- lib/manager/npm/post-update/lerna.ts | 4 +- lib/platform/__snapshots__/index.spec.ts.snap | 8 - lib/platform/azure/index.ts | 11 -- .../__snapshots__/index.spec.ts.snap | 186 ------------------ lib/platform/bitbucket-server/index.spec.ts | 28 --- lib/platform/bitbucket-server/index.ts | 12 -- .../__snapshots__/index.spec.ts.snap | 50 ----- lib/platform/bitbucket/index.spec.ts | 28 --- lib/platform/bitbucket/index.ts | 12 -- lib/platform/common.ts | 2 - lib/platform/gitea/index.spec.ts | 19 -- lib/platform/gitea/index.ts | 10 - lib/platform/github/index.ts | 13 -- .../gitlab/__snapshots__/index.spec.ts.snap | 56 ------ lib/platform/gitlab/index.spec.ts | 22 --- lib/platform/gitlab/index.ts | 14 -- lib/workers/branch/get-updated.spec.ts | 5 +- lib/workers/branch/get-updated.ts | 7 +- lib/workers/branch/lock-files/index.spec.ts | 6 +- lib/workers/pr/code-owners.spec.ts | 20 +- lib/workers/pr/code-owners.ts | 9 +- .../repository/extract/file-match.spec.ts | 8 +- lib/workers/repository/extract/file-match.ts | 6 +- lib/workers/repository/extract/index.spec.ts | 5 +- lib/workers/repository/init/config.spec.ts | 30 ++- lib/workers/repository/init/config.ts | 4 +- .../repository/onboarding/branch/check.ts | 3 +- .../onboarding/branch/index.spec.ts | 18 +- .../onboarding/branch/rebase.spec.ts | 5 +- .../repository/onboarding/branch/rebase.ts | 3 +- 33 files changed, 87 insertions(+), 557 deletions(-) diff --git a/lib/manager/cargo/artifacts.spec.ts b/lib/manager/cargo/artifacts.spec.ts index 8d1cbd004d..92fb548a64 100644 --- a/lib/manager/cargo/artifacts.spec.ts +++ b/lib/manager/cargo/artifacts.spec.ts @@ -2,7 +2,7 @@ import { exec as _exec } from 'child_process'; import _fs from 'fs-extra'; import { join } from 'upath'; import { envMock, mockExecAll } from '../../../test/execUtil'; -import { mocked, platform } from '../../../test/util'; +import { git, mocked } from '../../../test/util'; import { setExecConfig } from '../../util/exec'; import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; @@ -12,6 +12,7 @@ import * as cargo from './artifacts'; jest.mock('fs-extra'); jest.mock('child_process'); jest.mock('../../util/exec/env'); +jest.mock('../../util/git'); jest.mock('../../util/http'); const fs: jest.Mocked<typeof _fs> = _fs as any; @@ -70,7 +71,7 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('returns updated Cargo.lock', async () => { - platform.getFile.mockResolvedValueOnce('Old Cargo.lock'); + git.getFile.mockResolvedValueOnce('Old Cargo.lock'); const execSnapshots = mockExecAll(exec); fs.readFile.mockResolvedValueOnce('New Cargo.lock' as any); const updatedDeps = ['dep1']; @@ -87,7 +88,7 @@ describe('.updateArtifacts()', () => { it('returns updated Cargo.lock with docker', async () => { jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); await setExecConfig({ ...config, binarySource: BinarySource.Docker }); - platform.getFile.mockResolvedValueOnce('Old Cargo.lock'); + git.getFile.mockResolvedValueOnce('Old Cargo.lock'); const execSnapshots = mockExecAll(exec); fs.readFile.mockResolvedValueOnce('New Cargo.lock' as any); const updatedDeps = ['dep1']; diff --git a/lib/manager/npm/post-update/index.ts b/lib/manager/npm/post-update/index.ts index e045777b4f..072f947eb1 100644 --- a/lib/manager/npm/post-update/index.ts +++ b/lib/manager/npm/post-update/index.ts @@ -16,7 +16,7 @@ import { platform } from '../../../platform'; import { ExternalHostError } from '../../../types/errors/external-host-error'; import { getChildProcessEnv } from '../../../util/exec/env'; import { deleteLocalFile } from '../../../util/fs'; -import { getRepoStatus } from '../../../util/git'; +import { getFile, getRepoStatus } from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; import { PackageFile, PostUpdateConfig, Upgrade } from '../../common'; import * as lerna from './lerna'; @@ -172,7 +172,7 @@ export async function writeExistingFiles( await remove(npmLockPath); } else { logger.debug(`Writing ${npmLock}`); - let existingNpmLock = await platform.getFile(npmLock); + let existingNpmLock = await getFile(npmLock); const widens = []; for (const upgrade of config.upgrades) { if ( @@ -450,7 +450,7 @@ export async function getAdditionalFiles( stderr: res.stderr, }); } else { - const existingContent = await platform.getFile( + const existingContent = await getFile( lockFile, config.reuseExistingBranch ? config.branchName : config.baseBranch ); @@ -516,7 +516,7 @@ export async function getAdditionalFiles( stderr: res.stderr, }); } else { - const existingContent = await platform.getFile( + const existingContent = await getFile( lockFileName, config.reuseExistingBranch ? config.branchName : config.baseBranch ); @@ -528,9 +528,7 @@ export async function getAdditionalFiles( }); // istanbul ignore next try { - const yarnrc = await platform.getFile( - upath.join(lockFileDir, '.yarnrc') - ); + const yarnrc = await getFile(upath.join(lockFileDir, '.yarnrc')); if (yarnrc) { const mirrorLine = yarnrc .split('\n') @@ -618,7 +616,7 @@ export async function getAdditionalFiles( stderr: res.stderr, }); } else { - const existingContent = await platform.getFile( + const existingContent = await getFile( lockFile, config.reuseExistingBranch ? config.branchName : config.baseBranch ); @@ -716,7 +714,7 @@ export async function getAdditionalFiles( for (const packageFile of packageFiles.npm) { const filename = packageFile.npmLock || packageFile.yarnLock; logger.trace('Checking for ' + filename); - const existingContent = await platform.getFile( + const existingContent = await getFile( filename, config.reuseExistingBranch ? config.branchName : config.baseBranch ); diff --git a/lib/manager/npm/post-update/lerna.spec.ts b/lib/manager/npm/post-update/lerna.spec.ts index 49cc2015a2..b626c53fd6 100644 --- a/lib/manager/npm/post-update/lerna.spec.ts +++ b/lib/manager/npm/post-update/lerna.spec.ts @@ -1,18 +1,17 @@ import { exec as _exec } from 'child_process'; import { envMock, mockExecAll } from '../../../../test/execUtil'; -import { mocked } from '../../../../test/util'; -import { platform as _platform } from '../../../platform'; +import { git, mocked } from '../../../../test/util'; import * as _env from '../../../util/exec/env'; import * as _lernaHelper from './lerna'; jest.mock('child_process'); jest.mock('../../../util/exec/env'); +jest.mock('../../../util/git'); jest.mock('../../../manager/npm/post-update/node-version'); const exec: jest.Mock<typeof _exec> = _exec as any; const env = mocked(_env); const lernaHelper = mocked(_lernaHelper); -const platform = mocked(_platform); describe('generateLockFiles()', () => { beforeEach(() => { @@ -34,7 +33,7 @@ describe('generateLockFiles()', () => { expect(res.error).toBe(false); }); it('generates package-lock.json files', async () => { - platform.getFile.mockResolvedValueOnce( + git.getFile.mockResolvedValueOnce( JSON.stringify({ dependencies: { lerna: '2.0.0' } }) ); const execSnapshots = mockExecAll(exec); @@ -50,7 +49,7 @@ describe('generateLockFiles()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('performs full npm install', async () => { - platform.getFile.mockResolvedValueOnce( + git.getFile.mockResolvedValueOnce( JSON.stringify({ dependencies: { lerna: '2.0.0' } }) ); const execSnapshots = mockExecAll(exec); @@ -66,7 +65,7 @@ describe('generateLockFiles()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('generates yarn.lock files', async () => { - platform.getFile.mockResolvedValueOnce( + git.getFile.mockResolvedValueOnce( JSON.stringify({ devDependencies: { lerna: '2.0.0' } }) ); const execSnapshots = mockExecAll(exec); @@ -80,14 +79,14 @@ describe('generateLockFiles()', () => { expect(res.error).toBe(false); }); it('defaults to latest', async () => { - platform.getFile.mockReturnValueOnce(undefined); + git.getFile.mockReturnValueOnce(undefined); const execSnapshots = mockExecAll(exec); const res = await lernaHelper.generateLockFiles('npm', 'some-dir', {}, {}); expect(res.error).toBe(false); expect(execSnapshots).toMatchSnapshot(); }); it('maps dot files', async () => { - platform.getFile.mockReturnValueOnce(undefined); + git.getFile.mockReturnValueOnce(undefined); const execSnapshots = mockExecAll(exec); const res = await lernaHelper.generateLockFiles( 'npm', @@ -102,7 +101,7 @@ describe('generateLockFiles()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('allows scripts for trust level high', async () => { - platform.getFile.mockReturnValueOnce(undefined); + git.getFile.mockReturnValueOnce(undefined); const execSnapshots = mockExecAll(exec); global.trustLevel = 'high'; const res = await lernaHelper.generateLockFiles('npm', 'some-dir', {}, {}); diff --git a/lib/manager/npm/post-update/lerna.ts b/lib/manager/npm/post-update/lerna.ts index 2a7607ecf9..dbf1fa5a91 100644 --- a/lib/manager/npm/post-update/lerna.ts +++ b/lib/manager/npm/post-update/lerna.ts @@ -2,8 +2,8 @@ import semver, { validRange } from 'semver'; import { quote } from 'shlex'; import { join } from 'upath'; import { logger } from '../../../logger'; -import { platform } from '../../../platform'; import { ExecOptions, exec } from '../../../util/exec'; +import { getFile } from '../../../util/git'; import { PostUpdateConfig } from '../../common'; import { getNodeConstraint } from './node-version'; import { optimizeCommand } from './yarn'; @@ -84,7 +84,7 @@ export async function generateLockFiles( cmd.push(`${lernaClient} install ${cmdOptions}`); let lernaVersion: string; try { - const pJson = JSON.parse(await platform.getFile('package.json')); + const pJson = JSON.parse(await getFile('package.json')); lernaVersion = (pJson.dependencies && pJson.dependencies.lerna) || (pJson.devDependencies && pJson.devDependencies.lerna); diff --git a/lib/platform/__snapshots__/index.spec.ts.snap b/lib/platform/__snapshots__/index.spec.ts.snap index c14467a75f..f2e74e054f 100644 --- a/lib/platform/__snapshots__/index.spec.ts.snap +++ b/lib/platform/__snapshots__/index.spec.ts.snap @@ -23,8 +23,6 @@ Array [ "getBranchStatus", "getBranchStatusCheck", "getCommitMessages", - "getFile", - "getFileList", "getIssueList", "getPr", "getPrBody", @@ -66,8 +64,6 @@ Array [ "getBranchStatus", "getBranchStatusCheck", "getCommitMessages", - "getFile", - "getFileList", "getIssueList", "getPr", "getPrBody", @@ -109,8 +105,6 @@ Array [ "getBranchStatus", "getBranchStatusCheck", "getCommitMessages", - "getFile", - "getFileList", "getIssueList", "getPr", "getPrBody", @@ -152,8 +146,6 @@ Array [ "getBranchStatus", "getBranchStatusCheck", "getCommitMessages", - "getFile", - "getFileList", "getIssueList", "getPr", "getPrBody", diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 14b50d0acd..cb1c853036 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -184,10 +184,6 @@ export function getRepoForceRebase(): Promise<boolean> { // Search -export /* istanbul ignore next */ function getFileList(): Promise<string[]> { - return git.getFileList(); -} - export /* istanbul ignore next */ async function setBaseBranch( branchName = config.baseBranch ): Promise<string> { @@ -224,13 +220,6 @@ export /* istanbul ignore next */ function isBranchStale( return git.isBranchStale(branchName); } -export /* istanbul ignore next */ function getFile( - filePath: string, - branchName: string -): Promise<string> { - return git.getFile(filePath, branchName); -} - // istanbul ignore next async function abandonPr(prNo: number): Promise<void> { logger.debug(`abandonPr(prNo)(${prNo})`); diff --git a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap index d0f10c2bb9..3da1444b7a 100644 --- a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap @@ -546,37 +546,6 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with no path branchExists() getFileList() sends to gitFs 1`] = `true`; - -exports[`platform/bitbucket-server endpoint with no path branchExists() getFileList() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - exports[`platform/bitbucket-server endpoint with no path commitFiles() sends to gitFs 1`] = ` Array [ Object { @@ -2112,68 +2081,6 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with no path getFile() sends to gitFs 1`] = `undefined`; - -exports[`platform/bitbucket-server endpoint with no path getFile() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - -exports[`platform/bitbucket-server endpoint with no path getFileList() sends to gitFs 1`] = `undefined`; - -exports[`platform/bitbucket-server endpoint with no path getFileList() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - exports[`platform/bitbucket-server endpoint with no path getPr() canRebase 1`] = ` Object { "body": "* Line 1 @@ -4697,37 +4604,6 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with path branchExists() getFileList() sends to gitFs 1`] = `true`; - -exports[`platform/bitbucket-server endpoint with path branchExists() getFileList() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - exports[`platform/bitbucket-server endpoint with path commitFiles() sends to gitFs 1`] = ` Array [ Object { @@ -6263,68 +6139,6 @@ Array [ ] `; -exports[`platform/bitbucket-server endpoint with path getFile() sends to gitFs 1`] = `undefined`; - -exports[`platform/bitbucket-server endpoint with path getFile() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - -exports[`platform/bitbucket-server endpoint with path getFileList() sends to gitFs 1`] = `undefined`; - -exports[`platform/bitbucket-server endpoint with path getFileList() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "stash.renovatebot.com", - "user-agent": "https://github.com/renovatebot/renovate", - "x-atlassian-token": "no-check", - }, - "method": "GET", - "url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/branches/default", - }, -] -`; - exports[`platform/bitbucket-server endpoint with path getPr() canRebase 1`] = ` Object { "body": "* Line 1 diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index 7b5a659695..f6fb4eb626 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -400,26 +400,6 @@ describe('platform/bitbucket-server', () => { }); }); - describe('getFileList()', () => { - it('sends to gitFs', async () => { - await initRepo(); - expect(await bitbucket.getFileList()).toMatchSnapshot(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - - describe('branchExists()', () => { - describe('getFileList()', () => { - it('sends to gitFs', async () => { - await initRepo(); - expect( - await bitbucket.branchExists(undefined as any) - ).toMatchSnapshot(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - }); - describe('isBranchStale()', () => { it('sends to gitFs', async () => { await initRepo(); @@ -467,14 +447,6 @@ describe('platform/bitbucket-server', () => { }); }); - describe('getFile()', () => { - it('sends to gitFs', async () => { - await initRepo(); - expect(await bitbucket.getFile('', '')).toMatchSnapshot(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - describe('getAllRenovateBranches()', () => { it('sends to gitFs', async () => { await initRepo(); diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 100f159e3e..fa901ac28d 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -253,13 +253,6 @@ export /* istanbul ignore next */ function setBranchPrefix( return git.setBranchPrefix(branchPrefix); } -// Search - -// Get full file list -export function getFileList(): Promise<string[]> { - return git.getFileList(); -} - // Branch // Returns true if branch exists, otherwise false @@ -447,11 +440,6 @@ export async function commitFiles( return commit; } -export function getFile(filePath: string, branchName: string): Promise<string> { - logger.debug(`getFile(${filePath}, ${branchName})`); - return git.getFile(filePath, branchName); -} - export async function deleteBranch( branchName: string, closePr = false diff --git a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap index 486fdd173b..5bb9d7dac1 100644 --- a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap @@ -64,22 +64,6 @@ Array [ ] `; -exports[`platform/bitbucket branchExists() getFileList() sends to gitFs 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "api.bitbucket.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://api.bitbucket.org/2.0/repositories/some/repo", - }, -] -`; - exports[`platform/bitbucket commitFiles() sends to gitFs 1`] = `undefined`; exports[`platform/bitbucket commitFiles() sends to gitFs 2`] = ` @@ -989,40 +973,6 @@ Array [ ] `; -exports[`platform/bitbucket getFile() sends to gitFs 1`] = `undefined`; - -exports[`platform/bitbucket getFile() sends to gitFs 2`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "api.bitbucket.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://api.bitbucket.org/2.0/repositories/some/repo", - }, -] -`; - -exports[`platform/bitbucket getFileList() sends to gitFs 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "authorization": "Basic YWJjOjEyMw==", - "host": "api.bitbucket.org", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://api.bitbucket.org/2.0/repositories/some/repo", - }, -] -`; - exports[`platform/bitbucket getPr() canRebase 1`] = ` Object { "body": "summary", diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index 63059d005d..826b11d4e1 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -194,26 +194,6 @@ describe('platform/bitbucket', () => { }); }); - describe('getFileList()', () => { - it('sends to gitFs', async () => { - await initRepoMock(); - const fileList = await bitbucket.getFileList(); - expect(fileList).not.toBeNull(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - - describe('branchExists()', () => { - describe('getFileList()', () => { - it('sends to gitFs', async () => { - await initRepoMock(); - const branchExists = await bitbucket.branchExists('test'); - expect(branchExists).toEqual(true); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - }); - describe('isBranchStale()', () => { it('sends to gitFs', async () => { await initRepoMock(); @@ -846,14 +826,6 @@ describe('platform/bitbucket', () => { }); }); - describe('getFile()', () => { - it('sends to gitFs', async () => { - await initRepoMock(); - expect(await bitbucket.getFile('test.file')).toMatchSnapshot(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - describe('getCommitMessages()', () => { it('sends to gitFs', async () => { await initRepoMock(); diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 4e12052e5c..0348c5a057 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -177,11 +177,6 @@ export function getRepoForceRebase(): Promise<boolean> { // Search -// Get full file list -export function getFileList(): Promise<string[]> { - return git.getFileList(); -} - export async function setBaseBranch( branchName = config.baseBranch ): Promise<string> { @@ -215,13 +210,6 @@ export function isBranchStale(branchName: string): Promise<boolean> { return git.isBranchStale(branchName); } -export function getFile( - filePath: string, - branchName?: string -): Promise<string> { - return git.getFile(filePath, branchName); -} - // istanbul ignore next function matchesState(state: string, desiredState: string): boolean { if (desiredState === PR_STATE_ALL) { diff --git a/lib/platform/common.ts b/lib/platform/common.ts index 5c13b20183..32e9df9841 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -193,7 +193,6 @@ export interface Platform { getPrFiles(pr: Pr): Promise<string[]>; getAllRenovateBranches(branchPrefix: string): Promise<string[]>; ensureIssueClosing(title: string): Promise<void>; - getFileList(): Promise<string[]>; ensureIssue( issueConfig: EnsureIssueConfig ): Promise<EnsureIssueResult | null>; @@ -231,6 +230,5 @@ export interface Platform { requiredStatusChecks?: string[] | null ): Promise<BranchStatus>; getBranchPr(branchName: string): Promise<Pr | null>; - getFile(lockFileName: string, branchName?: string): Promise<string | null>; initPlatform(config: RenovateConfig): Promise<PlatformConfig>; } diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index 91768cd9ad..0df4a21569 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -1414,25 +1414,6 @@ describe('platform/gitea', () => { }); }); - describe('getFile', () => { - it('should propagate call to storage class', async () => { - await initFakeRepo(); - await gitea.getFile('some-file', 'some-branch'); - - expect(gitvcs.getFile).toHaveBeenCalledTimes(1); - expect(gitvcs.getFile).toHaveBeenCalledWith('some-file', 'some-branch'); - }); - }); - - describe('getFileList', () => { - it('propagates call to storage class', async () => { - await initFakeRepo(); - await gitea.getFileList(); - - expect(gitvcs.getFileList).toHaveBeenCalledTimes(1); - }); - }); - describe('getAllRenovateBranches', () => { it('should propagate call to storage class', async () => { await initFakeRepo(); diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index 8aebee95c0..f28be8edaf 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -878,14 +878,6 @@ const platform: Platform = { return git.getBranchLastCommitTime(branchName); }, - getFile(lockFileName: string, branchName?: string): Promise<string> { - return git.getFile(lockFileName, branchName); - }, - - getFileList(): Promise<string[]> { - return git.getFileList(); - }, - getAllRenovateBranches(branchPrefix: string): Promise<string[]> { return git.getAllRenovateBranches(branchPrefix); }, @@ -919,8 +911,6 @@ export const { getBranchStatus, getBranchStatusCheck, getCommitMessages, - getFile, - getFileList, getIssueList, getPr, getPrBody, diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 2302bf6f3d..144cbcedad 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -495,11 +495,6 @@ export function setBranchPrefix(branchPrefix: string): Promise<void> { // Search -// istanbul ignore next -export function getFileList(): Promise<string[]> { - return git.getFileList(); -} - // Branch // istanbul ignore next @@ -519,14 +514,6 @@ export function isBranchStale(branchName: string): Promise<boolean> { return git.isBranchStale(branchName); } -// istanbul ignore next -export function getFile( - filePath: string, - branchName?: string -): Promise<string> { - return git.getFile(filePath, branchName); -} - // istanbul ignore next export function deleteBranch( branchName: string, diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index 6fe7bf60c6..49186e996c 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -148,33 +148,6 @@ Array [ exports[`platform/gitlab addReviewers(issueNo, reviewers) should add the given reviewers to the PR 1`] = `Array []`; -exports[`platform/gitlab branchExists() getFileList() sends to gitFs 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/projects/some%2Frepo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, -] -`; - exports[`platform/gitlab commitFiles() sends to gitFs 1`] = ` Array [ Object { @@ -1492,35 +1465,6 @@ Array [ exports[`platform/gitlab getCommitMessages() passes to git 1`] = `undefined`; -exports[`platform/gitlab getFile() sends to gitFs 1`] = `undefined`; - -exports[`platform/gitlab getFileList() sends to gitFs 1`] = ` -Array [ - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/projects/some%2Frepo", - }, - Object { - "headers": Object { - "accept": "application/json", - "accept-encoding": "gzip, deflate", - "host": "gitlab.com", - "private-token": "abc123", - "user-agent": "https://github.com/renovatebot/renovate", - }, - "method": "GET", - "url": "https://gitlab.com/api/v4/user", - }, -] -`; - exports[`platform/gitlab getPr(prNo) returns the PR 1`] = ` Object { "body": "a merge request", diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index 438e1873ff..fa323cbbb1 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -387,22 +387,6 @@ describe('platform/gitlab', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); }); - describe('getFileList()', () => { - it('sends to gitFs', async () => { - await initRepo(); - await gitlab.getFileList(); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - describe('branchExists()', () => { - describe('getFileList()', () => { - it('sends to gitFs', async () => { - await initRepo(); - await gitlab.branchExists(''); - expect(httpMock.getTrace()).toMatchSnapshot(); - }); - }); - }); describe('getAllRenovateBranches()', () => { it('sends to gitFs', async () => { await initRepo(); @@ -1225,12 +1209,6 @@ These updates have all been created already. Click a checkbox below to force a r expect(gitlab.getPrBody(prBody)).toMatchSnapshot(); }); }); - describe('getFile()', () => { - it('sends to gitFs', async () => { - await initRepo(); - expect(await gitlab.getFile('')).toMatchSnapshot(); - }); - }); describe('commitFiles()', () => { it('sends to gitFs', async () => { expect.assertions(1); diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 739b43b945..f83527d874 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -286,13 +286,6 @@ export /* istanbul ignore next */ function setBranchPrefix( return git.setBranchPrefix(branchPrefix); } -// Search - -// Get full file list -export function getFileList(): Promise<string[]> { - return git.getFileList(); -} - // Returns true if branch exists, otherwise false export function branchExists(branchName: string): Promise<boolean> { return git.branchExists(branchName); @@ -631,13 +624,6 @@ export function commitFiles( return git.commitFiles(commitFilesConfig); } -export function getFile( - filePath: string, - branchName?: string -): Promise<string> { - return git.getFile(filePath, branchName); -} - export async function deleteBranch( branchName: string, shouldClosePr = false diff --git a/lib/workers/branch/get-updated.spec.ts b/lib/workers/branch/get-updated.spec.ts index 770269fe8b..70e12e2a88 100644 --- a/lib/workers/branch/get-updated.spec.ts +++ b/lib/workers/branch/get-updated.spec.ts @@ -1,4 +1,4 @@ -import { defaultConfig, mocked, platform } from '../../../test/util'; +import { defaultConfig, git, mocked } from '../../../test/util'; import * as datasourceGitSubmodules from '../../datasource/git-submodules'; import * as _composer from '../../manager/composer'; import * as _gitSubmodules from '../../manager/git-submodules'; @@ -15,6 +15,7 @@ const autoReplace = mocked(_autoReplace); jest.mock('../../manager/composer'); jest.mock('../../manager/npm'); jest.mock('../../manager/git-submodules'); +jest.mock('../../util/git'); jest.mock('./auto-replace'); describe('workers/branch/get-updated', () => { @@ -26,7 +27,7 @@ describe('workers/branch/get-updated', () => { upgrades: [], } as never; npm.updateDependency = jest.fn(); - platform.getFile.mockResolvedValueOnce('existing content'); + git.getFile.mockResolvedValueOnce('existing content'); }); it('handles autoreplace base updated', async () => { config.upgrades.push({ manager: 'html', branchName: undefined }); diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index 569dd61af9..3d5f64e37b 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -4,7 +4,8 @@ import * as datasourceGitSubmodules from '../../datasource/git-submodules'; import { logger } from '../../logger'; import { get } from '../../manager'; import { ArtifactError } from '../../manager/common'; -import { File, platform } from '../../platform'; +import { File } from '../../platform'; +import { getFile } from '../../util/git'; import { BranchConfig } from '../common'; import { doAutoReplace } from './auto-replace'; @@ -39,7 +40,7 @@ export async function getUpdatedPackageFiles( } else { let existingContent = updatedFileContents[packageFile]; if (!existingContent) { - existingContent = await platform.getFile( + existingContent = await getFile( packageFile, reuseExistingBranch ? config.branchName : config.baseBranch ); @@ -160,7 +161,7 @@ export async function getUpdatedPackageFiles( if (updateArtifacts) { const packageFileContents = updatedFileContents[packageFile] || - (await platform.getFile( + (await getFile( packageFile, config.reuseExistingBranch ? config.branchName : config.baseBranch )); diff --git a/lib/workers/branch/lock-files/index.spec.ts b/lib/workers/branch/lock-files/index.spec.ts index 7f2db89b45..4637d34e31 100644 --- a/lib/workers/branch/lock-files/index.spec.ts +++ b/lib/workers/branch/lock-files/index.spec.ts @@ -1,5 +1,5 @@ import _fs from 'fs-extra'; -import { mocked } from '../../../../test/util'; +import { git, mocked } from '../../../../test/util'; import { getConfig } from '../../../config/defaults'; import { PostUpdateConfig } from '../../../manager/common'; import * as _lockFiles from '../../../manager/npm/post-update'; @@ -21,6 +21,8 @@ const lerna = mocked(_lerna); const hostRules = mocked(_hostRules); const platform = mocked(_platform); +jest.mock('../../../util/git'); + hostRules.find = jest.fn((_) => ({ token: 'abc', })); @@ -76,7 +78,7 @@ describe('manager/npm/post-update', () => { ...defaultConfig, localDir: 'some-tmp-dir', }; - platform.getFile.mockResolvedValueOnce('some lock file contents'); + git.getFile.mockResolvedValueOnce('some lock file contents'); npm.generateLockFile = jest.fn(); npm.generateLockFile.mockResolvedValueOnce({ lockFile: 'some lock file contents', diff --git a/lib/workers/pr/code-owners.spec.ts b/lib/workers/pr/code-owners.spec.ts index 9e24673a0e..c1d8ac782a 100644 --- a/lib/workers/pr/code-owners.spec.ts +++ b/lib/workers/pr/code-owners.spec.ts @@ -1,8 +1,10 @@ import { mock } from 'jest-mock-extended'; -import { platform } from '../../../test/util'; +import { git, platform } from '../../../test/util'; import { Pr } from '../../platform'; import { codeOwnersForPr } from './code-owners'; +jest.mock('../../util/git'); + describe('workers/pr/code-owners', () => { describe('codeOwnersForPr', () => { let pr: Pr; @@ -11,13 +13,13 @@ describe('workers/pr/code-owners', () => { pr = mock<Pr>(); }); it('returns global code owner', async () => { - platform.getFile.mockResolvedValueOnce(['* @jimmy'].join('\n')); + git.getFile.mockResolvedValueOnce(['* @jimmy'].join('\n')); platform.getPrFiles.mockResolvedValueOnce(['README.md']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual(['@jimmy']); }); it('returns more specific code owners', async () => { - platform.getFile.mockResolvedValueOnce( + git.getFile.mockResolvedValueOnce( ['* @jimmy', 'package.json @john @maria'].join('\n') ); platform.getPrFiles.mockResolvedValueOnce(['package.json']); @@ -25,7 +27,7 @@ describe('workers/pr/code-owners', () => { expect(codeOwners).toEqual(['@john', '@maria']); }); it('ignores comments and leading/trailing whitespace', async () => { - platform.getFile.mockResolvedValueOnce( + git.getFile.mockResolvedValueOnce( [ '# comment line', ' \t ', @@ -39,21 +41,19 @@ describe('workers/pr/code-owners', () => { expect(codeOwners).toEqual(['@john', '@maria']); }); it('returns empty array when no code owners set', async () => { - platform.getFile.mockResolvedValueOnce(null); + git.getFile.mockResolvedValueOnce(null); platform.getPrFiles.mockResolvedValueOnce(['package.json']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual([]); }); it('returns empty array when no code owners match', async () => { - platform.getFile.mockResolvedValueOnce( - ['package-lock.json @mike'].join('\n') - ); + git.getFile.mockResolvedValueOnce(['package-lock.json @mike'].join('\n')); platform.getPrFiles.mockResolvedValueOnce(['yarn.lock']); const codeOwners = await codeOwnersForPr(pr); expect(codeOwners).toEqual([]); }); it('returns empty array when error occurs', async () => { - platform.getFile.mockImplementationOnce((_, __) => { + git.getFile.mockImplementationOnce((_, __) => { throw new Error(); }); const codeOwners = await codeOwnersForPr(pr); @@ -67,7 +67,7 @@ describe('workers/pr/code-owners', () => { ]; codeOwnerFilePaths.forEach((codeOwnerFilePath) => { it(`detects code owner file at '${codeOwnerFilePath}'`, async () => { - platform.getFile.mockImplementation((path, _) => { + git.getFile.mockImplementation((path, _) => { if (path === codeOwnerFilePath) { return Promise.resolve(['* @mike'].join('\n')); } diff --git a/lib/workers/pr/code-owners.ts b/lib/workers/pr/code-owners.ts index 1f5090e39d..5945b9cc8d 100644 --- a/lib/workers/pr/code-owners.ts +++ b/lib/workers/pr/code-owners.ts @@ -1,14 +1,15 @@ import ignore from 'ignore'; import { logger } from '../../logger'; import { Pr, platform } from '../../platform'; +import { getFile } from '../../util/git'; export async function codeOwnersForPr(pr: Pr): Promise<string[]> { try { const codeOwnersFile = - (await platform.getFile('CODEOWNERS', pr.targetBranch)) || - (await platform.getFile('.github/CODEOWNERS', pr.targetBranch)) || - (await platform.getFile('.gitlab/CODEOWNERS', pr.targetBranch)) || - (await platform.getFile('docs/CODEOWNERS', pr.targetBranch)); + (await getFile('CODEOWNERS', pr.targetBranch)) || + (await getFile('.github/CODEOWNERS', pr.targetBranch)) || + (await getFile('.gitlab/CODEOWNERS', pr.targetBranch)) || + (await getFile('docs/CODEOWNERS', pr.targetBranch)); if (!codeOwnersFile) { return []; diff --git a/lib/workers/repository/extract/file-match.spec.ts b/lib/workers/repository/extract/file-match.spec.ts index d4d8424d68..cef8ce0b55 100644 --- a/lib/workers/repository/extract/file-match.spec.ts +++ b/lib/workers/repository/extract/file-match.spec.ts @@ -1,6 +1,8 @@ -import { RenovateConfig, platform } from '../../../../test/util'; +import { RenovateConfig, git } from '../../../../test/util'; import * as fileMatch from './file-match'; +jest.mock('../../../util/git'); + describe('workers/repository/extract/file-match', () => { const fileList = ['package.json', 'frontend/package.json']; describe('getIncludedFiles()', () => { @@ -47,14 +49,14 @@ describe('workers/repository/extract/file-match', () => { fileMatch: ['(^|/)package.json$'], }; it('returns npm files', async () => { - platform.getFileList.mockResolvedValue(fileList); + git.getFileList.mockResolvedValue(fileList); fileList.push('Dockerfile'); const res = await fileMatch.getMatchingFiles(config); expect(res).toMatchSnapshot(); expect(res).toHaveLength(2); }); it('deduplicates', async () => { - platform.getFileList.mockResolvedValue(fileList); + git.getFileList.mockResolvedValue(fileList); config.fileMatch.push('package.json'); const res = await fileMatch.getMatchingFiles(config); expect(res).toMatchSnapshot(); diff --git a/lib/workers/repository/extract/file-match.ts b/lib/workers/repository/extract/file-match.ts index b07a08994e..1f2c37b840 100644 --- a/lib/workers/repository/extract/file-match.ts +++ b/lib/workers/repository/extract/file-match.ts @@ -1,7 +1,7 @@ import minimatch from 'minimatch'; import { RenovateConfig } from '../../../config/common'; import { logger } from '../../../logger'; -import { platform } from '../../../platform'; +import { getFileList } from '../../../util/git'; import { regEx } from '../../../util/regex'; export function getIncludedFiles( @@ -36,10 +36,6 @@ export function filterIgnoredFiles( ); } -export function getFileList(): Promise<string[]> { - return platform.getFileList(); -} - export function getFilteredFileList( config: RenovateConfig, fileList: string[] diff --git a/lib/workers/repository/extract/index.spec.ts b/lib/workers/repository/extract/index.spec.ts index 90e5952d9a..fdfff9e516 100644 --- a/lib/workers/repository/extract/index.spec.ts +++ b/lib/workers/repository/extract/index.spec.ts @@ -1,9 +1,10 @@ -import { defaultConfig, mocked, platform } from '../../../../test/util'; +import { defaultConfig, git, mocked } from '../../../../test/util'; import { RenovateConfig } from '../../../config'; import * as _managerFiles from './manager-files'; import { extractAllDependencies } from '.'; jest.mock('./manager-files'); +jest.mock('../../../util/git'); const managerFiles = mocked(_managerFiles); @@ -13,7 +14,7 @@ describe('workers/repository/extract/index', () => { const fileList = ['README', 'package.json', 'tasks/ansible.yaml']; beforeEach(() => { jest.resetAllMocks(); - platform.getFileList.mockResolvedValue(fileList); + git.getFileList.mockResolvedValue(fileList); config = { ...defaultConfig }; }); it('runs', async () => { diff --git a/lib/workers/repository/init/config.spec.ts b/lib/workers/repository/init/config.spec.ts index 38a3c5e880..736f650778 100644 --- a/lib/workers/repository/init/config.spec.ts +++ b/lib/workers/repository/init/config.spec.ts @@ -2,13 +2,14 @@ import { RenovateConfig, fs, getConfig, + git, mocked, - platform, } from '../../../../test/util'; import * as _migrateAndValidate from '../../../config/migrate-validate'; import { mergeRenovateConfig } from './config'; jest.mock('../../../util/fs'); +jest.mock('../../../util/git'); const migrateAndValidate = mocked(_migrateAndValidate); @@ -31,13 +32,13 @@ describe('workers/repository/init/config', () => { }); }); it('returns config if not found', async () => { - platform.getFileList.mockResolvedValue(['package.json']); + git.getFileList.mockResolvedValue(['package.json']); fs.readLocalFile.mockResolvedValue('{}'); const res = await mergeRenovateConfig(config); expect(res).toMatchObject(config); }); it('uses package.json config if found', async () => { - platform.getFileList.mockResolvedValue(['package.json']); + git.getFileList.mockResolvedValue(['package.json']); const pJson = JSON.stringify({ name: 'something', renovate: { @@ -49,7 +50,7 @@ describe('workers/repository/init/config', () => { expect(renovateConfig).toBeTruthy(); }); it('returns error if cannot parse', async () => { - platform.getFileList.mockResolvedValue(['package.json', 'renovate.json']); + git.getFileList.mockResolvedValue(['package.json', 'renovate.json']); fs.readLocalFile.mockResolvedValue('cannot parse'); let e; try { @@ -63,7 +64,7 @@ describe('workers/repository/init/config', () => { expect(e.validationMessage).toMatchSnapshot(); }); it('throws error if duplicate keys', async () => { - platform.getFileList.mockResolvedValue(['package.json', '.renovaterc']); + git.getFileList.mockResolvedValue(['package.json', '.renovaterc']); fs.readLocalFile.mockResolvedValue( '{ "enabled": true, "enabled": false }' ); @@ -79,10 +80,7 @@ describe('workers/repository/init/config', () => { expect(e.validationMessage).toMatchSnapshot(); }); it('finds and parse renovate.json5', async () => { - platform.getFileList.mockResolvedValue([ - 'package.json', - 'renovate.json5', - ]); + git.getFileList.mockResolvedValue(['package.json', 'renovate.json5']); fs.readLocalFile.mockResolvedValue(`{ // this is json5 format }`); @@ -90,7 +88,7 @@ describe('workers/repository/init/config', () => { expect(renovateConfig).toBeTruthy(); }); it('finds .github/renovate.json', async () => { - platform.getFileList.mockResolvedValue([ + git.getFileList.mockResolvedValue([ 'package.json', '.github/renovate.json', ]); @@ -99,7 +97,7 @@ describe('workers/repository/init/config', () => { expect(renovateConfig).toBeTruthy(); }); it('finds .gitlab/renovate.json', async () => { - platform.getFileList.mockResolvedValue([ + git.getFileList.mockResolvedValue([ 'package.json', '.gitlab/renovate.json', ]); @@ -108,19 +106,13 @@ describe('workers/repository/init/config', () => { expect(renovateConfig).toBeTruthy(); }); it('finds .renovaterc.json', async () => { - platform.getFileList.mockResolvedValue([ - 'package.json', - '.renovaterc.json', - ]); + git.getFileList.mockResolvedValue(['package.json', '.renovaterc.json']); fs.readLocalFile.mockResolvedValue('{}'); const renovateConfig = await mergeRenovateConfig(config); expect(renovateConfig).toBeTruthy(); }); it('throws error if misconfigured', async () => { - platform.getFileList.mockResolvedValue([ - 'package.json', - '.renovaterc.json', - ]); + git.getFileList.mockResolvedValue(['package.json', '.renovaterc.json']); fs.readLocalFile.mockResolvedValue('{}'); migrateAndValidate.migrateAndValidate.mockResolvedValueOnce({ errors: [{ depName: 'dep', message: 'test error' }], diff --git a/lib/workers/repository/init/config.ts b/lib/workers/repository/init/config.ts index 68bce6f6bc..4768afc10c 100644 --- a/lib/workers/repository/init/config.ts +++ b/lib/workers/repository/init/config.ts @@ -10,11 +10,11 @@ import * as presets from '../../../config/presets'; import { CONFIG_VALIDATION } from '../../../constants/error-messages'; import * as npmApi from '../../../datasource/npm'; import { logger } from '../../../logger'; -import { platform } from '../../../platform'; import { ExternalHostError } from '../../../types/errors/external-host-error'; import { getCache } from '../../../util/cache/repository'; import { clone } from '../../../util/clone'; import { readLocalFile } from '../../../util/fs'; +import { getFileList } from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; import { flattenPackageRules } from './flatten'; @@ -23,7 +23,7 @@ export async function mergeRenovateConfig( config: RenovateConfig ): Promise<RenovateConfig> { let returnConfig = { ...config }; - const fileList = await platform.getFileList(); + const fileList = await getFileList(); async function detectConfigFile(): Promise<string | null> { for (const fileName of configFileNames) { if (fileName === 'package.json') { diff --git a/lib/workers/repository/onboarding/branch/check.ts b/lib/workers/repository/onboarding/branch/check.ts index 363c697cec..e74f623e00 100644 --- a/lib/workers/repository/onboarding/branch/check.ts +++ b/lib/workers/repository/onboarding/branch/check.ts @@ -5,10 +5,11 @@ import { PR_STATE_NOT_OPEN } from '../../../../constants/pull-requests'; import { logger } from '../../../../logger'; import { platform } from '../../../../platform'; import { readLocalFile } from '../../../../util/fs'; +import { getFileList } from '../../../../util/git'; const findFile = async (fileName: string): Promise<boolean> => { logger.debug(`findFile(${fileName})`); - const fileList = await platform.getFileList(); + const fileList = await getFileList(); return fileList.includes(fileName); }; diff --git a/lib/workers/repository/onboarding/branch/index.spec.ts b/lib/workers/repository/onboarding/branch/index.spec.ts index a9d53d2703..c7577c4644 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -3,6 +3,7 @@ import { RenovateConfig, fs, getConfig, + git, platform, } from '../../../../../test/util'; import { PR_STATE_OPEN } from '../../../../constants/pull-requests'; @@ -14,6 +15,7 @@ const rebase: any = _rebase; jest.mock('../../../../workers/repository/onboarding/branch/rebase'); jest.mock('../../../../util/fs'); +jest.mock('../../../../util/git'); describe('workers/repository/onboarding/branch', () => { describe('checkOnboardingBranch', () => { @@ -21,7 +23,7 @@ describe('workers/repository/onboarding/branch', () => { beforeEach(() => { jest.resetAllMocks(); config = getConfig(); - platform.getFileList.mockResolvedValue([]); + git.getFileList.mockResolvedValue([]); }); it('throws if no package files', async () => { await expect(checkOnboardingBranch(config)).rejects.toThrow(); @@ -31,7 +33,7 @@ describe('workers/repository/onboarding/branch', () => { await expect(checkOnboardingBranch(config)).rejects.toThrow(); }); it('has default onboarding config', async () => { - platform.getFileList.mockResolvedValue(['package.json']); + git.getFileList.mockResolvedValue(['package.json']); fs.readLocalFile.mockResolvedValue('{}'); await checkOnboardingBranch(config); expect( @@ -47,25 +49,25 @@ describe('workers/repository/onboarding/branch', () => { it('handles skipped onboarding, requireConfig=true, and a config file', async () => { config.requireConfig = true; config.onboarding = false; - platform.getFileList.mockResolvedValueOnce(['renovate.json']); + git.getFileList.mockResolvedValueOnce(['renovate.json']); const res = await checkOnboardingBranch(config); expect(res.repoIsOnboarded).toBe(true); }); it('handles skipped onboarding, requireConfig=true, and no config file', async () => { config.requireConfig = true; config.onboarding = false; - platform.getFileList.mockResolvedValueOnce(['package.json']); + git.getFileList.mockResolvedValueOnce(['package.json']); fs.readLocalFile.mockResolvedValueOnce('{}'); const onboardingResult = checkOnboardingBranch(config); await expect(onboardingResult).rejects.toThrow('disabled'); }); it('detects repo is onboarded via file', async () => { - platform.getFileList.mockResolvedValueOnce(['renovate.json']); + git.getFileList.mockResolvedValueOnce(['renovate.json']); const res = await checkOnboardingBranch(config); expect(res.repoIsOnboarded).toBe(true); }); it('detects repo is onboarded via package.json config', async () => { - platform.getFileList.mockResolvedValueOnce(['package.json']); + git.getFileList.mockResolvedValueOnce(['package.json']); fs.readLocalFile.mockResolvedValueOnce('{"renovate":{}}'); const res = await checkOnboardingBranch(config); expect(res.repoIsOnboarded).toBe(true); @@ -89,7 +91,7 @@ describe('workers/repository/onboarding/branch', () => { await expect(checkOnboardingBranch(config)).rejects.toThrow(); }); it('creates onboarding branch with greenkeeper migration', async () => { - platform.getFileList.mockResolvedValue(['package.json']); + git.getFileList.mockResolvedValue(['package.json']); const pJsonContent = JSON.stringify({ name: 'some-name', version: '0.0.1', @@ -107,7 +109,7 @@ describe('workers/repository/onboarding/branch', () => { ).toMatchSnapshot(); }); it('updates onboarding branch', async () => { - platform.getFileList.mockResolvedValue(['package.json']); + git.getFileList.mockResolvedValue(['package.json']); platform.findPr.mockResolvedValue(null); platform.getBranchPr.mockResolvedValueOnce(mock<Pr>()); rebase.rebaseOnboardingBranch.mockResolvedValueOnce('abc123'); diff --git a/lib/workers/repository/onboarding/branch/rebase.spec.ts b/lib/workers/repository/onboarding/branch/rebase.spec.ts index fda34695fa..9ec32ee7a3 100644 --- a/lib/workers/repository/onboarding/branch/rebase.spec.ts +++ b/lib/workers/repository/onboarding/branch/rebase.spec.ts @@ -2,11 +2,14 @@ import { mock } from 'jest-mock-extended'; import { RenovateConfig, defaultConfig, + git, platform, } from '../../../../../test/util'; import { Pr } from '../../../../platform'; import { rebaseOnboardingBranch } from './rebase'; +jest.mock('../../../../util/git'); + describe('workers/repository/onboarding/branch/rebase', () => { describe('rebaseOnboardingBranch()', () => { let config: RenovateConfig; @@ -27,7 +30,7 @@ describe('workers/repository/onboarding/branch/rebase', () => { it('does nothing if branch is up to date', async () => { const contents = JSON.stringify(defaultConfig.onboardingConfig, null, 2) + '\n'; - platform.getFile + git.getFile .mockResolvedValueOnce(contents) // package.json .mockResolvedValueOnce(contents); // renovate.json platform.getBranchPr.mockResolvedValueOnce({ diff --git a/lib/workers/repository/onboarding/branch/rebase.ts b/lib/workers/repository/onboarding/branch/rebase.ts index 445ac440cc..ff4a8e628e 100644 --- a/lib/workers/repository/onboarding/branch/rebase.ts +++ b/lib/workers/repository/onboarding/branch/rebase.ts @@ -2,6 +2,7 @@ import { RenovateConfig } from '../../../../config'; import { configFileNames } from '../../../../config/app-strings'; import { logger } from '../../../../logger'; import { platform } from '../../../../platform'; +import { getFile } from '../../../../util/git'; import { getOnboardingConfig } from './config'; const defaultConfigFile = configFileNames[0]; @@ -31,7 +32,7 @@ export async function rebaseOnboardingBranch( logger.debug('Onboarding branch has been edited and cannot be rebased'); return null; } - const existingContents = await platform.getFile( + const existingContents = await getFile( defaultConfigFile, config.onboardingBranch ); -- GitLab