Skip to content

Commit

Permalink
fix(cache): Fix repositoryCache support for reset value (#15874)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jun 3, 2022
1 parent fff0a81 commit cbed786
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/util/cache/repository/index.spec.ts
Expand Up @@ -33,4 +33,11 @@ describe('util/cache/repository/index', () => {
await saveCache();
expect(fs.outputFile).toHaveBeenCalled();
});

it('resets cache', async () => {
await initRepoCache({ ...config, repositoryCache: 'reset' });
expect(fs.readFile).not.toHaveBeenCalled();
expect(fs.outputFile).toHaveBeenCalled();
expect(getCache()).toBeEmpty();
});
});
19 changes: 17 additions & 2 deletions lib/util/cache/repository/init.ts
Expand Up @@ -8,10 +8,25 @@ import { resetCache, setCache } from '.';
*/
export async function initRepoCache(config: RenovateConfig): Promise<void> {
resetCache();

const { platform } = GlobalConfig.get();
if (platform && config.repository && config.repositoryCache === 'enabled') {
const localCache = new LocalRepoCache(platform, config.repository);
const { repository, repositoryCache } = config;

if (repositoryCache === 'disabled' || !platform || !repository) {
return;
}

if (repositoryCache === 'enabled') {
const localCache = new LocalRepoCache(platform, repository);
await localCache.load();
setCache(localCache);
return;
}

if (repositoryCache === 'reset') {
const localCache = new LocalRepoCache(platform, repository);
await localCache.save();
setCache(localCache);
return;
}
}

0 comments on commit cbed786

Please sign in to comment.