Skip to content

Commit

Permalink
Revert "feat(onboarding): use cache to check if repo is onboarded (#2…
Browse files Browse the repository at this point in the history
…0733)"

This reverts commit 1d95167.
  • Loading branch information
rarkins authored Apr 21, 2023
1 parent b853af2 commit 34f9c53
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 202 deletions.
7 changes: 0 additions & 7 deletions lib/util/cache/repository/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ export interface BranchUpgradeCache {
sourceUrl?: string;
}

export interface OnboardingBranchCache {
onboardingBranch: string;
defaultBranchSha: string;
onboardingBranchSha: string;
}

export interface PrCache {
fingerprint: string;
/**
Expand Down Expand Up @@ -106,7 +100,6 @@ export interface RepoCacheData {
github?: Record<string, unknown>;
};
prComments?: Record<number, Record<string, string>>;
onboardingBranchCache?: OnboardingBranchCache;
}

export interface RepoCache {
Expand Down
49 changes: 0 additions & 49 deletions lib/workers/repository/onboarding/branch/check.spec.ts

This file was deleted.

16 changes: 1 addition & 15 deletions lib/workers/repository/onboarding/branch/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`);
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 0 additions & 14 deletions lib/workers/repository/onboarding/branch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.';

Expand All @@ -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();
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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>());
Expand All @@ -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);
});

Expand Down
27 changes: 1 addition & 26 deletions lib/workers/repository/onboarding/branch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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') {
Expand All @@ -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) {
Expand Down Expand Up @@ -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')) {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 34f9c53

Please sign in to comment.