diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index 6f5cbfe32601da14e78db24a26dfe25c2cd39fa2..3146e6e06385c49f6444d62116bd44d4df58bfa4 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -26,12 +26,6 @@ export interface BranchUpgradeCache { sourceUrl?: string; } -export interface OnboardingBranchCache { - onboardingBranch: string; - defaultBranchSha: string; - onboardingBranchSha: string; -} - export interface PrCache { fingerprint: string; /** @@ -106,7 +100,6 @@ export interface RepoCacheData { github?: Record<string, unknown>; }; prComments?: Record<number, Record<string, string>>; - onboardingBranchCache?: OnboardingBranchCache; } export interface RepoCache { diff --git a/lib/workers/repository/onboarding/branch/check.spec.ts b/lib/workers/repository/onboarding/branch/check.spec.ts deleted file mode 100644 index 6935cc04c1cf3ca367d006e393e2c57f2d58a9cd..0000000000000000000000000000000000000000 --- a/lib/workers/repository/onboarding/branch/check.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { RenovateConfig, git, mocked, partial } from '../../../../../test/util'; -import { logger } from '../../../../logger'; -import * as _cache from '../../../../util/cache/repository'; -import { isOnboarded } from './check'; - -jest.mock('../../../../util/cache/repository'); -jest.mock('../../../../util/git'); - -const cache = mocked(_cache); - -describe('workers/repository/onboarding/branch/check', () => { - const config = partial<RenovateConfig>({ requireConfig: 'required' }); - - it('skips normal onboarding check if onboardingCache is valid', async () => { - cache.getCache.mockReturnValueOnce({ - onboardingBranchCache: { - onboardingBranch: 'configure/renovate', - defaultBranchSha: 'default-sha', - onboardingBranchSha: 'onboarding-sha', - }, - }); - git.getBranchCommit - .mockReturnValueOnce('default-sha') - .mockReturnValueOnce('onboarding-sha'); - const res = await isOnboarded(config); - expect(res).toBeFalse(); - expect(logger.debug).toHaveBeenCalledWith( - 'Onboarding cache is valid. Repo is not onboarded' - ); - }); - - it('continues with normal logic if onboardingCache is invalid', async () => { - cache.getCache.mockReturnValueOnce({ - onboardingBranchCache: { - onboardingBranch: 'configure/renovate', - defaultBranchSha: 'default-sha', - onboardingBranchSha: 'onboarding-sha', - }, - }); - git.getBranchCommit - .mockReturnValueOnce('default-sha-1') - .mockReturnValueOnce('onboarding-sha'); - git.getFileList.mockResolvedValue([]); - await isOnboarded(config); - expect(logger.debug).not.toHaveBeenCalledWith( - 'Onboarding cache is valid. Repo is not onboarded' - ); - }); -}); diff --git a/lib/workers/repository/onboarding/branch/check.ts b/lib/workers/repository/onboarding/branch/check.ts index 040133d142a54058bbfaa920c5fb524f159414bf..7f77ded5485d6db00487674c009aa89a5163c189 100644 --- a/lib/workers/repository/onboarding/branch/check.ts +++ b/lib/workers/repository/onboarding/branch/check.ts @@ -9,7 +9,7 @@ import { Pr, platform } from '../../../../modules/platform'; import { ensureComment } from '../../../../modules/platform/comment'; import { getCache } from '../../../../util/cache/repository'; import { readLocalFile } from '../../../../util/fs'; -import { getBranchCommit, getFileList } from '../../../../util/git'; +import { getFileList } from '../../../../util/git'; async function findFile(fileName: string): Promise<boolean> { logger.debug(`findFile(${fileName})`); @@ -61,21 +61,7 @@ export async function isOnboarded(config: RenovateConfig): Promise<boolean> { logger.debug('Config file will be ignored'); return true; } - const cache = getCache(); - const onboardingBranchCache = cache?.onboardingBranchCache; - // if onboarding cache is present and base branch has not been updated branch is not onboarded - if ( - onboardingBranchCache && - onboardingBranchCache.defaultBranchSha === - getBranchCommit(config.defaultBranch!) && - onboardingBranchCache.onboardingBranchSha === - getBranchCommit(config.onboardingBranch!) - ) { - logger.debug('Onboarding cache is valid. Repo is not onboarded'); - return false; - } - if (cache.configFileName) { logger.debug('Checking cached config file name'); try { diff --git a/lib/workers/repository/onboarding/branch/index.spec.ts b/lib/workers/repository/onboarding/branch/index.spec.ts index 04fc5ed1856d67db72e99746efe2efbf42a473f1..1569fab4c451c3a08775ffe87a717d8cafce435d 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -21,7 +21,6 @@ import * as _cache from '../../../../util/cache/repository'; import type { FileAddition } from '../../../../util/git/types'; import { OnboardingState } from '../common'; import * as _config from './config'; -import * as _onboardingCache from './onboarding-branch-cache'; import * as _rebase from './rebase'; import { checkOnboardingBranch } from '.'; @@ -33,21 +32,12 @@ jest.mock('../../../../util/cache/repository'); jest.mock('../../../../util/fs'); jest.mock('../../../../util/git'); jest.mock('./config'); -jest.mock('./onboarding-branch-cache'); const cache = mocked(_cache); -const onboardingCache = mocked(_onboardingCache); describe('workers/repository/onboarding/branch/index', () => { describe('checkOnboardingBranch', () => { let config: RenovateConfig; - const dummyCache = { - onboardingBranchCache: { - onboardingBranch: 'configure/renovate', - defaultBranchSha: 'default-sha', - onboardingBranchSha: 'onboarding-sha', - }, - }; beforeEach(() => { memCache.init(); @@ -178,11 +168,9 @@ describe('workers/repository/onboarding/branch/index', () => { }); it('detects repo is onboarded via file', async () => { - cache.getCache.mockReturnValue(dummyCache); git.getFileList.mockResolvedValueOnce(['renovate.json']); const res = await checkOnboardingBranch(config); expect(res.repoIsOnboarded).toBeTrue(); - expect(onboardingCache.deleteOnboardingCache).toHaveBeenCalledTimes(1); // removes onboarding cache when repo is onboarded }); it('handles removed cached file name', async () => { @@ -263,7 +251,6 @@ describe('workers/repository/onboarding/branch/index', () => { }); it('updates onboarding branch', async () => { - cache.getCache.mockReturnValue(dummyCache); git.getFileList.mockResolvedValue(['package.json']); platform.findPr.mockResolvedValue(null); platform.getBranchPr.mockResolvedValueOnce(mock<Pr>()); @@ -272,7 +259,6 @@ describe('workers/repository/onboarding/branch/index', () => { expect(res.repoIsOnboarded).toBeFalse(); expect(res.branchList).toEqual(['renovate/configure']); expect(git.checkoutBranch).toHaveBeenCalledTimes(1); - expect(onboardingCache.setOnboardingCache).toHaveBeenCalledTimes(1); // update onboarding cache expect(scm.commitAndPush).toHaveBeenCalledTimes(0); }); diff --git a/lib/workers/repository/onboarding/branch/index.ts b/lib/workers/repository/onboarding/branch/index.ts index c8f50ecefa8575b9bb71f235039901293d7fff9a..2add4def7375e7874ff47e861f00f5dfe0dcebd6 100644 --- a/lib/workers/repository/onboarding/branch/index.ts +++ b/lib/workers/repository/onboarding/branch/index.ts @@ -8,21 +8,13 @@ import { } from '../../../../constants/error-messages'; import { logger } from '../../../../logger'; import { Pr, platform } from '../../../../modules/platform'; -import { - checkoutBranch, - getBranchCommit, - setGitAuthor, -} from '../../../../util/git'; +import { checkoutBranch, setGitAuthor } from '../../../../util/git'; import { extractAllDependencies } from '../../extract'; import { mergeRenovateConfig } from '../../init/merge'; import { OnboardingState } from '../common'; import { getOnboardingPr, isOnboarded } from './check'; import { getOnboardingConfig } from './config'; import { createOnboardingBranch } from './create'; -import { - deleteOnboardingCache, - setOnboardingCache, -} from './onboarding-branch-cache'; import { rebaseOnboardingBranch } from './rebase'; export async function checkOnboardingBranch( @@ -34,9 +26,6 @@ export async function checkOnboardingBranch( const repoIsOnboarded = await isOnboarded(config); if (repoIsOnboarded) { logger.debug('Repo is onboarded'); - - // delete onboarding cache - deleteOnboardingCache(); return { ...config, repoIsOnboarded }; } if (config.isFork && config.forkProcessing !== 'enabled') { @@ -58,13 +47,6 @@ export async function checkOnboardingBranch( { branch: config.onboardingBranch, commit, onboarding: true }, 'Branch updated' ); - - // update onboarding cache - setOnboardingCache( - config.onboardingBranch!, - getBranchCommit(config.defaultBranch!)!, - commit - ); } // istanbul ignore if if (platform.refreshPr) { @@ -96,13 +78,6 @@ export async function checkOnboardingBranch( { branch: onboardingBranch, commit, onboarding: true }, 'Branch created' ); - - // set onboarding branch cache - setOnboardingCache( - config.onboardingBranch!, - getBranchCommit(config.defaultBranch!)!, - commit - ); } } if (!GlobalConfig.get('dryRun')) { diff --git a/lib/workers/repository/onboarding/branch/onboarding-branch-cache.spec.ts b/lib/workers/repository/onboarding/branch/onboarding-branch-cache.spec.ts deleted file mode 100644 index 10307e5a3ec37424a7199fed37f4751c35ff6c1c..0000000000000000000000000000000000000000 --- a/lib/workers/repository/onboarding/branch/onboarding-branch-cache.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { mocked } from '../../../../../test/util'; -import * as _cache from '../../../../util/cache/repository'; -import type { RepoCacheData } from '../../../../util/cache/repository/types'; -import { - deleteOnboardingCache, - setOnboardingCache, -} from './onboarding-branch-cache'; - -jest.mock('../../../../util/cache/repository'); -const cache = mocked(_cache); - -describe('workers/repository/onboarding/branch/onboarding-branch-cache', () => { - it('sets new cache', () => { - const dummyCache = {} satisfies RepoCacheData; - cache.getCache.mockReturnValueOnce(dummyCache); - setOnboardingCache('configure/renovate', 'default-sha', 'onboarding-sha'); - expect(dummyCache).toEqual({ - onboardingBranchCache: { - onboardingBranch: 'configure/renovate', - defaultBranchSha: 'default-sha', - onboardingBranchSha: 'onboarding-sha', - }, - }); - }); - - it('updates old cache', () => { - const dummyCache = { - onboardingBranchCache: { - onboardingBranch: 'configure/renovate', - defaultBranchSha: 'default-sha', - onboardingBranchSha: 'onboarding-sha', - }, - } satisfies RepoCacheData; - cache.getCache.mockReturnValueOnce(dummyCache); - setOnboardingCache( - 'configure/renovate', - 'default-sha-1', - 'onboarding-sha-1' - ); - expect(dummyCache).toEqual({ - onboardingBranchCache: { - onboardingBranch: 'configure/renovate', - defaultBranchSha: 'default-sha-1', - onboardingBranchSha: 'onboarding-sha-1', - }, - }); - }); - - it('deletes cache', () => { - const dummyCache = { - onboardingBranchCache: { - onboardingBranch: 'configure/renovate', - defaultBranchSha: 'default-sha', - onboardingBranchSha: 'onboarding-sha', - }, - } satisfies RepoCacheData; - cache.getCache.mockReturnValueOnce(dummyCache); - deleteOnboardingCache(); - expect(dummyCache.onboardingBranchCache).toBeUndefined(); - }); -}); diff --git a/lib/workers/repository/onboarding/branch/onboarding-branch-cache.ts b/lib/workers/repository/onboarding/branch/onboarding-branch-cache.ts deleted file mode 100644 index a6ecfcb29677b2f81315e7dad4415505f9274c7f..0000000000000000000000000000000000000000 --- a/lib/workers/repository/onboarding/branch/onboarding-branch-cache.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { logger } from '../../../../logger'; -import { getCache } from '../../../../util/cache/repository'; - -export function setOnboardingCache( - onboardingBranch: string, - defaultBranchSha: string, - onboardingBranchSha: string -): void { - const cache = getCache(); - const onboardingCache = { - onboardingBranch, - defaultBranchSha, - onboardingBranchSha, - }; - if (cache.onboardingBranchCache) { - logger.debug('Update Onboarding Cache'); - } else { - logger.debug('Create Onboarding Cache'); - } - cache.onboardingBranchCache = onboardingCache; -} - -export function deleteOnboardingCache(): void { - const cache = getCache(); - - if (cache?.onboardingBranchCache) { - logger.debug('Delete Onboarding Cache'); - delete cache.onboardingBranchCache; - } -}