Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove getFile/getFileList from platform #6674

Merged
merged 4 commits into from Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/manager/cargo/artifacts.spec.ts
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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'];
Expand All @@ -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'];
Expand Down
16 changes: 7 additions & 9 deletions lib/manager/npm/post-update/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand All @@ -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')
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down
17 changes: 8 additions & 9 deletions 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(() => {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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',
Expand All @@ -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', {}, {});
Expand Down
4 changes: 2 additions & 2 deletions lib/manager/npm/post-update/lerna.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions lib/platform/__snapshots__/index.spec.ts.snap
Expand Up @@ -23,8 +23,6 @@ Array [
"getBranchStatus",
"getBranchStatusCheck",
"getCommitMessages",
"getFile",
"getFileList",
"getIssueList",
"getPr",
"getPrBody",
Expand Down Expand Up @@ -66,8 +64,6 @@ Array [
"getBranchStatus",
"getBranchStatusCheck",
"getCommitMessages",
"getFile",
"getFileList",
"getIssueList",
"getPr",
"getPrBody",
Expand Down Expand Up @@ -109,8 +105,6 @@ Array [
"getBranchStatus",
"getBranchStatusCheck",
"getCommitMessages",
"getFile",
"getFileList",
"getIssueList",
"getPr",
"getPrBody",
Expand Down Expand Up @@ -152,8 +146,6 @@ Array [
"getBranchStatus",
"getBranchStatusCheck",
"getCommitMessages",
"getFile",
"getFileList",
"getIssueList",
"getPr",
"getPrBody",
Expand Down
11 changes: 0 additions & 11 deletions lib/platform/azure/index.ts
Expand Up @@ -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> {
Expand Down Expand Up @@ -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})`);
Expand Down