mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
fix: Revert "refactor: move branch cache files to util/cache" (#18667)
This commit is contained in:
parent
e4b20f4368
commit
c229652e9f
15 changed files with 84 additions and 79 deletions
11
lib/util/cache/branch/index.ts
vendored
11
lib/util/cache/branch/index.ts
vendored
|
@ -1,11 +0,0 @@
|
||||||
export {
|
|
||||||
deleteCachedBranchParentShaResult,
|
|
||||||
getCachedBranchParentShaResult,
|
|
||||||
} from './parent-sha';
|
|
||||||
export { setBranchNewCommit } from './set-branch-commit';
|
|
||||||
export {
|
|
||||||
getCachedBehindBaseResult,
|
|
||||||
setCachedBehindBaseResult,
|
|
||||||
} from './behind-base-branch';
|
|
||||||
export { getCachedConflictResult, setCachedConflictResult } from './conflict';
|
|
||||||
export { getCachedModifiedResult, setCachedModifiedResult } from './modified';
|
|
|
@ -1,15 +1,15 @@
|
||||||
import { logger, mocked, partial } from '../../../../test/util';
|
import { logger, mocked, partial } from '../../../test/util';
|
||||||
import * as _repositoryCache from '../repository';
|
import * as _repositoryCache from '../cache/repository';
|
||||||
import type { BranchCache, RepoCacheData } from '../repository/types';
|
import type { BranchCache, RepoCacheData } from '../cache/repository/types';
|
||||||
import {
|
import {
|
||||||
getCachedBehindBaseResult,
|
getCachedBehindBaseResult,
|
||||||
setCachedBehindBaseResult,
|
setCachedBehindBaseResult,
|
||||||
} from './behind-base-branch';
|
} from './behind-base-branch-cache';
|
||||||
|
|
||||||
jest.mock('../repository');
|
jest.mock('../cache/repository');
|
||||||
const repositoryCache = mocked(_repositoryCache);
|
const repositoryCache = mocked(_repositoryCache);
|
||||||
|
|
||||||
describe('util/cache/branch/behind-base-branch', () => {
|
describe('util/git/behind-base-branch-cache', () => {
|
||||||
let repoCache: RepoCacheData = {};
|
let repoCache: RepoCacheData = {};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
|
@ -1,5 +1,5 @@
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../logger';
|
||||||
import { getCache } from '../repository';
|
import { getCache } from '../cache/repository';
|
||||||
|
|
||||||
export function getCachedBehindBaseResult(
|
export function getCachedBehindBaseResult(
|
||||||
branchName: string,
|
branchName: string,
|
|
@ -1,12 +1,15 @@
|
||||||
import { mocked, partial } from '../../../../test/util';
|
import { mocked, partial } from '../../../test/util';
|
||||||
import * as _repositoryCache from '../repository';
|
import * as _repositoryCache from '../cache/repository';
|
||||||
import type { BranchCache, RepoCacheData } from '../repository/types';
|
import type { BranchCache, RepoCacheData } from '../cache/repository/types';
|
||||||
import { getCachedConflictResult, setCachedConflictResult } from './conflict';
|
import {
|
||||||
|
getCachedConflictResult,
|
||||||
|
setCachedConflictResult,
|
||||||
|
} from './conflicts-cache';
|
||||||
|
|
||||||
jest.mock('../repository');
|
jest.mock('../cache/repository');
|
||||||
const repositoryCache = mocked(_repositoryCache);
|
const repositoryCache = mocked(_repositoryCache);
|
||||||
|
|
||||||
describe('util/cache/branch/conflict', () => {
|
describe('util/git/conflicts-cache', () => {
|
||||||
let repoCache: RepoCacheData = {};
|
let repoCache: RepoCacheData = {};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
|
@ -1,5 +1,5 @@
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../logger';
|
||||||
import { getCache } from '../repository';
|
import { getCache } from '../cache/repository';
|
||||||
|
|
||||||
export function getCachedConflictResult(
|
export function getCachedConflictResult(
|
||||||
branchName: string,
|
branchName: string,
|
|
@ -7,17 +7,25 @@ import {
|
||||||
CONFIG_VALIDATION,
|
CONFIG_VALIDATION,
|
||||||
INVALID_PATH,
|
INVALID_PATH,
|
||||||
} from '../../constants/error-messages';
|
} from '../../constants/error-messages';
|
||||||
import * as _branchCache from '../cache/branch';
|
|
||||||
import { newlineRegex, regEx } from '../regex';
|
import { newlineRegex, regEx } from '../regex';
|
||||||
|
import * as _behindBaseCache from './behind-base-branch-cache';
|
||||||
|
import * as _conflictsCache from './conflicts-cache';
|
||||||
|
import * as _modifiedCache from './modified-cache';
|
||||||
|
import * as _parentShaCache from './parent-sha-cache';
|
||||||
import type { FileChange } from './types';
|
import type { FileChange } from './types';
|
||||||
import * as git from '.';
|
import * as git from '.';
|
||||||
import { setNoVerify } from '.';
|
import { setNoVerify } from '.';
|
||||||
|
|
||||||
jest.mock('../cache/branch');
|
jest.mock('./conflicts-cache');
|
||||||
|
jest.mock('./behind-base-branch-cache');
|
||||||
|
jest.mock('./modified-cache');
|
||||||
|
jest.mock('./parent-sha-cache');
|
||||||
jest.mock('delay');
|
jest.mock('delay');
|
||||||
jest.mock('../cache/repository');
|
jest.mock('../cache/repository');
|
||||||
const branchCache = mocked(_branchCache);
|
const behindBaseCache = mocked(_behindBaseCache);
|
||||||
|
const conflictsCache = mocked(_conflictsCache);
|
||||||
|
const modifiedCache = mocked(_modifiedCache);
|
||||||
|
const parentShaCache = mocked(_parentShaCache);
|
||||||
// Class is no longer exported
|
// Class is no longer exported
|
||||||
const SimpleGit = Git().constructor as { prototype: ReturnType<typeof Git> };
|
const SimpleGit = Git().constructor as { prototype: ReturnType<typeof Git> };
|
||||||
|
|
||||||
|
@ -108,8 +116,8 @@ describe('util/git/index', () => {
|
||||||
// override some local git settings for better testing
|
// override some local git settings for better testing
|
||||||
const local = Git(tmpDir.path);
|
const local = Git(tmpDir.path);
|
||||||
await local.addConfig('commit.gpgsign', 'false');
|
await local.addConfig('commit.gpgsign', 'false');
|
||||||
branchCache.getCachedBranchParentShaResult.mockReturnValue(null);
|
parentShaCache.getCachedBranchParentShaResult.mockReturnValue(null);
|
||||||
branchCache.getCachedBehindBaseResult.mockReturnValue(null);
|
behindBaseCache.getCachedBehindBaseResult.mockReturnValue(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -256,7 +264,7 @@ describe('util/git/index', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns cached value', async () => {
|
it('returns cached value', async () => {
|
||||||
branchCache.getCachedBehindBaseResult.mockReturnValue(true);
|
behindBaseCache.getCachedBehindBaseResult.mockReturnValue(true);
|
||||||
expect(await git.isBranchBehindBase('develop', defaultBranch)).toBeTrue();
|
expect(await git.isBranchBehindBase('develop', defaultBranch)).toBeTrue();
|
||||||
expect(logger.logger.debug).toHaveBeenCalledWith(
|
expect(logger.logger.debug).toHaveBeenCalledWith(
|
||||||
'branch.isBehindBase(): using cached result "true"'
|
'branch.isBehindBase(): using cached result "true"'
|
||||||
|
@ -266,7 +274,7 @@ describe('util/git/index', () => {
|
||||||
|
|
||||||
describe('isBranchModified()', () => {
|
describe('isBranchModified()', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
branchCache.getCachedModifiedResult.mockReturnValue(null);
|
modifiedCache.getCachedModifiedResult.mockReturnValue(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false when branch is not found', async () => {
|
it('should return false when branch is not found', async () => {
|
||||||
|
@ -290,7 +298,7 @@ describe('util/git/index', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return value stored in modifiedCacheResult', async () => {
|
it('should return value stored in modifiedCacheResult', async () => {
|
||||||
branchCache.getCachedModifiedResult.mockReturnValue(true);
|
modifiedCache.getCachedModifiedResult.mockReturnValue(true);
|
||||||
expect(await git.isBranchModified('renovate/future_branch')).toBeTrue();
|
expect(await git.isBranchModified('renovate/future_branch')).toBeTrue();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -797,7 +805,7 @@ describe('util/git/index', () => {
|
||||||
|
|
||||||
await repo.checkout(defaultBranch);
|
await repo.checkout(defaultBranch);
|
||||||
|
|
||||||
branchCache.getCachedConflictResult.mockReturnValue(null);
|
conflictsCache.getCachedConflictResult.mockReturnValue(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns true for non-existing source branch', async () => {
|
it('returns true for non-existing source branch', async () => {
|
||||||
|
@ -854,7 +862,7 @@ describe('util/git/index', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns cached values', async () => {
|
it('returns cached values', async () => {
|
||||||
branchCache.getCachedConflictResult.mockReturnValue(true);
|
conflictsCache.getCachedConflictResult.mockReturnValue(true);
|
||||||
|
|
||||||
const res = await git.isBranchConflicted(
|
const res = await git.isBranchConflicted(
|
||||||
defaultBranch,
|
defaultBranch,
|
||||||
|
@ -862,7 +870,7 @@ describe('util/git/index', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(res).toBeTrue();
|
expect(res).toBeTrue();
|
||||||
expect(branchCache.getCachedConflictResult.mock.calls).toEqual([
|
expect(conflictsCache.getCachedConflictResult.mock.calls).toEqual([
|
||||||
[
|
[
|
||||||
'renovate/conflicted_branch',
|
'renovate/conflicted_branch',
|
||||||
git.getBranchCommit('renovate/conflicted_branch'),
|
git.getBranchCommit('renovate/conflicted_branch'),
|
||||||
|
@ -870,11 +878,11 @@ describe('util/git/index', () => {
|
||||||
git.getBranchCommit(defaultBranch),
|
git.getBranchCommit(defaultBranch),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
expect(branchCache.setCachedConflictResult).not.toHaveBeenCalled();
|
expect(conflictsCache.setCachedConflictResult).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('caches truthy return value', async () => {
|
it('caches truthy return value', async () => {
|
||||||
branchCache.getCachedConflictResult.mockReturnValue(null);
|
conflictsCache.getCachedConflictResult.mockReturnValue(null);
|
||||||
|
|
||||||
const res = await git.isBranchConflicted(
|
const res = await git.isBranchConflicted(
|
||||||
defaultBranch,
|
defaultBranch,
|
||||||
|
@ -882,13 +890,13 @@ describe('util/git/index', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(res).toBeTrue();
|
expect(res).toBeTrue();
|
||||||
expect(branchCache.setCachedConflictResult.mock.calls).toEqual([
|
expect(conflictsCache.setCachedConflictResult.mock.calls).toEqual([
|
||||||
['renovate/conflicted_branch', true],
|
['renovate/conflicted_branch', true],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('caches falsy return value', async () => {
|
it('caches falsy return value', async () => {
|
||||||
branchCache.getCachedConflictResult.mockReturnValue(null);
|
conflictsCache.getCachedConflictResult.mockReturnValue(null);
|
||||||
|
|
||||||
const res = await git.isBranchConflicted(
|
const res = await git.isBranchConflicted(
|
||||||
defaultBranch,
|
defaultBranch,
|
||||||
|
@ -896,7 +904,7 @@ describe('util/git/index', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(res).toBeFalse();
|
expect(res).toBeFalse();
|
||||||
expect(branchCache.setCachedConflictResult.mock.calls).toEqual([
|
expect(conflictsCache.setCachedConflictResult.mock.calls).toEqual([
|
||||||
['renovate/non_conflicted_branch', false],
|
['renovate/non_conflicted_branch', false],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,22 +28,24 @@ import { api as semverCoerced } from '../../modules/versioning/semver-coerced';
|
||||||
import { ExternalHostError } from '../../types/errors/external-host-error';
|
import { ExternalHostError } from '../../types/errors/external-host-error';
|
||||||
import type { GitProtocol } from '../../types/git';
|
import type { GitProtocol } from '../../types/git';
|
||||||
import { Limit, incLimitedValue } from '../../workers/global/limits';
|
import { Limit, incLimitedValue } from '../../workers/global/limits';
|
||||||
import {
|
|
||||||
deleteCachedBranchParentShaResult,
|
|
||||||
getCachedBehindBaseResult,
|
|
||||||
getCachedConflictResult,
|
|
||||||
getCachedModifiedResult,
|
|
||||||
setCachedConflictResult,
|
|
||||||
setCachedModifiedResult,
|
|
||||||
} from '../cache/branch';
|
|
||||||
import { newlineRegex, regEx } from '../regex';
|
import { newlineRegex, regEx } from '../regex';
|
||||||
import { parseGitAuthor } from './author';
|
import { parseGitAuthor } from './author';
|
||||||
|
import { getCachedBehindBaseResult } from './behind-base-branch-cache';
|
||||||
import { getNoVerify, simpleGitConfig } from './config';
|
import { getNoVerify, simpleGitConfig } from './config';
|
||||||
|
import {
|
||||||
|
getCachedConflictResult,
|
||||||
|
setCachedConflictResult,
|
||||||
|
} from './conflicts-cache';
|
||||||
import {
|
import {
|
||||||
bulkChangesDisallowed,
|
bulkChangesDisallowed,
|
||||||
checkForPlatformFailure,
|
checkForPlatformFailure,
|
||||||
handleCommitError,
|
handleCommitError,
|
||||||
} from './error';
|
} from './error';
|
||||||
|
import {
|
||||||
|
getCachedModifiedResult,
|
||||||
|
setCachedModifiedResult,
|
||||||
|
} from './modified-cache';
|
||||||
|
import { deleteCachedBranchParentShaResult } from './parent-sha-cache';
|
||||||
import { configSigningKey, writePrivateKey } from './private-key';
|
import { configSigningKey, writePrivateKey } from './private-key';
|
||||||
import type {
|
import type {
|
||||||
CommitFilesConfig,
|
CommitFilesConfig,
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import { logger, mocked, partial } from '../../../../test/util';
|
import { logger, mocked, partial } from '../../../test/util';
|
||||||
import * as _repositoryCache from '../repository';
|
import * as _repositoryCache from '../cache/repository';
|
||||||
import type { BranchCache, RepoCacheData } from '../repository/types';
|
import type { BranchCache, RepoCacheData } from '../cache/repository/types';
|
||||||
import { getCachedModifiedResult, setCachedModifiedResult } from './modified';
|
import {
|
||||||
|
getCachedModifiedResult,
|
||||||
|
setCachedModifiedResult,
|
||||||
|
} from './modified-cache';
|
||||||
|
|
||||||
jest.mock('../repository');
|
jest.mock('../cache/repository');
|
||||||
const repositoryCache = mocked(_repositoryCache);
|
const repositoryCache = mocked(_repositoryCache);
|
||||||
|
|
||||||
describe('util/cache/branch/modified', () => {
|
describe('util/git/modified-cache', () => {
|
||||||
let repoCache: RepoCacheData = {};
|
let repoCache: RepoCacheData = {};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
|
@ -1,5 +1,5 @@
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../logger';
|
||||||
import { getCache } from '../repository';
|
import { getCache } from '../cache/repository';
|
||||||
|
|
||||||
export function getCachedModifiedResult(
|
export function getCachedModifiedResult(
|
||||||
branchName: string,
|
branchName: string,
|
|
@ -1,15 +1,15 @@
|
||||||
import { mocked } from '../../../../test/util';
|
import { mocked } from '../../../test/util';
|
||||||
import * as _repositoryCache from '../repository';
|
import * as _repositoryCache from '../cache/repository';
|
||||||
import type { BranchCache, RepoCacheData } from '../repository/types';
|
import type { BranchCache, RepoCacheData } from '../cache/repository/types';
|
||||||
import {
|
import {
|
||||||
deleteCachedBranchParentShaResult,
|
deleteCachedBranchParentShaResult,
|
||||||
getCachedBranchParentShaResult,
|
getCachedBranchParentShaResult,
|
||||||
} from './parent-sha';
|
} from './parent-sha-cache';
|
||||||
|
|
||||||
jest.mock('../repository');
|
jest.mock('../cache/repository');
|
||||||
const repositoryCache = mocked(_repositoryCache);
|
const repositoryCache = mocked(_repositoryCache);
|
||||||
|
|
||||||
describe('util/cache/branch/parent-sha', () => {
|
describe('util/git/parent-sha-cache', () => {
|
||||||
let repoCache: RepoCacheData = {};
|
let repoCache: RepoCacheData = {};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
|
@ -1,4 +1,4 @@
|
||||||
import { getCache } from '../repository';
|
import { getCache } from '../cache/repository';
|
||||||
|
|
||||||
export function getCachedBranchParentShaResult(
|
export function getCachedBranchParentShaResult(
|
||||||
branchName: string,
|
branchName: string,
|
|
@ -1,13 +1,13 @@
|
||||||
import { git, logger, mocked, partial } from '../../../../test/util';
|
import { git, logger, mocked, partial } from '../../../test/util';
|
||||||
import * as _repositoryCache from '../repository';
|
import * as _repositoryCache from '../cache/repository';
|
||||||
import type { BranchCache, RepoCacheData } from '../repository/types';
|
import type { BranchCache, RepoCacheData } from '../cache/repository/types';
|
||||||
import { setBranchNewCommit } from './set-branch-commit';
|
import { setBranchNewCommit } from './set-branch-commit';
|
||||||
|
|
||||||
jest.mock('../repository');
|
jest.mock('../cache/repository');
|
||||||
jest.mock('../../git');
|
jest.mock('.');
|
||||||
const repositoryCache = mocked(_repositoryCache);
|
const repositoryCache = mocked(_repositoryCache);
|
||||||
|
|
||||||
describe('util/cache/branch/set-branch-commit', () => {
|
describe('util/git/set-branch-commit', () => {
|
||||||
let repoCache: RepoCacheData = {};
|
let repoCache: RepoCacheData = {};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
|
@ -1,7 +1,7 @@
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../logger';
|
||||||
import { getBranchCommit } from '../../git';
|
import { getCache } from '../cache/repository';
|
||||||
import { getCache } from '../repository';
|
import type { BranchCache } from '../cache/repository/types';
|
||||||
import type { BranchCache } from '../repository/types';
|
import { getBranchCommit } from '.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a new commit is added to branch
|
* Called when a new commit is added to branch
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import { logger } from '../../logger';
|
import { logger } from '../../logger';
|
||||||
import { platform } from '../../modules/platform';
|
import { platform } from '../../modules/platform';
|
||||||
import { getCachedBranchParentShaResult } from '../../util/cache/branch';
|
|
||||||
import { getCache } from '../../util/cache/repository';
|
import { getCache } from '../../util/cache/repository';
|
||||||
import type {
|
import type {
|
||||||
BranchCache,
|
BranchCache,
|
||||||
|
@ -14,6 +13,7 @@ import {
|
||||||
isBranchConflicted,
|
isBranchConflicted,
|
||||||
isBranchModified,
|
isBranchModified,
|
||||||
} from '../../util/git';
|
} from '../../util/git';
|
||||||
|
import { getCachedBranchParentShaResult } from '../../util/git/parent-sha-cache';
|
||||||
import type { BranchConfig, BranchUpgradeConfig } from '../types';
|
import type { BranchConfig, BranchUpgradeConfig } from '../types';
|
||||||
|
|
||||||
function generateBranchUpgradeCache(
|
function generateBranchUpgradeCache(
|
||||||
|
|
|
@ -2,11 +2,11 @@ import is from '@sindresorhus/is';
|
||||||
import type { RenovateConfig } from '../../../config/types';
|
import type { RenovateConfig } from '../../../config/types';
|
||||||
import { addMeta, logger, removeMeta } from '../../../logger';
|
import { addMeta, logger, removeMeta } from '../../../logger';
|
||||||
import { hashMap } from '../../../modules/manager';
|
import { hashMap } from '../../../modules/manager';
|
||||||
import { setBranchNewCommit } from '../../../util/cache/branch';
|
|
||||||
import { getCache } from '../../../util/cache/repository';
|
import { getCache } from '../../../util/cache/repository';
|
||||||
import type { BranchCache } from '../../../util/cache/repository/types';
|
import type { BranchCache } from '../../../util/cache/repository/types';
|
||||||
import { fingerprint } from '../../../util/fingerprint';
|
import { fingerprint } from '../../../util/fingerprint';
|
||||||
import { branchExists, getBranchCommit } from '../../../util/git';
|
import { branchExists, getBranchCommit } from '../../../util/git';
|
||||||
|
import { setBranchNewCommit } from '../../../util/git/set-branch-commit';
|
||||||
import { Limit, incLimitedValue, setMaxLimit } from '../../global/limits';
|
import { Limit, incLimitedValue, setMaxLimit } from '../../global/limits';
|
||||||
import {
|
import {
|
||||||
BranchConfig,
|
BranchConfig,
|
||||||
|
|
Loading…
Reference in a new issue